My data seems to become zigzagged as the output continues for many iterations. How do I fix this?
Code:
function sfun(x,a)
%This function computes y=1/(1x) using series expansion
%input:
% x = value 1/(1x) is to be evaluated
% err = approx percent error for computed result.
%Initial condition y(0)=1
format compact
format short
if abs(x)<1
y=1;
yexact = 1/(1x)
fprintf('\t Iter. \t approx. \t\t %% of true \t\t\t %% of approx. \n');
for i = 1:50
order=i;
yold = y;
y = y + (x^order);
epst = abs((yyexact)/yexact)*100;
epsa = abs((yyold)/y)*100;
fprintf('\t %1.0d \t %10.10f \t\t %10.10f \t\t %10.10f \n',i,y,epst,epsa);
if(epsa <= a),break,end
end
elseif abs(x)>1
disp(' the absolute value of x must be less than one' )
end
Ouput:
well the output gets zig zagged about halfway down. When I copied it to the screen, the forum editor made it look correct. Thats why I am not visualizing it here.
