How to constrain the lower and upper bounds in lsqcurvefit?
Show older comments
Hi,
For a data set (x, y), I am trying to fit a function f(m, x) using lsqcurvefit. I write as follow:
x=xdata;
y=ydata;
fun=f(m,x);
m0=[m01; m02; m03]; %these are real numbers
lb=[0; 0; 0];
ub=[ub1; ub2; ub3]; %these are real numbers
m=lsqcurvefit(fun, m0, xdata, ydata, lb, ub);
However, sometimes it obeys the bounds and sometimes it does not while fitting. Could anyone please help me if there is any way of constraining the bounds?
Thank you very much in advance!
Kind regards,
Arun
7 Comments
Viren Gupta
on 2 Jan 2019
Edited: Viren Gupta
on 2 Jan 2019
Is the column vector - 'xdata' having the same dimensions as the column vector - lb and ub i.e 3*1?
Arun Kumar Bar
on 2 Jan 2019
Torsten
on 2 Jan 2019
sometimes it obeys the bounds and sometimes it does not while fitting
This might happen during the fitting process. Usually, the parameters only respect the prescribed bounds after fitting.
Arun Kumar Bar
on 2 Jan 2019
Arun Kumar Bar
on 2 Jan 2019
Edited: Matt J
on 2 Jan 2019
I don't get negative values when I run this code. I get complex ones,
output =
0.3528 + 0.0001i -3.5428 - 1.5825i 0.2693 + 0.0047i
0.3698 + 0.0000i -0.0523 - 0.0029i 0.2063 + 0.0017i
Your function is not real-valued at certain m in the search space.
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!