Solve a nonlinear equation using fixed-point iteration in MATLAB

AI Thread Summary
The user is attempting to solve a nonlinear equation using fixed-point iteration in MATLAB but encounters issues with plotting and no output. They are advised to plot the function g(x) before performing the fixed-point calculation to visualize it properly. The suggested code includes defining a range for x and plotting g(x) before and after the iteration. The user reports receiving an error when trying to define g(x) in their code. Properly structuring the code and plotting steps is crucial for successful execution and visualization in MATLAB.
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 !
p1.JPG

attempt.JPG
 
Physics news on Phys.org
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 .
error.jpg
 
Jaime_mc2 said:
g = x^5-3*x^3-2*x^2+2;
I got an error .
error.jpg
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
3
Views
740
Replies
1
Views
2K
Replies
3
Views
1K
Replies
1
Views
264
Replies
10
Views
2K
Replies
20
Views
3K
Replies
1
Views
2K
Back
Top