Non-Linear Regression - Too many Input Arguments
Mostrar comentarios más antiguos
I am trying to perform a NL Regression via the following code:
%Non-Linear Regression
clear, clc, close all;
I = [50 80 130 200 250 350 450 550 700];
P = [99 177 202 248 229 219 173 142 72];
func = @(x) P - x(1)*(I/x(2))*exp((-I/x(2))+1);
[x,fval] = fminsearch(func,[1,1],[],I,P);
disp(x)
disp(fval)
I keep getting the 'Too many input arguments' error. I have tried all kinds of formatting to no avail. Help needed.
Thanks.
1 comentario
dpb
el 1 de Mzo. de 2014
Several problems here beginning with the functional definition --
FUN in fminsearch is a function handle to a function which must return a single value -- as written your function won't actually even run correctly owing to the definition of I and P as vectors. There's a dimension mismatch.
>> func = @(x) P - x(1)*(I/x(2))*exp((-I/x(2))+1);
>> func([1 1])
Error using *
Inner matrix dimensions must agree.
Error in @(x)P-x(1)*(I/x(2))*exp((-I/x(2))+1)
If you correct that by using the .* operator then you'll get a vector output the length of I and P which violates the fminsearch rules.
In the call to fminsearch once you iron that out, you can't pass I and P is the actual error you're bombing on now.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with Curve Fitting Toolbox 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!