LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I fit a curve with two independant variables

I have looked at the General Polynomial Fit.Vi and it seems to be made for single variable functions (y=Fx). My project has empirical data from y=Fx,z. I am sure LabVIEW does this but I am not sure how. Can someone point me in the right direction please?
0 Kudos
Message 1 of 12
(7,903 Views)
Well, what is your definition of a 2D polynominal? Do you have an actual model function for your data?

(e.g.: z = Ax + Bx^2 + Dy + Ey^2 + Fxy + G ...)


I don't think this is directly available in LabVIEW, but it would not be too difficult to adapt the "nonliner Lev-Mar Fit.vi" for this use. I use it for all kinds of much more complex functions that that. 😉

In fact I did exactly the above described function last weekend and made a very simple demo using Lev-Mar subVIs that I modified from the stock versions a few years ago to allow fitting of arrays. In the case of arbitrary x-y data that is not on a regular grid, you would need to use extra connectors for the independent variables, etc.

(I have much more elaborate modified versions of
Lev-Mar for my own use, but the attached should be OK to show the principle.)

Enjoy!

Let me know if you have questions. There are probably a few minor errors in the code, but it seems to work just fine. Simply unzip the llb and run it (LabVIEW 7.1).
Message 2 of 12
(7,904 Views)
The model equation (where x is a function of C and of T) is as follows:
x=K1+K2/(C+K5*T*C)+K3/(C^2+C^2*K5*T+C^2*K5^2*T^2)+K4/(C^3+2*C^3*K5*T+2*C^3*K5^2*T^2+C^3*K5^3*T^3)

The example that you kindly provided would not open due to an error message stating that I needed LabVIEW 7.1: I am running the 2004 Feb upgrade (we did not renew the service in May - yet.)

I have noted in the Polynomial Fit VI that there is a model equation that may be edited but I have not found a discussion of how one should formulate such an equation for use by LabVIEW.
0 Kudos
Message 3 of 12
(7,903 Views)
Your code is awesome. I have taken a number of informal cracks at making a 2d lev mar function and have given up. I also want to complement you on your nice UI in the toplevel VI. It is clean and intuitive (plus it has directions if it is not so intutive for someone). Great Example!
0 Kudos
Message 4 of 12
(7,903 Views)
Here is the LabVIEW 7.0 version.

Just glancing at it, your function does not look like a simple polynominal, but is quite a bit more complex. (Unless it can be rewritten in some other form, which I haven't tried). 🙂 Note that my algorithm should have no problems dealing with your function. Do your function values form a regular grid or are they randomly distributed?

(Just a note to the demo: The function I quoted (z=Sum(A(n)x^py^q)) above could be easily implemented using the "general LS fit", which is a direct method. You would just index all your (x,y) pairs, then generate the "H" matrix by creating an array where each column (n) is the function with all A except A(n) set to zero and each row is the point index. If course thi
s will not work if the function is not a "k-dimension linear curve", as is the case with most of my problems. Lev-Mar converges in a few steps, so it's probably not worth re-inventing the wheel.)
0 Kudos
Message 5 of 12
(7,903 Views)
The function evolved when temperature compensation was introduced.
The equation was x = K1 + K2/P + K3/(P**2) + K4/(P**3)
and now P = C(1+K5T).

This looks more like the standard form.
0 Kudos
Message 6 of 12
(7,903 Views)
altenbach-

is there any chance you can save that code as version 6.1? 🙂 i tried writing something similar myself using powell's method (downhill gradient extrapolation thing), but it was very slow and slightly unpredictable.

thank you very much,
micah
0 Kudos
Message 7 of 12
(7,903 Views)
Micah,

I had quite a bit of trouble converting it back to 6.1 and it lost some functionality. When I first opened it in 6.1, I got an insane error and a few things were broken. I had to delete and redo the event assignements and it is now working.

Since 6.1 does not have signaling properties, you need to manually move one of the sliders to update the graphs after starting the program (I did not bother to code around this limitation). The rest seems to work fine.

(Whenever I go back to 6.1 or earlier, it amazes me how much easier, more functional, and better the 7.1 version is. Try to upgrade if you can.)
0 Kudos
Message 8 of 12
(7,903 Views)
altenbach-

thanks a ton. sorry it was such a pain to convert. now i just have to convince the rest of my lab to upgrade. 🙂

micah
0 Kudos
Message 9 of 12
(7,903 Views)
AWESOME Coding.
Looks good, very intuitive and easy to use.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 10 of 12
(7,903 Views)