LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to reverse 4th order polynomial expression?

This is not specifically a LabVIEW question, but a math question.

I have a set of data, defined by Y = A + BX + CX^2 + DX^3 + EX^4.

X would be a voltage, A,B,C,D,E are constants, and Y is a resulting measurement ( in engineering units).

I actually implement this (in code) as (((EX + D)X + C)X + B)X + A.

Now, because of design changes, I need to convert that data back to raw ("X") values. Can that be done, and if so, how?

In other words, given the above equation, and values for A,B,C,D,E, and (multiple, if necessary) values for Y, can I extract the X values that produced Y?

Or is it an irreversible equation?

It's been too many years since math class...

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 19
(6,694 Views)
"CoastalMaineBird" <x@no.email> wrote in message
news:1149648009024-375156@exchange.ni.com...
> This is not specifically a LabVIEW question, but a math question.
> I have a set of data, defined by Y = A + BX + CX^2 + DX^3 + EX^4.
> X would be a voltage, A,B,C,D,E are constants, and Y is a resulting
> measurement
> ( in engineering units).
> I actually implement this (in code) as (((EX + D)X + C)X + B)X + A.
>
> Now, because of design changes, I need to convert that data back to raw
> ("X") values.
> Can that be done, and if so, how?
> In other words, given the above equation, and values for A,B,C,D,E, and
> (multiple, if necessary) values for Y, can I extract the X values that
> produced Y?
> Or is it an irreversible equation?
> It's been too many years since math class...

Yes it is possible but you have a problem in that for every value of Y there
will be from 0 to 4 possible values for X.

Try using the Newton-Raphson Technique to locate the roots (X value) for
each of your Y values.

http://web.mit.edu/10.001/Web/Course_Notes/NLAE/node6.html



0 Kudos
Message 2 of 19
(6,698 Views)
Or you can do it another cheesy way,

Generate a curve of approximately 10 or 12 points over the range of interest, then reverse the X and Y arrays and fit a new 4th order polynomial.

I don't know the newtom raphson method, so no idea whether that's the better solution or not....

Shane (math-impaired)
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 19
(6,686 Views)


@CoastalMaineBird wrote:
I actually implement this (in code) as (((EX + D)X + C)X + B)X + A.


Easier would be to use the "polynomial evaluation" function. 🙂

Yes, in general there are between zero and four solutions, but for a typical calibration curve there is exactly one solution and you even know the lower and upper limits for X and Y. How accurate does it need to be? I agree with Keyser that newton-raphson should converge with a few iterations given a reasonable initial estimate, e.g. halfway between the upper and lower limits of X.

Message Edited by altenbach on 06-06-2006 11:31 PM

0 Kudos
Message 4 of 19
(6,690 Views)
OK, I made a quick example using Newton-Raphson (LabVIEW 7.1). It typically converges to better than 10e-10 in 5-6 iterations.
 
Let me know if it makes sense to you. Of course the algorithm can fail if there are multiple solutions or the initial estimate is too far off.
 
(VI may contain bugs, I only spent a few minutes on this). 🙂

Message Edited by altenbach on 06-07-2006 12:33 AM

Message 5 of 19
(6,678 Views)
Try using the Newton-Raphson Technique to locate the roots (X value) for each of your Y values.

Hmmm - I know the N-R technique for finding integer square roots, from back in the days when integer math was much faster than floating point...

It says that X(i+1) = X(i) - (X(i) * X(i) - Y) / (2 * X(i)). This will find the square root of Y, given an initial guess of X(0). The more iterations you go, the closer you get to the true answer.

I didn't realize it was generalized to any function.

I had seen the FUNCTIONS | ANALYZE | MATHEMATICS | ZEROES | COMPLEX POLYNOMIAL ROOTS vi. If I feed it the A,B,C,D,E, I get out four complex numbers, but I don't know what to do with them.

I see the NEWTON-RAPHSON ROOT FINDER in that same palette, I'll see what I can do with that.

Thanks...

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 19
(6,666 Views)
Easier would be to use the "polynomial evaluation" function.

Not so. Given 100 channels, with 100 {ABCDE} sets, and 100 samples (1 from each channel), it's way simpler (way faster, too) to multiply 100 X's by 100 E's, add 100 D's, multiply by 100 X's, add 100 C's, etc. etc.

The code is simple looking (8 operations total - no loops) and measurably faster (1/4 or so).

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 19
(6,660 Views)


@CoastalMaineBird wrote:
Easier would be to use the "polynomial evaluation" function.

Not so. Given 100 channels, with 100 {ABCDE} sets, and 100 samples (1 from each channel), it's way simpler (way faster, too) to multiply 100 X's by 100 E's, add 100 D's, multiply by 100 X's, add 100 C's, etc. etc.

The code is simple looking (8 operations total - no loops) and measurably faster (1/4 or so).



By "easier" I meant "dropping a single system VI and hooking up three connectors is easier than explicit multiplications". It is also much easier to modify it later for a 3rd, 5th, or even higher order polynomial, simply change the coefficient array size. 🙂 I usually don't worry about speed unless the difference is at least a factor of 2..10. 🙂

Anyway, If speed is really a concern and accurracy is less important, I would just create a calibration array of reasonable size, then use threshold array to find the solution by linear interpolation. Attached is a quick modification of my above example to demonstrate this suggestion.

0 Kudos
Message 8 of 19
(6,645 Views)
By "easier" I meant "dropping a single system VI and hooking up three connectors is easier than explicit multiplications".

Ah, but since I do it for a single sample, I have to BUILD ARRAY to turn that one sample into an array, and then INDEX ARRAY on the other side, just to extract it. And I would have to call the VI once for each channel, since each channel has its own ABCDE set.

I usually don't worry about speed unless the difference is at least a factor of 2..10.

Well, the factor is four in my tests, and I'm doing so much stuff I have to scrimp every chance I get.

Anyway, If speed is really a concern and accurracy is less important,

In the REVERSE case, I need accuracy more than speed. I will be undoing some previously recorded data files, and whether it takes a minute or and hour is unimportant, since I will only do that once.

In the FORWARD case, I need speed, which is why I did not use the EVAL POLYNOMIAL thingy.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 9 of 19
(6,630 Views)
Weird. When I tried to reply to your first example, I got another "Forums Are Closed for Maintenance" message. I've been getting that all day, trying to reply to you. But if I reply to your recent one it's OK...

OK, I made a quick example using Newton-Raphson

That works well PROVIDED I give it an initial guess that's in the right ballpark. But it suffers (just like the papers say) from the fact that if the guess is off, then it will home in on a different root.

In my case, since I'm measuring a continuous signal, I could use the previous value as a starting guess for the next sample, and it would probably STAY on track. But how do I make sure I'm following the right root to start with?

Maybe your linear estimate (example 2) will give me a good enough answer for that. In other words, use that for the initial guess, and then use the N-R technique for the rest. I suppose the curve is not going to be too extremely warped, or else you would lose 1:1 relationship between voltage and pressure (or whatever).

Does that make sense?

Does that sound reasonable?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 19
(6,628 Views)