Not enough input arguments
5 views (last 30 days)
Show older comments
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')
0 Comments
Answers (2)
Elad
on 19 Aug 2013
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));
0 Comments
Bahloul Derradji
on 8 Dec 2018
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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!