I have a equation f(x)=exp(x)+3x^2
, f(x)=0
, x=?
then I use scilab
to solve that equation using fixed point iteration this is my code
function fixed_point(fung,x0,err)
x=zeros(100);
ea = 100;
i = 1;
x(i)=x0;
printf(" \t i \t x(i) \t ea(%%)");
printf("\n\t %d \t %f \t %f", i, x(i), abs(ea));
while (abs(ea) >err) do
i=i+1;
z =x(i-1);
x(i) = evstr(fung)+z;
ea =100*(x(i)-x(i-1))/x(i);
printf("\n\t %d \t %f \t %f", i, x(i), abs(ea));
end
printf("\n Akar = %f", x(i));
endfunction
then I call it using:
fixed_point ('exp(z)-(3 .* z .*z)',0.00000000001,0.5)
I got x(i)=inf
at last, but I think that's not the answer, can someone explain to me what's wrong with my code?