Fit, fittype, fitoptions

5 views (last 30 days)
Mete Mutlu
Mete Mutlu on 31 Mar 2017
Answered: Mete Mutlu on 31 Mar 2017
Hello,
I have a two input, one output custom equation that I am trying to define the coefficients using field data. The code I am using is as below
fo = fitoptions('Method','NonlinearLeastSquares', 'Lower',[0 0 0 0 ]', 'Upper', [5 5 4000 200 ], 'StartPoint',[0.1 0.1 0 0], 'MaxIter',4000);
ft = fittype( @(a,b,c,d,m,n) a.*(exp(b.*m)-1)+c+d.*n.^2,'independent', {'m', 'n'}, 'options', fo);
f = fit( M, N,Q, ft);
M and N are variables. a, b,c,d need to be defined.
When I run it, I get the following error:
Error using fit>iParseOptionalArgs (line 965)
The properties, PROP1, PROP2, ..., in property-value pairs must be
strings.
Error in fit (line 105)
[useroptions, useroptargs, probparams] = iParseOptionalArgs(
varargin{:} );
Error in FirstTryWithFlowRate (line 106)
f = fit( M, N,Q, ft, fo);
Any ideas on what might be causing this? I do not have any problem when I have only one independent variable. I also don't have any problem when I do it through the Curve Fitting application. But I need to automate the process, so I need to do it via script.
Thanks

Answers (1)

Mete Mutlu
Mete Mutlu on 31 Mar 2017
After much deliberation, I found my mistake. The inputs M and N should be in bracket. So here would be the correct format.
f = fit([M, N],Q, ft);
The rest is the same.
For the record, if you have a more complicated fit or options, try setting it up in the curve fitting toolbox, then, File> Generate Code will generate the code for you that you can use later on.

Categories

Find more on Linear and Nonlinear Regression 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!