secant method help matlab

1 回表示 (過去 30 日間)
dulanga
dulanga 2014 年 9 月 21 日
コメント済み: Alberto 2014 年 9 月 22 日
hi i have been asked to make a function file for secant menthod
fxi=f(xi);
fxi_1=f(xi_1);
% Initialize iteration count iter = 1;
%iteration for the secant starts while abs(fxi)>precsion
xi=xi-(fxi/fxi_1);
xi_1=(xi-f(xi).(xi_1-xi))/(f(xi_1)-f(xi))
% Increment the iteration count by 1
iter = iter + 1;
end %the final xr value is the root root=xi; % The total iteration number iter = iter - 1; this what i have done
when i run the values its gives this error(Attempted to access f(2); index out of bounds because numel(f)=1.) can anyone help ?
  1 件のコメント
Alberto
Alberto 2014 年 9 月 22 日
I think your code interpret f, not as a function, but as an array with values. So, when you are trying to evaluate f(x), where x=2, your code looks for the second values in an array f.
Advice: 1) save your bound points in variables a and b (for example). Also create a proper function f (inline function or m-file function), so you can evaluate f in a and b. You will need a while or for+if to make your iterations.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by