Matlab code for (i)
clear t % Clears old time steps and
clear y % y values from previous runs
a=0;
b=1;
y0=0.5; % Initial value y(a)
h=0.1; % Time step
N=(b-a)/h;
t(1)=a;
y(1)=y0;
f=@(t,y)(1-y^2);
%while (norm(v,2))>10^-4 % For loop, sets next t,y values
for n=1:N
t(n+1)=t(n)+h;
y(n+1)=y(n)+h*f(t(n),y(n)); % Calls the function f(t,y)=dy/dt
end
y
plot(t(end),y(end),'*')
Output
y =
Columns 1 through 6
0.500000000000000 0.575000000000000 0.641937500000000 0.700729124609375 0.751626994001793 0.795132680190576
Columns 7 through 11
0.831909082279871 0.862701810161897 0.888276368836236 0.909372878092947 0.926676974951842
Trapezoid rule
tspan =0:0.1:1;
y0 = 0.5;
[t,y] = ode23t(@(t,y) 1-y^2, tspan, y0)
plot(t(end),y(end),'square')
Output
t =
0
0.100000000000000
0.200000000000000
0.300000000000000
0.400000000000000
0.500000000000000
0.600000000000000
0.700000000000000
0.800000000000000
0.900000000000000
1.000000000000000
y =
0.500000000000000
0.570980566474321
0.634534816080768
0.690558579148676
0.739387374705229
0.781534279817847
0.817603838846551
0.848245447862247
0.874112554393215
0.895832147232664
0.913968745956985
iii Matlab Code
t=0:0.1:1;
y=(3*exp(2*t)-1)./(3*exp(2*t)+1);
plot(t,y)
Output
4. * Using your calculations from 3., plot the exact solution to dy = 1-y, dt y(0) = 1/2, for 0 <ts1, along with the numerical solution given by Euler's method and the trapezoid method, both w...
using matlab solve numerically dy/dt = sin t, y(0)=0 for 0<=t<=4π the exact solution is y(t) = 1 - cos t. Compare the exact and numerical solution.
Problem 1 Use Euler's method with step size h = 0.5 to approximate the solution of the IVP. 2 dy ev dt t 1-t-2, y(1) = 0. Problem 2 Consider the IVP: dy dt (a) Use Euler's method with step size h0.25 to approximate y(0.5) b) Find the exact solution of the IV P c) Find the maximum error in approximating y(0.5) by y2 (d) Calculate the actual absolute error in approximating y(0.5) by /2. Problem 1 Use Euler's method...
4. Apply Euler's method with step size h = 1/8 to the model problem y' = -20y, y(0) = 1 - just use the formula. What is the Euler approximation at t = 1? The exact numerical solution goes to 0 as t + . What happens to the numerical solution?
1. Consider the following differential equation. ag = ty, y(0)=1. dt (a) Use Euler's Method with At = .1 to approximate y(1). (b) Use Euler's Method with At = .05 to approximate y(1). (c) Find the exact solution to the problem. Use this solution to compare the error for the different values of At. What does this say about the method? Note: On the course page there are notes describing an implementation of Euler's method on a spread sheet.
Problem 3. Given the initial conditions, y(0) from t- 0 to 4: and y (0 0, solve the following initial-value problem d2 dt Obtain your solution with (a) Euler's method and (b) the fourth-order RK method. In both cases, use a step size of 0.1. Plot both solutions on the same graph along with the exact solution y- cos(3t). Note: show the hand calculations for t-0.1 and 0.2, for remaining work use the MATLAB files provided in the lectures Problem...
solve it with matlab 25.24 Given the initial conditions, y(0) = 1 and y'(0) = 1 and y'(0) = 0, solve the following initial-value problem from t = 0 to 4: dy + 4y = 0 dt² Obtain your solutions with (a) Euler's method and (b) the fourth- order RK method. In both cases, use a step size of 0.125. Plot both solutions on the same graph along with the exact solution y = cos 2t.
Problem Thre: 125 points) Consider the following initial value problem: dy-2y+ t The y(0) -1 ea dt ical solution of the differential equation is: y(O)(2-2t+3e-2+1)y fr exoc the differential equation numerically over the interval 0 s i s 2.0 and a step size h At 0.5.A Apply the following Runge-Kutta methods for each of the step. (show your calculations) i. [0.0 0.5: Euler method ii. [0.5 1.0]: Heun method. ii. [1.0 1.5): Midpoint method. iv. [1.5 2.0): 4h RK method...
Use 6 decimal places in your calculations Consider the following IVP: 5 x a) Compute y(0.4) using Euler's method with step size h 0.1. b) If the exact solution is y - ex+ ex, then find the true error at each case Use 6 decimal places in your calculations Consider the following IVP: 5 x a) Compute y(0.4) using Euler's method with step size h 0.1. b) If the exact solution is y - ex+ ex, then find the true...
Using the Runge-Kutta fourth-order method, obtain a solution to dx/dt=f(t,x,y)=xy^3+t^2; dy/dt=g(t,x,y)=ty+x^3 for t= 0 to t= 1 second. The initial conditions are given as x(0)=0, y(0) =1. Use a time increment of 0.2 seconds. Do hand calculations for t = 0.2 sec only.
MATLAB CODE: Task 2 8y dt Solve the above ordinary differential equation (ODE) using Euler's method with step sizes of: 2. h 0.75 3. h 0.5 4. h 0.001 a) For each step size, plot the results at each step starting from y(0) 3 to y(3). b) Plot on the same figure as part a) the analytical solution which is given by: 9 24 -8t c) Calculate and print the percentage error between the Euler's method and the analytical result...