Nanna Pedersen <firstname.lastname@example.org> wrote in message <email@example.com>... > Hi everyone. > > I am using lsqcurvefit to fit a signalequation to some data. I am using the Levenberg-Marqaurdt algorithm but would really like to put some boundary constraints on the output. The most important constraint is that all the output parameters are positive but I would like to constrain the values to certain ranges. > > lsqcurvefit does not accept boundary constraints for the Levenberg-Marquardt algorithm, so do any of you have an idea how I can cheat lsqcurvefit to accept boundary conditions indirectly somehow or (even better): do any of you know of another implementation in matlab? > > Thank you! > > Best regards, Nanna
Instead of the parameter p handed to you in the function routine of lsqcurvefit, use p'=(lb+ub)/2 + sin(p)*(ub-lb)/2 in the evaluation of your residuals. Then p' ranges from lb to ub where lb is a lower bound and ub is an upper bound for the parameter you want to fit.