% t0=input('punto iniziale');
% v=input('valore iniziale');
% tf=input('punto finale');
% tol=input('tolleranza');
% lambda=input('lambda');
% h=input('passo iniziale');
dati
x=[t0:.05:tf];
z=soluz(x,lambda,t0,v);
plot(x,z)
pause
  axis;
  ymin=ans(3)*1.1;
  ymax=ans(4)*1.1;
  xmin=ans(1);
  xmax=ans(2);
  axis([xmin,xmax,ymin,ymax]);
  plot(x,z)
hold on
t=t0;
y=z(1);
i=0;r=0;
while t<tf
yy=(y+h/2*(funct(t,y,lambda)+funct(t+h,0,lambda)))/(1-h*lambda/2);
i=i+1;
y1=y;
y1=(y1+h/4*(funct(t,y,lambda)+funct(t+h/2,0,lambda)))/(1-h/4*lambda);
y2=(y1+h/4*(funct(t+h/2,y1,lambda)+funct(t+h,0,lambda)))/(1-h/4*lambda);
%test di errore
err=(y2-yy)/7;
if abs(err) <=tol*h
   plot(t+h,y2,'o');
   t=t+h;
   y=y2;

%pause
   h=h*min(2, sqrt(.5*tol*h/abs(err)));
   else
   r=r+1;
   h=h*max(.5, sqrt(.5*tol*h/abs(err)));
   end

end

   title(['TRAPEZI   num. rifiuti=',int2str(r),'   num. passi=',int2str(i)]);
hold off


