我有2个功能:
function y=Fun(x)
7*x^4+exp(-7*x)-5*x-11
和
function Xs = secantroot(Fun,x1,x2,imax)
% SecantRoot finds theroot of Fun=0 using the secant
% Input variables:
% Fun Name of a user-defined function that calculates Fun for a given x.
% x1,x2 Two points in the neighborhood of the root (on either side or the
% same side of the root
% Err Relative error.
% imax Maximum number of iterations
% Output variable:
% Xs Solution
xi(1)=x1;%sets the initial values of x1,the value to the right of the true root
xi(2)=x2;%sets the initial values of x2, the value to the left of the true root
for i=3:imax
xi(i)=x2-feval(Fun,x2)*(x1-x2)/(feval(Fun,x1)-feval(Fun,x2));
x1=x2;
x2=xi(i);
end
Xs=xi
但是当我进入
>>>secantroot(Fun,2.5,0.7,10)
我使用Fun收到错误(第2行)输入参数不足。
尝试传递一个函数句柄:
>>> secantroot(@Fun,2.5,0.7,10)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句