Simple fixed-point iteration method

조회 수: 110 (최근 30일)
John  Smith
John Smith 2019년 9월 22일
답변: Tsega'ab 2023년 12월 13일
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

채택된 답변

Dimitris Kalogiros
Dimitris Kalogiros 2019년 9월 22일
Dear John
Put your function into the same folder with the program (m-file) that calls it.
  댓글 수: 4
John  Smith
John Smith 2019년 9월 23일
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 2019년 9월 24일
Hm hm, I don't know if it is necessary , but I always follow this rule.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Ishita Sharma
Ishita Sharma 2020년 8월 18일
f(x)=x^2 - x -1 =0

emmanuel john Lavarias
emmanuel john Lavarias 2021년 9월 27일
  1. Solve one real root of ex2x5=0ex2x5=0 with x0=2x0=2 using the Fixed-Point Iteration Method accurate to four decimal places.

Ahteshamul Hoque  Tareq
Ahteshamul Hoque Tareq 2022년 1월 8일
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

Tsega'ab
Tsega'ab 2023년 12월 13일
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by