Xo = 0;%lower limit h = .05;%intervals Xn = 6;%upper limit lam = -1; y = sin(Xo);%the function at Xo dy = lam.*y + cos(Xo) - lam.*sin(Xo);%the derivative of y at Xo for x = Xo:h:Xn Y = y + h.*dy;%the value of the tangent line at x if (rem(x,2)==0) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% func = sin(x);%actual function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Error = func - Y; Rel = Error/func; AError = (h./2).*((cos(x)+lam.*sin(x)-exp(lam.*x))./(1+lam.^2)); [x, Y, Error, Rel, AError] end y = Y;%function at Xn %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dy = lam.*y + cos(x) - lam.*sin(x);%derivative of y at Xn %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end