Hi, I am getting error on secant problem.

2 ビュー (過去 30 日間)
Nasser Yari
Nasser Yari 2016 年 2 月 20 日
コメント済み: Nasser Yari 2016 年 2 月 20 日
when I type in command window i get the following
Xs=(exp(-x)-x,0,1,.001,3)
Xs=(exp(-x)-x,0,1,.001,3)
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
Here is my program
function Xs=secantroot (fun,Xa,Xb,tol,n)
for i=1:n
funXb=feval(fun,Xb);
Xi=Xb-funXb*(Xa-Xb)/(feval(fun,Xa)-funXb);
if abs((Xi-Xb)/Xb)<tol
Xs=Xi;
break
end
Xa=Xb;
Xb=Xi;
end
if i==n
fprintf('solution is not in intersection %g\n',n)
Xs=('sorry no answer');
end
I appreciate your help. I am beginner.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 20 日
There is no error in your function. To call it:
fun=@(x)exp(-x)-x
Xa=0
Xb=1
tol=0.001
n=3
Xs=secantroot (fun,Xa,Xb,tol,n)
  1 件のコメント
Nasser Yari
Nasser Yari 2016 年 2 月 20 日
Thank you Azzi

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by