what toolbox do I need to fit an exponential with bounded parameters?

Hi,
I want to fit an exponential function to my data, and force this exponential to be positive and decreasing (i.e. y=a*exp(b*x) with a>0 and b<0).
I figured this is what I need (built using examples from helfile):
fo = fitoptions('Method','LinearLeastSquares',...
'Lower',[0,-Inf],...
'Upper',[Inf,0]);
ft = fittype('a*exp(b*x)','independent','x','coefficients',{'a','b'},'options','fo');
coeffs=fit(data(:,1),data(:,2), 'ft');
However, I get a weird error message while compiling:
To use 'copy', at least one of the following products must be licensed, installed, and enabled:
RF Toolbox
Simulink
Simulink Control Design
Simulink Design Optimization
Stateflow
Error in fittype>iParseParameters (line 567)
obj.fFitoptions = copy( value );
.....
Do I really need additional toolboxes, or is there a wrong syntax in my code that I can't see?
Thanks a lot in advance,
Francois

3 Comments

You need the curve fitting toolbox.
I have it, and it is activated too (otherwise Matlab would not even recognize the fit and fitoption functions)
Why do you write under "fitoptions" that it's a linear least squares problem ? It is not.
Further use
coeffs=fit(data(:,1),data(:,2), ft);
instead of
coeffs=fit(data(:,1),data(:,2), 'ft');

Sign in to comment.

 Accepted Answer

Ho thanks! Sorry I am new to Matlab and tend to get confused over what should be a string and what should not.
I finally managed now, actually skipping the whole fittype call and putting the fitoption as an argument to the fit function directly. I do not think this construction is very well explained in the help file...
for the record, this is how I made it work:
options = fitoptions('exp1');
options.Lower = [0 -Inf];
options.Upper = [Inf 0];
coeffs=fit(data(:,1),data(:,2), 'exp1',options);
Thanks again for your help, Torsten.

More Answers (2)

You do not need Simulink or the Curve Fitting Toolbox. You can use the more common Statistics and Machine Learning Toolbox and use fitnlm (Fit Non Linear Model). I'm attaching a demo.
0000 Screenshot.png
And this is probably the toolbox I will actually need. Thanks for the tip..

2 Comments

Not sure who your "Answer" here is talking to...
Or what toolbox you're referring to.
I was actually trying to reply to you... Statistics and machine learning Toolbox looks like what i should have requested from my office, had I known that it did include a fitting tool.

Sign in to comment.

Categories

Products

Release

R2018a

Asked:

on 16 Nov 2018

Commented:

on 16 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!