How to get a solution of f(x)=x^3 +x-1 by iteration on Matlab? And x=g(x) ......x(n+1)=g(x) when n>=0. Give that g(x)=1/(1+x^2)

How to get a solution of f(x)=x^3 +x-1 by iteration on Matlab? And x=g(x) ......x(n+1)=g(x) when n>=0. Give that g(x)=1/(1+x^2)
clear
% Value of f(x)
f(x)=x.^3 +x-1;
% First guess for the square root of x
x(1) = 1;
i = 1;
% If the error is greater than 10^-4, continue iterating
while abs (x (i) - f(x) ) >= 10^-4
i = i + 1;
x ( i ) = 1./(1+(x.^2));
end
% Show the result
x ( i )
plot ( abs ( x - f(x) ) )
grid on
xlabel('Number of iterations')
ylabel('error')

답변 (2개)

f=@(x)x.^3 +x-1;
x(1) = 1;
i1 = 1;
while abs(f(x)) >= 10^-4
i1 = i1 + 1;
x(i1) = 1./(1+x(i1 - 1).^2);
end

카테고리

도움말 센터File Exchange에서 External Language Interfaces에 대해 자세히 알아보기

질문:

2012년 11월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by