function [t,y]=euler2(inter,y0,h)
inter = [0,1];
y0 = 1;
n = 10;
t(1)=inter(1); y(1)=y0;
h=(inter(2)-inter(1))/n;
for i=1:n
t(i+1)=t(i)+h;
y(i+1)=eulerstep(t(i),y(i),h);
end
yt = @(t) 3.*exp(t.^2/2)-t.^2-2;
close all
plot(t,y)
hold on
fplot(yt,[0 1])
xlabel('t')
ylabel('y')
legend('Approximate solution','Original solution')
function y=eulerstep(t,y,h)
y=y+h.*ydot(t,y);
end
function z=ydot(t,y)
z=t.*y+t.^3;
end
end
I have this code to plot the approximate and exact solution on a graph but I need to add a for loop to plot another graph that shows step size h and error which is difference between exact and approx solution. For some reason, I can't seem to plot it. Please help me plot it using loglog command