clear
disp('metodo trap_hcost per eq. lineare a passo costante con dati in dati_gen')
disp('i dati sono la funzione f(t,x)=a(t)x+b(t), t0,y0,tf h')
dati_gen;
y(:,1)=y0;
t(1)=t0;
i=1;
% calcolo della soluzione esatta con trapezi_hcost hh=.001
hh=.1;
yy(:,1)=y0;
tt(1)=t0;
i=1;
while tt(i) < tf
    yy(:,i+1)=(eye(length(y0))-a(tt(i)+hh)*hh/2)\((eye(length(y0))+a(tt(i))*hh/2)*yy(:,i)+hh/2*(b(tt(i))+b(tt(i)+hh)));
    tt(i+1)=tt(i)+hh;
    i=i+1;
end
plot(tt,yy)
hold on
% fine trapezi
pause
%metodo dei trapezi
i=1;
while t(i) < tf
    y(:,i+1)=(eye(length(y0))-a(t(i)+h)*h/2)\((eye(length(y0))+a(t(i))*h/2)*y(:,i)+h/2*(b(t(i))+b(t(i)+h)));
    %y(:,i+1)=(eye(length(y0))-a*h/2)\((eye(length(y0))+a*h/2)*y(:,i)+h/2*(b+b));
    t(i+1)=t(i)+h;
    i=i+1;
end
plot(t,y,'r')
%plot(y)
hold off
pause
close all
end