False Position Method.
Hi everyone, I wrote a code that finds the root of the equation using False Position Method. I would like to ask that, how can I plot the root as a function of iteration number and approximate error as a function of itteration number? Thanks in advance to all who want to help!
![]() |
| False Position Method. |
F = @(x) 1000*x^3 + 3000*x – 15000;
X_l = 0;
X_u = 4;
If f(x_l)*f(x_u) > 0
Fprintf(‘There is no solution in the given interval’);
Return
Elseif f(x_l) == 0
Fprintf(‘%f is the solution’,x_l);
Elseif f(x_u) == 0
Fprintf(‘%f is the solution’, x_u);
End
Fprintf(‘I xl xu xm\n’);
For I = 1:1000
Xm = x_u – (x_l-x_u)*f(x_u)/(f(x_l)-f(x_u));
Fprintf(‘%i %f %f %f\n’,I,x_l,x_u,xm)
If abs(f(xm)) < 0.0001
Return
End
If f(x_l)*f(xm) < 0
X_u = xm;
Elseif f(x_u)*f(xm) < 0
X_l = xm;
End
End
Hi everyone, I wrote a code that finds the root of the equation using False Position Method. I would like to ask that, how can I plot the root as a function of iteration number and approximate error as a function of itteration number? Thanks in advance to all who want to help!
F = @(x) 1000*x^3 + 3000*x – 15000;
X_l = 0;
X_u = 4;
If f(x_l)*f(x_u) > 0
Fprintf(‘There is no solution in the given interval’);
Return
Elseif f(x_l) == 0
Fprintf(‘%f is the solution’,x_l);
Elseif f(x_u) == 0
Fprintf(‘%f is the solution’, x_u);
End
Fprintf(‘I xl xu xm\n’);
For I = 1:1000
Xm = x_u – (x_l-x_u)*f(x_u)/(f(x_l)-f(x_u));
Fprintf(‘%i %f %f %f\n’,I,x_l,x_u,xm)
If abs(f(xm)) < 0.0001
Return
End
If f(x_l)*f(xm) < 0
X_u = xm;
Elseif f(x_u)*f(xm) < 0
X_l = xm;
End
End


0 Comments