• Support PF! Buy your school textbooks, materials and every day products Here!

MATLAB:Please Help with My Fixed Point Iteration Program

  • Thread starter pjkily
  • Start date
  • #1
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".
 

Answers and Replies

  • #2
CEL
656
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".
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.
 

Related Threads on MATLAB:Please Help with My Fixed Point Iteration Program

Replies
2
Views
10K
Replies
9
Views
468
Replies
17
Views
11K
Replies
51
Views
23K
Replies
6
Views
2K
Replies
0
Views
794
Replies
1
Views
611
  • Last Post
Replies
1
Views
832
  • Last Post
Replies
2
Views
615
Top