LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

inverse prediction order 2 or 3 polynomials

Any idea on how to compute, using LabVIEW, the inverse prediction of X from a given Y using a fit of order 2 or order 3 polynomials ?
 
order 2          Y = a + b*X + c*X**2
 
order 3          Y = a + b*X + c*X**2 + d*X**3
 
Regression coefficients a,b,c & d are obtained using the "Levenberg-Marquardt algorithm " as implemented in the LabVIEW Nonlinear Lev-Mar Fit.vi
 
X acceptable area will be given manually by the user to select between different solutions.
 
Any example code would be very wellcome
 
Thanks in advance
0 Kudos
Message 1 of 15
(5,196 Views)
It's not trivial, since a 2nd or 3rd order polanomial can have multiple X values for a given Y value...... This can really rear it's ugly head and bite you at a later date......

Why not implement an approximation....  You can set bounds and do an iterative backwards calculation to approximate the solution you require.

i.e. X0=0, X0.5=0.5, X1=1 evaluate Y0, Y0.5 and Y1. If Ytarget is between Y0 and Y0.5, take X0 and X0.5 as your new X0 and X1 (re-calculate X0.5) and re-iterate.  Repeat until the absolute difference between X0 and X1 are small enough to not bother you (1E-8?).  Should require max 27 Iterations to find a solution within 1E-8.....

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 2 of 15
(5,178 Views)

Thanks,

your option seems quite simple to implement, & I guess I know how to choose the first X0 & X1 values, deriving them from the user's choice on the actual regression curve monotonous sub zone.

CheersSmiley Very Happy

0 Kudos
Message 3 of 15
(5,175 Views)
Indeed it's quite simple.  Not neccessarily the most efficient, but it's not too bad either.  Since we're dealing with Floating point values, an approximation to a certain level (15 digits for DBL) will hardly be noticeable.

The nice thing about this approach is that it allows you to stick with a single polynomial.....

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 4 of 15
(5,167 Views)

Hi Shane

a quick implementation of your method works fine with both order 2 & 3 polynomials, as long as I stick to the first X0 to X1 sub zone.

Here is the little VI I did put together. Coeff for both examples you see on the graph pictures are loaded when you run the VI.

If you choose order 2 for instance, an Y value that would be on the example curve, & the first X range from 1 to 4, GREAT approx.

If you do the same using X Range from 4.5 to 8 to get another solution, the method does not find the correct value & return one of the range limit.

Any idea how I should make the system more robust ? Users should still have to select the proper range.

Thanks

PS : sorry my math courses are so old...

Using LV 7.1 & LV8.20 on WXP SP2

0 Kudos
Message 5 of 15
(5,145 Views)
Apart from the fact that you can do away with the formula node to make the code deal with ANY size polynomial and you have some unneccessary code, it's very close to what you want.

Here's a slightly changed version.

You forgot to make sure that the values going to the "high" and "low" input of the "In range and coerce" function really are the high and low values.  I've inserted a primitive (Max-min) into the code to make sure of this.  I think you'll find it works much better now.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 6 of 15
(5,137 Views)

First of all, don't use Levenberg Marquardt for a polynomial fit. It's overkill. There is a polynomial fit built-in. 🙂

Easiest would be to adjust your constant term by subtracting the desired y and use "Polynomial roots". Use all real solutions and ignore the imaginary ones. 🙂

0 Kudos
Message 7 of 15
(5,130 Views)
Here's a quick draft of what I had in mind. Seems to work well. 🙂
 
Modify as needed.
 
 

Message Edited by altenbach on 09-05-2007 01:30 PM

Download All
Message 8 of 15
(5,126 Views)
Using my code, you can then simply get the soution that is in the desired x range.
0 Kudos
Message 9 of 15
(5,094 Views)

Thanks Shane

that was indeed very simple. I know I should get id of the formula node but I have no need for polynomials with different orders than 2 a 3.

Your simple correction makes it work fine

 

Thanks a lot Smiley Very Happy

0 Kudos
Message 10 of 15
(5,078 Views)