I want to fit a curve using the lsqcurvefit function. It is something like this problem:
y = a1 * x + a2 * z
s.t
a1 > 0
a2 > 0
a1 + a2 <= some number
Is it possible to have such dynamic constraints in matlab or should i use some other package?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
lsqlin is the tool for your problem, as long as the constraints are linear equalities or inequalities. You have described the linear case, so this is the correct solution.
Had you shown an example with nonlinear constraints, you would then be forced to use fmincon (as suggested by Marcin) but this would be overkill for a fully linear problem. And of course, fmincon would also be considerably less efficient, because fmincon does not know that your objective is a linear least squares under constraints.
Finally, in order to use fmincon, you would need to define an objective as a sum of squares of the residuals. This latter step is not necessary for lsqlin, since lsqlin is designed explicitly to solve your class of problem.