MAT 275 MATLAB LAB 3
Alejandro Carranza
Monday 9:40 AM
Javier Baez
Exercise 1
Part (a)
% Define ODE function f
f = inline('2*y','t','y');
% analytical solution vector.
t = linspace(0,.5,100); y=3*exp(2*t); % exact
solution
% Create vector
[t50,y50] = euler(f,[0,.5],3, 50); % solves the
ODE
% Solve IVP numerically with 5 time steps.
[t5,y5]=euler(f,[0,.5],3, 5);
% Solve IVP numerically 50 time steps.
[t50,y50]=euler(f,[0,.5],3, 50);
% Solve IVP numerically with 500 time steps.
[t500,y500]=euler(f,[0,.5],3, 500);
% Solve IVP numerically with 5000 time steps.
[t5000,y5000]=euler(f,[0,.5],3, 5000);
% Compute numerical with 5
% time steps.
e5 = y(end)-y5(end)
% define error
% Compute numerical solution error
e50 = y(end) - y50(end)
% Compute numerical solution error with 500
% time steps.
e500 = y(end)- y500(end)
% Compute numerical solution error with 5000
% time steps.