我有两个功能:
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行) 没有足够的输入参数。
答案 0 :(得分:0)
尝试传递函数句柄:
>>> secantroot(@Fun,2.5,0.7,10)