Non-Linear Regression - Too many Input Arguments
Show older comments
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 Comment
dpb
on 1 Mar 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.
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!