amirvahid
09-22-2009, 01:01 PM
Hi Dave,
What is the general routine for fitting a "non-linear function" to a "multidimentional" (NOT just a vector) matrix of data using Levenberg-Marquardt method? Thanks
amirvahid
09-23-2009, 01:46 PM
I think that the "LM" method is one of the most reliable methods when you are dealing with a multidimensional matrix of data and trying to fit a non-linear function to it. I wonder if someone can help me writing the general routine for it and provide a working example. I appreciate it!
amirvahid
09-24-2009, 07:09 PM
I refer readers interested in this discussion to the following thread :
http://www.nr.com/forum/showthread.php?t=1689
Thanks
Robert McLean
10-21-2009, 05:24 PM
I find the suggestions in the thread you posted to be way more complicated than needed, but it may be that I just dont understand them.
I got the first edition of NR back in the 80s, I was using Turbo Pascal and this is how I did multidimensional fitting. Routine was called MRQMIN back then.
The trick is that you do not pass your multidimensional array to the function directly, you cant, it takes a double type. Instead, you pass the index to your array, after converting it to double. Then your function looks up the values in your array, and uses them in the calculation of the return value y and the derivatives dyda. You need to make your multidimensional array a global variable, or a member of a class or in some other way accessible to your function.
For example in my case I am modeling an electronic device with a current Ip dependant on 3 voltages Vp, Vs, Vg. So I have arrays
Vp[x], Vs[x], Vg[x] of the measured voltages, an array Ip[x] of measured currents , and I want to determine model parameter to give best fit of Ip to Imodel.
I make an array x setting x[row] = row for each element. Then I send x to my funcs, ( called BasicPentode here)
void BasicPentode(const Doub x, VecDoub_I &Params, Doub &Ipmodel, VecDoub_O &dyda )
Then my function looks up Vp[x], Vs[x], Vg[x] etc and does its calculations.
Ip[x ] is the yy array required by fitmrq, which it compares to Imodel etc etc.
This is what I did in Turbo Pascal, so I know it works, I am now converting to C++ and the NR3 routines.
amirvahid
10-21-2009, 07:02 PM
Thanks Michael,
Can you send a complete small code that is working. I want to see how it works b/c I really confused with mrqmin.