06-01-2009 11:41 PM - edited 06-01-2009 11:44 PM
You forgot to wire the variant to the fit VI! 😉
Here's a quick modification that seems to work just fine. Note: you don't need a temperature control in the model subVI. Just use a diagram constant, the value is irrelevant. Also "index array is resizeable, so you can get both slices at once.

06-02-2009 12:12 AM
07-27-2009 12:56 AM
So I thought I had sorted out my fitting algorithm problem, and to some extent I have. I can now put data in and get it to fit (I was able to do this after that last message). My problem now, however, is that I finally have some real data (although it isn't particularly great) and I was just tryings to fit it to my theory just to have a play around with things. What I have realised is that one of my fitting parameters doesn't not appear to be acting as a variable most of time. I have 3 variables, these are G, kappa (I acutally use the symbol) and hm and in the fit function these are a1, a2 and a3, respectively. My problem is typcially when I put in a value for kappa in the initiall fitting parameters, it remains the same after the fit. So effectively, the other two variables are actually varying but kappa is not. It is important for my work that kappa be allowed to vary vary whilst the data is being fitted. I have looked through the code and I can't seem to find any reason as to why I am having this trouble.
I am using LV 8.6.1 and I have included my vis and my data in a zip file.
Thanks again for any help that you can give.
07-27-2009 03:24 AM - edited 07-27-2009 03:26 AM
I have not fully inverstigated this, but my best guess is that your matrices become ill conditioned because some of your parameters differ by a factor of 10e20.
For example if you would multiply G with 1e-12 and kappa with 1e8 inside the model and use initial paramters of 1,1,0 (~within a factor of 10), everything works perfectly. So maybe try some better scaling. Just scale the result back after the fit.
On a side note, long ago I wrote a drop-in replacement for the nonlinear curve fit that uses Nelder-Mead (simplex) instead (no matrices and no partial derivatives!) and it works perfectly with your data if the initial simplex is scaled properly (see image below). It gives the same result and same residual as the scaled workaround.
I will probably release it to the public sometime after NI week, so stay tuned.

Note that the fit is not great near the edges, because you are downweighting these parts significantly. I guess that's want you want.
07-27-2009 03:47 AM
07-27-2009 10:46 AM - edited 07-27-2009 10:49 AM
Here's one possibility to stabilize the fitting. The factors can easily be wrong by a few orders of magnitude, so you can probably keep them as diagram constants as shown here. I use the data variant to tell the model what the factors are.

I also cleaned up some of the code. Do you really need four (!) diagram comments to label what (X) and (Y) are? One is enough (see image above). I also placed the parameter names into the captions so they stay with the controls and indictators.
See if this makes sense.
07-27-2009 07:55 PM