Not enough input arguments
Mostrar comentarios más antiguos
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')
Respuestas (2)
Elad
el 19 de Ag. de 2013
0 votos
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
el 8 de Dic. de 2018
0 votos
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!
Categorías
Más información sobre Linear Least Squares en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!