10-21-2011 05:02 PM
Hi. I have a rather complicated curve fitting problem.
Attached are 2 images noted with numbers 1. and 2. and 3.
Basically, the formula expression in 1. represents the graph in 3. and Non-linear fitting model has to keep checking for the closest match until the formulae on 2. is satisfied.
I checked the Lev-Mar Nonlinear Curve fit VI, but I don't quite know how to represent the formula on 1. in a string format. Furthermore, the VI seems to run based on the amount of iterations that user specifies, I however need to replace that with formula 3. where the VI should continue to run untill expression on 3. is satisfied to a certain degree. i.e. 0.0001 accuracy.
Any thoughts are appreciated.
Thanks
Kas
10-21-2011 05:53 PM
What are M and A in image 2?
Could it be you are looking for the "least absolute residual" instead of "least squares"? The constrained nonlinear fit has several methods available.
No need to make a formula. Simply create a subVI that matches the model template and incorporates your model as a function of [X] and your model parameters.
See how far you get?
In image 2, what are constants and what are the fitting paramters? What is the independent variable? Can you point to a website that describes the theory behind it?
10-21-2011 06:29 PM - edited 10-21-2011 06:29 PM
"What are M and A in image 2?"
M & A represent the Magnitude and Phase of an FFT (i.e. The real part of a complex FFT and the Phase).
"Could it be you are looking for the "least absolute residual" instead of "least squares"?"
I'm not really sure about this.
In image 2, what are constants and what are the fitting paramters?
The fitting parameters are "n" and "k" on image 1, representing refractive index and absorption coefficient respectevly, basically, image 3 shows the Real part of an FFT. Image 1 is a trasnfer function that explains image 3 in IDEAL situation, so, I am trying to recreate Image 3 from an Ideal function by replacing the "n" and "k" values constantly untill image 2 is satisfied. Image 2 basically gives the difference between the actual parameters (i.e. image 3) that were practically measured, and the recreated parameters (estimated from Lev-Med) algorithm.
"Can you point to a website that describes the theory behind it?"
Attached is a paper where they describe this process. It has some physics involved but it should be a light read. They use the "Nelder-Mead algorithm" (i.e. the Downhill Simplex nD VI ), but I find it even more difficult to implement this formula on this VI.
"Simply create a subVI that matches the model template and incorporates your model as a function of [X] and your model parameters"
Is it possible to give just a simple example VI that includes a "summation and an exponential" form, maybe I can built on that the more complex formula from image 1.
Overall:
Even that image 1 contains alot of letters, the only variables are "ns - as seen on image" and "k", all others are defined descrete values. I can perhaps replace all the letters in image 1 with numbers and only leave "n" and "k" as variables to make it easier, and make that as the starting point in building the VI.
Thanks
10-24-2011 06:11 AM - edited 10-24-2011 06:14 AM
Hi zerotolerance,
- How have you been getting on with this?
You asked for a simple example of implementing a summation and exponential function. You can achieve this as follows:
- The exponential function is used in the above example.
- This used a For Loop where the number of iterations is set by m_echo and the 'Constant' would be replaced by your summation function.
These are simplified examples but hopefully it gives you a starting point. Additionally, if you are more accustomed to using text-based techniques, there is the mathscript node available.
Please let me know if you have any questions.
10-24-2011 10:53 AM
There is also "add array elements" as well as the various numerical integration function (evenly spaced, unevely spaced), etc.
10-25-2011 07:38 PM
Thanks for your replies. I've been working till now to get this problem sorted. Attached is my result.
I am alittle confused since the "Best Nonlinear Fit" comes pretty close to the actual measurement results, but the "Best Fit Parameters" only comes back as 2 values. Should it not be an array for "n" and an array for "k"? Since n & k are both frequency dependent i.e. one value of n & k are correct for only one frequency, and for the next frequency than different values of n & k.
Thanks again for your replies.
Kas
10-26-2011 08:53 AM
Would anyone know on how I can solve the above issue?
Thanks
Kas
10-26-2011 12:40 PM - edited 10-26-2011 12:41 PM
Attached is the attempt that I made in solving the issue of the previous post. Now I get array of values for both n & k. and when I plot them, I get a much better fit. However, when I ran the software, I get the following error:
" The system of equations cannot be solved because the input matrix is singular"
The difference between this and the previous example is that this time I use the algorithm to match the best case for n & k for 1 frequency only i.e. 1 point. and the algorithm runs for all available points untill I get a set of n & k values for all frequencies. Trouble is, "n" represents the refractive index of a material, and even though I get a really good match with the measured parameters, the refractive index is less than 1, where this can never be the case, since the refractive index of air is 1. I'm hoping that if I sort out the error, I might get the correct results.
Any thoughts and help is appriciatted.
Thanks
Kas
P.S. If you need help runnig the attached example let me know.
10-26-2011 04:14 PM
Hello again (I hope someone is still around). I just realised that the "Lev-Mar" algorithm is no good for for this project. It seems to depend on the gradient and the derivitive of the function. Since My function is involved in discrete values, I don't think this algorithm is good. As such I'm trying to implement similar idea based on the "Simplex" method. Attached I found an example, but I don't know how I can transfer my function into a string, since it involves exponentials, and the input to the "Simplex" algorithm is only in strings.
"Untitled 2" is my actual function that I want to convert into a string, similar to what the attached VI is doing.
Any help is well appriciatted.
Thanks again
Kas
10-27-2011 02:56 AM
Can anyone shed some light into this?
I'm alittle bit stuck. Tried all night and nothing works.
Thanks in advanced.
Kas