MATLAB: with My Fixed Point Iteration Program

In summary, MATLAB provides useful tools and functions to aid in the implementation of the fixed point iteration method, which is an algorithm used for solving equations of the form x = g(x). This method can be used for a variety of equations in both linear and nonlinear forms, but it may not always converge to a solution and requires a starting value to be chosen. In MATLAB, the fixed point iteration method can be implemented through a loop or by using built-in functions such as "fzero" or "fsolve". However, there are limitations and drawbacks to using this method, such as difficulty in determining the initial guess and potential computational inefficiency for certain equations.
  • #1
pjkily
4
0

Homework Statement


Fixed Point Iteration MATLAB program


Homework Equations


To test for convergence: abs(g'(x))<1


The Attempt at a Solution



Hi all, I am trying to write a Fixed Point Iteration program but when I enter in the command line it kept giving me an error message. Can you please look over my program and tell me what might have gone wrong? Thank you very much!

First, I defined a function in a new M-File:

function y=FUN3(x)
y=5/(sin(x)*exp(-x./2));

Then, I opened up another M-File and wrote the program:

function Xs = FixedIterationRoot3(FUN3,Xest,imax)
syms x FUN3 FunDer3
Xi(1)=Xest;
FUN3=5/(sin(x)*exp(-x./2));
FunDer3 = diff(FUN3) % To find g'(x)

if abs(subs(FunDer3,x,Xest))>=1 % to check if g'(x) diverges
return;
fprintf('not valid')
end

for i=2:imax
Xi(i)=feval(FUN3,Xest);
Xest=Xi(i);
Xs=Xi;
end



When I enter in the command line:
>> xSolutions=FixedIterationRoot3('FUN3',-3,10)

it gave me error message:
syms x FUN3 FunDer3

? Output argument "Xs" (and maybe others) not assigned during call
to
"C:\Users\Jane\Documents\MATLAB\FixedIterationRoot3.m>FixedIterationRoot3".
 
Physics news on Phys.org
  • #2
pjkily said:

Homework Statement


Fixed Point Iteration MATLAB program


Homework Equations


To test for convergence: abs(g'(x))<1


The Attempt at a Solution



Hi all, I am trying to write a Fixed Point Iteration program but when I enter in the command line it kept giving me an error message. Can you please look over my program and tell me what might have gone wrong? Thank you very much!

First, I defined a function in a new M-File:

function y=FUN3(x)
y=5/(sin(x)*exp(-x./2));

Then, I opened up another M-File and wrote the program:

function Xs = FixedIterationRoot3(FUN3,Xest,imax)
syms x FUN3 FunDer3
Xi(1)=Xest;
FUN3=5/(sin(x)*exp(-x./2));
FunDer3 = diff(FUN3) % To find g'(x)

if abs(subs(FunDer3,x,Xest))>=1 % to check if g'(x) diverges
return;
fprintf('not valid')
end

for i=2:imax
Xi(i)=feval(FUN3,Xest);
Xest=Xi(i);
Xs=Xi;
end



When I enter in the command line:
>> xSolutions=FixedIterationRoot3('FUN3',-3,10)

it gave me error message:
syms x FUN3 FunDer3

? Output argument "Xs" (and maybe others) not assigned during call
to
"C:\Users\Jane\Documents\MATLAB\FixedIterationRoot3.m>FixedIterationRoot3".

In your test for divergence you should attribute a value to Xs before returning.
Also the printf command should come before return, otherwise it will not be executed.
 

1. How does MATLAB help with the fixed point iteration method?

MATLAB provides a variety of functions and tools that make it easier to implement the fixed point iteration method. These include built-in functions for performing mathematical operations, creating and manipulating arrays, and visualizing data.

2. What is the fixed point iteration method and how does it work?

The fixed point iteration method is an algorithm used for solving equations of the form x = g(x), where g(x) is a function. It involves repeatedly substituting a starting value for x into the function g(x) until the resulting value converges to the desired solution.

3. Can I use the fixed point iteration method in MATLAB for any type of equation?

Yes, the fixed point iteration method can be used to solve a wide range of equations, including linear and nonlinear equations. However, it may not always converge to a solution, so it is important to choose an appropriate starting value and check for convergence.

4. How do I implement the fixed point iteration method in MATLAB?

To use the fixed point iteration method in MATLAB, you can create a loop that repeatedly applies the function g(x) to a starting value for x. You can also use the built-in functions such as "fzero" or "fsolve" to find the root of a function, which is equivalent to solving an equation using the fixed point iteration method.

5. Are there any limitations or drawbacks to using the fixed point iteration method in MATLAB?

The fixed point iteration method may not always converge to a solution, especially for complex equations with multiple solutions. It also requires an initial guess for the solution, which may be difficult to determine for some equations. Additionally, the method may be computationally inefficient for certain types of equations.

Similar threads

  • General Math
Replies
1
Views
717
  • Engineering and Comp Sci Homework Help
Replies
2
Views
11K
Replies
17
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Math Proof Training and Practice
2
Replies
69
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
14K
  • Topology and Analysis
Replies
16
Views
2K
  • Precalculus Mathematics Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
Back
Top