Download<< Back
%% Compare Nystrom 2-step & Adams-Bashfort 2-step
figure
axis([0 10 -4 4]);
hold on;
xlabel('x_1');
ylabel('x_2');
[t,x]=ny2(@oscillator,0,10, [2;1], .1);
plot(t,x(:,1),'ro','DisplayName','Nystrom 2');
[t,x]=ode23(@oscillator,[0,10], [2;1]);
plot(t,x(:,1),'k-','DisplayName','ode23');
legend('Location', 'NorthEast');
%% Compare Nystrom 3-step & Adams-Bashfort 3-step
figure
axis([0 10 -4 4]);
hold on;
xlabel('t');
ylabel('x_1');
[t,x]=ny3(@oscillator,0,10, [2;1], .1);
plot(t,x(:,1),'ro','DisplayName','Nystrom 3');
[t,x]=ode23(@oscillator,[0,10], [2;1]);
plot(t,x(:,1),'k-','DisplayName','ode23');
legend('Location', 'NorthEast');
%% Nystrom 3-step for Stiff Linear Problem
figure
axis([0 .1 -1 7]);
hold on;
xlabel('t');
ylabel('x_1');
[t,x]=ny3(@linsystem,0,.05, [2;1], 1e-3);
plot(t,x(:,1),'go','DisplayName','Nystrom 3');
options=odeset('AbsTol',1e-3,'RelTol',1e-3);
[t,x]=ode23(@linsystem,[0,.05], [2;1], options);
plot(t,x(:,1),'k-','DisplayName','ode23');
legend('Location', 'NorthEast');