MATLAB Answers

Simple fixed-point iteration method

403 views (last 30 days)
My task is to implement (simple) fixed-point interation.
So far, I've got the following and I keep receiving error Undefined function 'fixedpoint' for input arguments of type 'function_handle'.
(I'm new in Matlab, so there may be both syntactical or semantical errors...)
function [ x ] = fixedpoint(g,I,y,tol,m)
% input: g, I, y, tol, max
% g - function
% I - interval
% y - starting point
% tol - tolerance (error)
% m - maximal number of iterations
% x - approximate solution
a=I(1);b=I(2);
if(y<a | y>b)
error('The starting iteration does not lie in I.')
end
x=y;
gx=g(y);
while(abs(x-gx)>tol & m>0)
if(gx<a | gx>b)
error('The point g(x) does not lie in I.')
end
y=x;
x=g(y);
m=m-1;
end

  0 Comments

Sign in to comment.

Accepted Answer

Dimitris Kalogiros
Dimitris Kalogiros on 22 Sep 2019
Dear John
Put your function into the same folder with the program (m-file) that calls it.

  4 Comments

Show 1 older comment
Dimitris Kalogiros
Dimitris Kalogiros on 22 Sep 2019
I wonder , what is the calling program.
If you don't mind , could you provide it ?
John  Smith
John Smith on 23 Sep 2019
I am not sure, what I have done, but it is working fine now. ¯\_(ツ)_/¯
Anyway, thank you for your time.
> I wonder , what is the calling program.
It might have been the problem. I guess the function and the file have to share the name, right?(I mean, if I code a function F, then it has to be saved as file F.m.)
Dimitris Kalogiros
Dimitris Kalogiros on 24 Sep 2019
Hm hm, I don't know if it is necessary , but I always follow this rule.

Sign in to comment.

More Answers (0)

Sign in to answer this question.