LAB 3 - Easton Zhong - MAT 275
Exercise 1
Read the instructions in your lab pdf file carefully!
Part (a)
NOTE: We often define the right-hand side of an ODE as some function, say , in terms of the input and output f
variables in the ODE. For example, Although the ODE does not explicitly depend on , it t
does so implicitly, since is a function of . Therefore, is an input variable of y t t f.
Define ODE function for your version of the lab.f
f=@(t,y)(4.5*y);
Define vector of time-values over the interval in your version of the lab, to compute analytical solution vector.t
t = linspace(0,0.5,100);
Create vector of analytical solution values at corresponding t values.
y = exp(4.5*t);
NOTE: In your version of the lab you were given a table in problem1(a), which you need to fill out. This table
has four different values of N - call them Nsmall, Nmed, Nlarge and Nhuge (where, of course, Nsmall < Nmed
< Nlarge < Nhuge). For the following steps, please use notation consistent with the protocol and appropriate for
your version of the lab. For example, if in your version timesteps, then use the variable name to Nsmall=5 t5
represent the vector of t-points in the solution with number of steps N=5. Also, if in your version Nlarge=500
timesteps, use variable name o represent the numerical solution vector produced from Euler's method, y500 t
and use the name to denote the corresponding error. In the following comments, I refer to "Euler's e500
method" as "forward Euler's method," which is more precise since there is also a backward Euler's method.
I use "IVP" as an abbreviation for Initial Value Problem, which for our purposes here means an ODE with
associated initial condition. Delete this note upon submission.
Solve IVP numerically using forward Euler's method with Nsmall timesteps (use variable names as instructed).
[t5,y5] = euler(f,[0,0.5],1,5);
y5(end);
Solve IVP numerically using forward Euler's method with Nmed timesteps (use variable names as instructed).
[t50,y50] = euler(f,[0,0.5],1,50);
y50(end);
Solve IVP numerically using forward Euler's method with Nlarge timesteps (use variable names as instructed).
[t500,y500] = euler(f,[0,0.5],1,500);
1
y500(end);
Solve IVP numerically using forward Euler's method with Nhuge timesteps (use variable names as instructed).
[t5000,y5000] = euler(f,[0,0.5],1,5000);
y5000(end);
In the following steps, we define error as exact - numerical solution value at the last time step
Compute numerical solution error at the last time step for forward Euler with Nsmall timesteps (use variable
names as instructed).
e5 = y(end) - y5(end);