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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2014년 9월 21일

댓글:

2014년 9월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by