2013-05-19

Same curve fit, but using levmar

Using Matlab's cftool for curve fitting is probably too expensive for home use. When I did that curve fit, I chose the Levenberg-Marquardt algorithm and applied suitable bounds for the coefficients. Suitable in this case meant that $K_0 > 0$, $K_T >0$ and $E_K > 0$. There are C++ implementations of the LMA available, such as the levmar library.

I tried to use that instead of Matlab and almost immediately got the same results for the parameters, which is great. It was as simple as taking the example that came with levmar and modifying it to suit my needs:
  • Wrote a model function that returns $T_A(P)$ in steady state;
  • Supplied the $T_A$ measurements as the measurement vector x;
  • Wrote a vector for the lower bounds (with low values for the parameters, like $0.01$);
  • Used dlevmar_bc_dif (double precision levmar with box constraints and finite difference approximated Jacobian) for solving the minimization problem;
  • As levmar has no way to directly pass inputs to the model, I passed the power settings in the additional data argument.
I could have also used inequality constraints instead, but I just started with box constraints and got satisfactory results. I might need them though when the model gets more complicated. The levmar library also offers linear equation constraints, and all (box, linear equation, and inequality) can be combined.

No comments:

Post a Comment