我有一个方程,f(x)=exp(x)+3x^2
然后我用定点迭代来求解这个方程这是我的代码f(x)=0
x=?
scilab
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
然后我使用以下方法调用它:
fixed_point ('exp(z)-(3 .* z .*z)',0.00000000001,0.5)
我x(i)=inf
终于得到了,但我认为这不是答案,有人可以向我解释我的代码有什么问题吗?