clear all
global a
%
% Example 1
%
a=-2;

t1=-1;t2=2;x1=-1;x2=1;
N=20;
tinc=(t2-t1)/N;xinc=(x2-x1)/N;
[t,x]=meshgrid(t1:tinc:t2,x1:xinc:x2);
f=a.*x;
dt=cos(atan(f));
dx=sin(atan(f));
quiver(t,x,dt,dx,.35);


T=2;
xinit=[-1  -.5 0 .5  1];
K=length(xinit(1,:));
for k=1:K
[t,x]=ode23('g',[-1, T],xinit(:,k));
hold on
plot(t,x,'r-','linewidth',2)
end

T=2;
tinit=[0  1 ];
K=length(tinit(1,:));
for k=1:K
[t,x]=ode23('g',[tinit(:,k), T],-1);
hold on
plot(t,x,'r-','linewidth',2)
end

T=2;
tinit=[0  1 ];
K=length(tinit(1,:));
for k=1:K
[t,x]=ode23('g',[tinit(:,k), T],1);
hold on
plot(t,x,'r-','linewidth',2)
end
axis([-1 T -1 1])

