How to constrain lsqnonlin not to give me negative values???
Show older comments
Hi ! I am currently using the LSQNONLIN method in order to find the 4 variables of my equation that best fit on a know curve. I use lsqnonlin like this:
X0=[0 4,5 0 T];
options = optimset('Algorithm','levenberg-marquardt');
[fs,residual]=lsqnonlin(@OutInpDiff,X0,[],[],options);
My problem is that in the initial values X0; the fourth value (T) represents time delay. So when i run the program for different values sometimes for the best solution i get that the fourth parameter (T) have a negative value (T=-39.4521). That has no meaning since T is time delay.
So is there any way to constrain lsqnonlin to search for values which are greater than zero??
I tried
[fs,residual]=lsqnonlin(@OutInpDiff,X0,0,[],options);
but i still get negative values... What can i do? Thanks
Answers (1)
Titus Edelhofer
on 11 Mar 2012
Hi,
you should define 0 as lower bound for all the variables, i.e.
[rs, res] = lsqnonline(@OutInpDiff, X0, zeros(1,4), [], options);
Or, if the other may be negative:
[rs, res] = lsqnonline(@OutInpDiff, X0, [-inf,-inf,-inf, 0], [], options);
Titus
2 Comments
Walter Roberson
on 11 Mar 2012
Heh, I made exactly the same typo yesterday, lsqnonline in place of lsqnonlin
Titus Edelhofer
on 11 Mar 2012
;-)
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!