m檔
function[x, ea] = fixed_point(g, x0,es ,n);
X(1) = (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(1))*100
if i >= n
break;
end
end
matlab執行
>> g=inline('-x^2+1.8*x+2.5');
>> x0=5;
>> es=0.1;
>> n=10;
>> [x, ea] = fixed_point(g, x0,es ,n)
Undefined function 'fixed_point' for input arguments of type
'inline'.