Solve a nonlinear equation using fixed-point iteration in MATLAB

3 replies · 3K views · last reply
Fatima Hasan
Messages
315
Reaction score
14
Homework Statement
The statement is attached below.
Relevant Equations
-
My attempt is attached below.
When I tried to solve it , nothing comes up. However, there are no errors !
Typed homework problem: design a MATLAB program for fixed point iteration, graph g(x) = x^5 - 3x^3 - 2x^2 + 2 with y = x, and sketch convergence versus iterations.

Screenshot of a MATLAB editor showing a fixed-point iteration script for x^5-3x^3-2x^2+2 with x0=2, maxiter=50 and tolx=1e-4, next to an empty plot window with axes from -10 to 10.
 
You are plotting just one point at the end, with coordinates (maxiter + 1, x(maxiter + 1)).

If you want to plot ##g(x)##, you should do something like this (for example before calculating the fixed-point):
Matlab:
x= -10:0.01:10;
g = x^5-3*x^3-2*x^2+2;
plot(x, g);

After this, you should calculate the fixed-point. If you call it ##x## in your code, you can do the following after the fixed-point iteration:
Matlab:
hold on;
fixed_g = x^5-3*x^3-2*x^2+2;
plot(x, fixed_g, 'o');
 
Jaime_mc2 said:
g = x^5-3*x^3-2*x^2+2;
I got an error .
MATLAB editor showing a fixed-point iteration script with a for loop and a plot, and the Command Window reporting 'Incorrect dimensions for raising a matrix to a power' at line 10, g=x^5-3*x^3-2*x^2+2.
 
Jaime_mc2 said:
g = x^5-3*x^3-2*x^2+2;
I got an error .
MATLAB editor showing a fixed-point iteration script with a for loop, followed by a Command Window error: 'Incorrect dimensions for raising a matrix to a power' at line 10, g=x^5-3*x^3-2*x^2+2.