Permalink
Cannot retrieve contributors at this time
06_initial_value_ode/prob2plot.m
Go to fileset(0, 'defaultAxesFontSize', 16) | |
set(0,'defaultTextFontSize',14) | |
set(0,'defaultLineLineWidth',3) | |
dt = 0.1; | |
t = [0:dt:3]; | |
y = zeros(size(t)); | |
y(1) = 1; | |
for i = 2:length(t) | |
dy = prob2_ode(t,y(i-1)); | |
y(i) = y(i-1)+dt*dy; | |
end | |
a = figure(1); | |
y_heun = Prob2ptC (@(t,y) prob2_ode(t,y), 0.1, 1, [0 3]); | |
plot(t,exp(-t),t,y,t,y_heun); | |
legend('Analytical','Euler','Heun','Location','Northeast') | |
xlabel('Time') | |
ylabel('Position') |