y_0 = 2; x_0 = 1; x_final = 20; N = 100; [x1,y1] = euler_step(y_0,x_0,x_final,N,'f'); N = 2*N; [x2,y2] = euler_step(y_0,x_0,x_final,N,'f'); N = 2*N; [x3,y3] = euler_step(y_0,x_0,x_final,N,'f'); N = 2*N; [x4,y4] = euler_step(y_0,x_0,x_final,N,'f'); N = 2*N; [x5,y5] = euler_step(y_0,x_0,x_final,N,'f'); N = 2*N; [x6,y6] = euler_step(y_0,x_0,x_final,N,'f'); figure(1) clf plot(x1,abs(y1-y2(1:2:length(y2))),'b') hold on plot(x2,abs(y2-y3(1:2:length(y3))),'k') plot(x3,abs(y3-y4(1:2:length(y4))),'c') plot(x4,abs(y4-y5(1:2:length(y5))),'g') plot(x5,abs(y5-y6(1:2:length(y6))),'r') rat1 = (y1 - y2(1:2:length(y2)))./(y2(1:2:length(y2))-y3(1:4:length(y3))); rat2 = (y2 - y3(1:2:length(y3)))./(y3(1:2:length(y3))-y4(1:4:length(y4))); rat3 = (y3 - y4(1:2:length(y4)))./(y4(1:2:length(y4))-y5(1:4:length(y5))); rat4 = (y4 - y5(1:2:length(y5)))./(y5(1:2:length(y5))-y6(1:4:length(y6))); figure(2) clf plot(x1,rat1,'b') hold on plot(x2,rat2,'k') plot(x3,rat3,'c') plot(x4,rat4,'g') axis([x_0,x_final,0,8]) Y1 = 2*exp(sin(x1))/exp(sin(1)); Y2 = 2*exp(sin(x2))/exp(sin(1)); Y3 = 2*exp(sin(x3))/exp(sin(1)); Y4 = 2*exp(sin(x4))/exp(sin(1)); Y5 = 2*exp(sin(x5))/exp(sin(1)); Y6 = 2*exp(sin(x6))/exp(sin(1)); Rat1 = (y1 - Y1)./(y2(1:2:length(y2))-Y2(1:2:length(Y2))); Rat2 = (y2 - Y2)./(y3(1:2:length(y3))-Y3(1:2:length(Y3))); Rat3 = (y3 - Y3)./(y4(1:2:length(y4))-Y4(1:2:length(Y4))); Rat4 = (y4 - Y4)./(y5(1:2:length(y5))-Y5(1:2:length(Y5))); Rat5 = (y5 - Y5)./(y6(1:2:length(y6))-Y6(1:2:length(Y6))); figure(3) clf plot(x1,Rat1,'b') hold on plot(x2,Rat2,'k') plot(x3,Rat3,'c') plot(x4,Rat4,'g') plot(x5,Rat5,'r') axis([x_0,x_final,0,8])