MATLAB: with My Fixed Point Iteration Program

Click For Summary
SUMMARY

The forum discussion focuses on troubleshooting a Fixed Point Iteration program written in MATLAB. The user encountered an error message indicating that the output argument "Xs" was not assigned during the function call. The program defines a function FUN3 and attempts to implement the FixedIterationRoot3 function, but fails to assign a value to Xs before the return statement. Additionally, the fprintf command should precede the return statement to ensure it executes correctly.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with symbolic computation in MATLAB
  • Knowledge of fixed point iteration methods
  • Concept of function derivatives and convergence criteria
NEXT STEPS
  • Review MATLAB function definitions and output assignment
  • Learn about symbolic differentiation in MATLAB using the 'diff' function
  • Explore error handling and debugging techniques in MATLAB
  • Study convergence criteria for iterative methods in numerical analysis
USEFUL FOR

Students and professionals working with MATLAB, particularly those involved in numerical methods and algorithm development for root-finding problems.

pjkily
Messages
4
Reaction score
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
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.
 

Similar threads

Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
11K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 17 ·
Replies
17
Views
15K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 69 ·
3
Replies
69
Views
9K