Simple fixed-point iteration method
50 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Dimitris Kalogiros
2019 年 9 月 22 日
Dear John
Put your function into the same folder with the program (m-file) that calls it.
4 件のコメント
Dimitris Kalogiros
2019 年 9 月 24 日
Hm hm, I don't know if it is necessary , but I always follow this rule.
その他の回答 (4 件)
emmanuel john Lavarias
2021 年 9 月 27 日
- Solve one real root of ex−2x−5=0ex−2x−5=0 with x0=−2x0=−2 using the Fixed-Point Iteration Method accurate to four decimal places.
0 件のコメント
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
0 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!