%% Compare Nystrom 2-step & Adams-Bashfort 2-step
%
% We solve linear oscillator with $a = 0$, $b = 9$, $c = 10$, $\omega = 1$
% and $x_0=(2,1)^T$ using  Nystrom 2,and ode23.

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');

% compare with  ode23
[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
%
% We solve linear oscillator with $a = 0$, $b = 9$, $c = 10$, $\omega = 1$
% and $x_0=(2,1)^T$ using Nystrom 3, and ode23.

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');

% compare with  ode23
[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
%
% We solve linear oscillator stiff linear problem using Nystrom 3,
% and ode23.

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');

% comparing with  ode23
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');

