Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
17 lines (17 sloc) 457 Bytes
set(0, 'defaultAxesFontSize', 16)
set(0,'defaultTextFontSize',14)
set(0,'defaultLineLineWidth',1)
dt = 0.01;
t = [0:dt:3];
y = zeros(length(t),2);
y(1,:) = [1,0];
for i = 2:length(t)
dy = prob3_ode(t,y(i-1,:));
y(i,:) = y(i-1,:)+dt*dy;
end
b = figure(2);
y_heun = prob3ptC (@(t,y) prob3_ode(t,y),0.01,[1,0],[0 3]);
plot(t,cos(3*t),t, y(:,1),t,y_heun(:,1))
legend('Analytical','Euler','Heun','Location','Northeast')
xlabel('Time')
ylabel('Position')
You can’t perform that action at this time.