1 / 12144%
LAB 3 - Your Name - MAT 275
Exercise 1
Part (a)
Define ODE function for your version of the lab.f
f =@( t , y ) 0.7* y;
Define vector of time-values over the interval in your version of the lab, to compute analytical solution vector.t
t = linspace (0 ,3 ,100); y = -4* exp (0.7* t );
Create vector of analytical solution values at corresponding t values.
[ t60 , y60 ]= euler (f ,[0 ,3] , -4 ,60);
Solve IVP numerically using forward Euler's method with Nsmall timesteps (use variable names as instructed).
[ t6 , y6 ]= euler (f ,[0 ,3] , -4 ,6) ;
Solve IVP numerically using forward Euler's method with Nmed timesteps (use variable names as instructed).
[ t60 , y60 ]= euler (f ,[0 ,3] , -4 ,60);
Solve IVP numerically using forward Euler's method with Nlarge timesteps (use variable names as instructed).
[ t600 , y600 ]= euler (f ,[0 ,3] , -4 ,600);
Solve IVP numerically using forward Euler's method with Nhuge timesteps (use variable names as instructed).
[ t6000 , y6000 ]= euler (f ,[0 ,3] , -4 ,6000);
In the following steps, we define error as exact - numerical solution value at the last time step
%eN=y(end)-yN(end)
Compute numerical solution error at the last time step for forward Euler with Nsmall timesteps (use variable
names as instructed).
eNsmall= y(end) - y6(end);
Compute numerical solution error at the last time step for forward Euler with Nmed timesteps (use variable
names as instructed).
eNmed= y(end) - y60(end);
Compute numerical solution error at the last time step for forward Euler with Nlarge timesteps (use variable
names as instructed).
1
eNlarge= y(end) - y600(end);
Compute numerical solution error at the last time step for forward Euler with Nhuge timesteps (use variable
names as instructed).
eNhuge= y(end) - y6000(end);
Compute ratio of errors between N=Nsmall and N=Nmed.
ratio1= e6/e60;
Compute ratio of errors between N=Nmed and N=Nlarge.
ratio2= e60/e600;
Students also viewed