function [x,ea] = fixed_point(g, x0, es, N)
%
x(1) = g(x0);
ea(1) =abs((x(1)-x0)/x(1))*100;
i = 1;
while ea(i) > es
i = i + 1;
x(i) = g(x(i-1));
ea(i) = abs((x(i)-x(i-1))/x(i))*100;
if i >= N
break;
end
end
我把上面存成.m之後,然後打
f=inline('-x^2+1.8x+2.5');
x0=5;
es=0.1;
N=10;
function [x,ea] = fixed_point(g, x0, es, N);
就跑出
function [x,ea] = fixed_point(g, x0, es, N);
|
Error: Function definitions are not permitted in this context.
新手自己在摸索,我少做了什麼事情嗎?
還是叫.m檔的方式錯誤,麻煩各位幫小弟解答,感謝。