function doublin(a,b,g)
%    doublin(a,b,g)
% run the double integrator.
% a and b are vectors of dimension 2
% g is a string describing the control function
% u=g(x1,x2)
	L=1024*4;T=10;dt=T/L;t=dt*[0:L-1];epsilon=.1;
	x=zeros(2,L);v=zeros(1,L);
	x(:,1)=a;x1=a(1);x2=a(2);
	k=2;
	while (k<=L)&(sum(abs([x1;x2]-b))>epsilon);
		u=eval(g);
		x1=x1+dt*x2;x2=x2+dt*u;
		x(:,k)=[x1;x2];
		v(k)=u;
		k=k+1;
	end	
	subplot(2,2,1)
	kk=[1:k-1];
	plot(t(kk),v(kk))
	axis([0 t(k-1) -1.2 1.2])
	xlabel('u(t)')
	title(['u = ',g])
	subplot(2,2,2)
	plot(x(1,kk),x(2,kk))
	xlabel('phase plane')
	subplot(2,2,3)
	plot(t(kk),x(1,kk))
	xlabel(['x_1(t)','  elapsed time = ',num2str(t(k-1))])
	subplot(2,2,4)
	plot(t(kk),x(2,kk))
	xlabel('x_2(t)')
