Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Calculating a value from a collection of given points on the graph? (http://www.chiefdelphi.com/forums/showthread.php?t=102662)

Itamar 12-02-2012 18:48

Calculating a value from a collection of given points on the graph?
 
Hey. I need a function that does something like this: I give it a collection of (X, Y) points on my graph, plus another X point. Then the output is the Y coordinates in the given X. Something like this:



The blue points are given, and then I give another X value and get it's Y value. I went through a lot of the mathmatics functions and found nothing that performs this action, so it would be really helpful if anyone could help me find the right VI to do this.

thanks,
Itamar.

Ether 12-02-2012 18:56

Re: Calculating a value from a collection of given points on the graph?
 
Quote:

Originally Posted by Itamar (Post 1125182)
Hey. I need a function that does something like this: I give it a collection of (X, Y) points on my graph, plus another X point. Then the output is the Y coordinates in the given X. Something like this:



The blue points are given, and then I give another X value and get it's Y value. I went through a lot of the mathmatics functions and found nothing that performs this action, so it would be really helpful if anyone could help me find the right VI to do this.

thanks,
Itamar.

There are at least two classes of methods to do this.

Method1: Lookup Table.

You put the known X,Y points in a table (array) in your code, and you sort the points so that the X values are in order. Then you take your unknown X and search the table, comparing it to the X values in the table, until you find the two points in the table which it is between. Then you perform a calculation called "interpolation" to find the unknown Y value. This might sound difficult but it's really quite straightforward.

Method2: Mathematical Model

The most common mathematical model is a polynomial. You take all the given data and you try to find a polynomial which fits the data. Once you've got the polynomial, you just plug in your unknown X and compute the associated Y value. You can find this polynomial very easily using Excel spreadsheet using the "trendline" feature. Just type your X,Y data into Excel in to two columns, then graph it, then use the trendline feature to find a polynomial of chosen degree.


I'm not a LabVIEW guru and I don't have LabVIEW installed here, but I believe LabVIEW supports lookup tables. It wouldn't surprise me if it also has the ability to calculate the coefficients of a polynomial model for you as well. Try searching the LabVIEW help for those words.

Itamar 12-02-2012 19:04

Re: Calculating a value from a collection of given points on the graph?
 
Quote:

Originally Posted by Ether (Post 1125192)
There are at least two classes of methods to do this.

Method1: Lookup Table.

You put the known X,Y points in a table (array) in your code, and you sort the points so that the X values are in order. Then you take your unknown X and search the table, comparing it to the X values in the table, until you find the two points in the table which it is between. Then you perform a calculation called "interpolation" to find the unknown Y value. This might sound difficult but it's really quite straightforward.

Method2: Mathematical Model

The most common mathematical model is a polynomial. You take all the given data and you try to find a polynomial which fits the data. Once you've got the polynomial, you just plug in your unknown X and compute the associated Y value. You can find this polynomial very easily using Excel spreadsheet using the "trendline" feature. Just type your X,Y data into Excel in to two columns, then graph it, then use the trendline feature to find a polynomial of chosen degree.

Funny, those are actually exactly the two ideas which my friend and I thought of. To be honest, I was convinced LabVIEW is designed to solve these kind of problems with quick and easy-to-use VIs. We will probably go with the second solution. However, are you sure there isn't a VI that already does this? (not out of lazyness, it's just very surprising)

Ether 12-02-2012 19:07

Re: Calculating a value from a collection of given points on the graph?
 
Quote:

Originally Posted by Itamar (Post 1125205)
However, are you sure there isn't a VI that already does this? (not out of lazyness, it's just very surprising)

I didn't say there isn't a VI that does that.

I said I don't know. I'm not a seasoned LabVIEW user.


Alan Anderson 12-02-2012 20:20

Re: Calculating a value from a collection of given points on the graph?
 
You're looking for the Interpolate 1D function. It's in the Mathematics>Interpolation & Extrapolation function palette. You can select from many different methods by which it can do its job; the detailed help for the function does a good job of explaining what each method does.


All times are GMT -5. The time now is 11:17.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi