Solve the equation \(x^3 + 5x = 2\) by the fixed-point iteration method.
Solution.
The function \(x^3 + 5x\) is increasing from 0 to 6 on the interval \([0, 1]\text{.}\) Therefore, the equation has a solution in this interval. Following the idea of the previous paragraph, rewrite it as \((2-x^3)/5 = x\text{.}\) This means \(g(x) = (2-x^3)/5\) and \(g'(x) = -3x^2/5\text{.}\) Note this \(|g'| \lt 1\) on \([0, 1]\) which guarantees that the fixed point is attracting. Here is the code to find it.
g = @(x) (2-x^3)/5;
x0 = 0;
max_tries = 1000;
for k = 1:max_tries
x1 = g(x0);
if abs(x1-x0) < 100*eps(x0)
break
end
x0 = x1;
end
if k < max_tries
fprintf('Found x = %.12g after %d steps\n', x1, k);
else
disp('Failed to converge')
end
The reason for using a
for loop is to set a limit for the number of attempts (1000). The loop ends sooner if the values of x essentially stop changing. We do not need separate variables for every element of the sequence: x0 and x1 keep being reused for “old” and “new” x-values. The output is “Found x = 0.388291441005”.
