The core of the fitting is based on the stock Lev-Mar VI but it assumes that the function outputs all y values in one swoop (The stock VI requires the function to be calculated one point at a time, which makes it more restrictive and unsuitable more many models). All the skeleton code is plain Levenberg-Marquardt. It optimizes a set of function parameters to produce a closest match between a calculate and an experimental dataset (based on chi-square criterium).
You definitely have to make some modifications, but most of what you need is in place.
You need for example the following:
Provide a way for the function subroutine to get the x1, and x2 inputs so it can calculate y according to your mathematical model.Note that the "2DNonlinear Lev-Mar Fit.vi" already has an array input labeled x, however it is not used in my particular simplified application because the subVI creates a fixed square lattice of know size. You need to add a connector to the function to receive all your x1, x2 values so it can output a calculated y-array to be compared with your experimental y data for all the same x1, x2 combinations. It does not matter how you design these inputs, it only matters that the function outputs a 1D array of the correct length. For example you could interleave your x1, x2 pairs, send them along the x array input then decimate them in the function VI.
Write a function subroutine for your model.As mentioned, it should receive the x1, x2 pairs so you need to add a connector and change the template. In addition, it also needs to receive an array of your fitting parameters. I would arrange them in the following order:
(A, B, a, b, c, d, e, f ...).
This way, the function can determine the order of the polynomial straight from the lenght of the parameter array and should directly work for any choose order you want. Simply truncate this array at runtime if you want to lower the polynomial order.
🙂The output is the y-array.
Create a user interface to pick good initial guesses for the paramteresCreate a graph to display your y data for all your measured points overlayed with simulated data using your the function subroutine above and your parameter guesses. Now manually adjust the parameters until there is reasonable agreement. Levenberg-Marquardt does not guarantee results if the initial guesses are way off or unreasonable. It really depends on the model how robust the fitting is (In my example, it is very robust and the initial guesses can be zero for all parameters). Once you're in the ball park, call the fitting VI using these initial guesses.
Maybe this can get you in the right direction. It would probably take me at least an hour to do implement the above suggestion, but I'm currently quite busy with other things. If you get stuck, please give me an experimental data set and I'll play with it a bit. It does not look very hard, but it would be weird flying blind without real data for testing. If you want, you can contact me further via the e-mail address given on the front panel of the discussed VI.