I want to store output values of x1,g(x) etc in a matrix,plz help me out. here's my program:
function SA()x1=input('\n enter initial value:-');acc=input('\n enter accuracy:-');n=input('\n itterations:-');while (dg(x1)>1) x1=input('\n enter initial value:-');endfprintf('\n n x1 x2 (x2-x1) g(x1) ');for i=1:1:n x2=g(x1); fprintf('\n %d %f %f %f %f',i,x1,x2,abs(x2-x1),g(x1)); if abs(x2-x1)>acc x1=x2; else fprintf('\n root is %f',x2'); break; endendendfunction y=g(x)y=(((x^2)+1)/3);endfunction z=dg(x)z=((2*x)/3);end
Best Answer