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