Not enough input arguments

7 次查看(过去 30 天)
Jac
Jac 2013-8-19
All input variables are provided for in the code below, but still running it gives the "Not enough input arguments" error message. Can anyone help out?
PS: the function is doing nonlinear least squares of a weighted average of variables (x(2) and x(3))
function F = myfun2(x,n,cn);
F = @(x,n,cn)x(1)+n.*log(1+(1-exp(-cn))*x(2)+exp(-cn)*x(3));
FW=inline(char(F));
x=[0 0 0]
n=1:7
cn=0.5
ct=1
Fut=[5 4.9 4.8 4.65 4.5 4.3 4.05]
[x,resnorm] = lsqcurvefit(myfun2,x,n'-1-ct/12,Fut')

回答(2 个)

Elad
Elad 2013-8-19
Hey, From matlab help it seems that
lsqcurvefit is a function of ( fun , x , xdata , ydata ) where fun is a function of ( x , xdata )
your myFun2 is a function of 3 input arguments .. not 2
another quick tip you might use, you dont have to create myFun2 as a function, you can write as a function handle
cn = 0.5; myFun2 = @(x,n)x(1)+n.*log(1+(1-exp(-cn))*x(2)+exp(-cn)*x(3));

Bahloul Derradji
Bahloul Derradji 2018-12-8
Try this code. It works.
the user defined function in a separate file named : myfun.m
function F = myfun(x,xdata,c)
F = x(1)*exp(c*xdata)+x(2)
end
the main script:
xdata = [3; 1; 4]; % example xdata
ydata = 6*exp(-1.5*xdata)+3; % example ydata
c = -1.5; % define parameter
x = lsqcurvefit(@(x,xdata) myfun(x,xdata,c),[5;1],xdata,ydata)
Good luck!

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by