0

I'm using the fitnlm function within Matlab to calculate three coefficients. To improve the results, I know that two of the coefficients need to be positive and the third to be from 0 - 360 degrees. How can I add these assumptions into the model? I've looked through the help files and can't seem to find anything that helps. The following is the code I have used:

modelfun = @(b,x)b(1)*(1/b(2)) - (b(1)/cp).*cos(Rays).*(cos(X1)*cos(b(3)) - sin(X1)*sin(b(3)));
beta0=[0.15 2.5 0];
mdl=fitnlm(X1,Y,modelfun,beta0)

Thanks for the help

James

Whitt
  • 1
  • 1
  • 1
    Since what you are trying to solve is a **constrained nonlinear optimization** problem, you should look into [`fmincon`](http://www.mathworks.com/help/optim/ug/fmincon.html). (Note that this requires the _Optimization_, and **not** the _Statistics_, toolbox) – Dev-iL Oct 13 '16 at 11:51
  • Thanks for the idea, the optimization tool box was the way to go. I didn't end up using fmincon in the end and used lsqcurvefit as this takes into account the regression of the variables not just solving the equation for a set range. Seems to be working well so far though, cheers! – Whitt Oct 13 '16 at 15:23
  • Cool. If it's not something confidential, you might want to add the solution you found as an answer to this question to help future readers with the same problem. – Dev-iL Oct 13 '16 at 16:06

0 Answers0