Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the initial value problem y 2e cos(2t) dt dy t = + with initial conditi

ID: 2259229 • Letter: C

Question

Consider the initial value problem y 2e cos(2t) dt dy t = + with initial condition y(0) = 0 . Implement forward Euler method and solve the problem with final time T=1.0. The exact solution is given as y(t) e sin(2t) t = . List the error in the absolute value sense at final time T=1.0 between the numerical solution and the exact solution with refined mesh N=20, 40, 80, 160. Do you observe any tendency from the error behavior? Explain your results.

3. Consider the initial value problem a -y +2e-cs(2)with initial condition y(0)=0 dt Implement forward Euler method and solve the problem with final time T-1.0. The exact solution is given as y()-sin(2). List the error in the absolute value sense at final time T-1.0 between the numerical solution and the exact solution with refined mesh N-20, 40 80, 160. Do you observe any tendency from the error behavior? Explain your results. N- 20 N 40 N-80 N 160 ERROR

Explanation / Answer

clc;
clear all;
format long

f=@(t,y)-y+2*exp(-t)*cos(2*t);

a=0; %lower limit
b=1; %upper limit

disp('-----------------------------------------------------')
disp( ' N               Erorr                ')
disp('---------------------------------------------------')
N=20; % number of intervals
while(N<=160)
h=(b-a)/N; %step length
t=a:h:b;
y_eu(1)=0; % intial conditon
%Euler formula
for i=1:N
    y_eu(i+1)=y_eu(i)+h*f(t(i),y_eu(i));
end

%Exact solution
for i=1:N+1
     y_ex(i)=exp(-t(i))*sin(2*t(i));
end
erorr=max(abs(y_eu-y_ex));

fprintf('%d %20f ',N,erorr)
N=N*2;
end

-----------------------------------------------------
N               Erorr              
---------------------------------------------------
20                 0.041072
40                 0.020269
80                 0.010071
160                0.005019

If the numer of intervals or points are increasing bertween 0 and 1 then error is decreasing