LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding best fit equation for two knows variables

Solved!
Go to solution

I have some chart in excel, where I get two values from measurment, lets say Va and Vb.

Now I need to find the best fit equation for it?

can labview do it?

0 Kudos
Message 1 of 34
(3,867 Views)

Edit: wha ti wanted to know equation would be 

C = some equation of (A,B)

 

A,B, & C values I know, want to find equation where I can put A&B values and get C from it.

0 Kudos
Message 2 of 34
(3,859 Views)

If you have only two points, you can fit basically anything to it.

 

The most common solution (and perhaps what you're asking for) is a linear fit - a straight line that goes through your two points with the equation "y = mx + c".

To solve for that equation, you'd want to write your results as follows:

 

Va = m * Xa (whatever your input is at measurement a) + c

Vb = (m * Xb) + c

 

Vb - Va = (m * Xa) + c - (m * Xb) - c = m * (Xa - Xb).

Since you know Xa and Xb and Va and Vb, you can calculate "m" from this.

 

Then, substitute into one of your starting equations to find c.

Now you have a linear equation that goes through your two points.

 

Note that this has nothing to do with LabVIEW - it's just algebra.

 

Implementing it in LabVIEW can be done with the nodes on the Numeric palette (i.e. subtract, multiply, etc).

You can also use a graph and something like a For loop to plot a line that highlights your solution.

 

For more complicated assumed equations, you can use more advanced tools like the Fitting VIs. However, for an equation of greater than linear complexity you'll need more than 2 points (results) to be able to solve it.


GCentral
Message 3 of 34
(3,843 Views)

i have around 200 value sets where i know C,A,B

Need to form equaton, its not linear fit.

would be something like this I guess, but not sure.  So what labview function for this?

 

 
 

ddd.png

 

0 Kudos
Message 4 of 34
(3,810 Views)

I think you probably want to take a look at this VI - it can be used generally to solve this kind of fitting problem: Nonlinear Curve Fit

This page will give more information about its usage: Creating the Formula String or Fitting Model to Specify a Nonlinear Function

 

Christian Altenbach gave a presentation about the use of this function (amongst others) that can be found here: slides. Unfortunately I can't find a video anymore...

 


GCentral
0 Kudos
Message 5 of 34
(3,806 Views)

@Vindhyachal.Takniki wrote:

i have around 200 value sets where i know C,A,B

Need to form equaton, its not linear fit.

would be something like this I guess, but not sure.  So what labview function for this?

 

 
 

ddd.png


If you are not "sure", you need to fully research the problem until you are. Nobody can solve a "not sure" problem.

 

Your question makes no sense because your function shown does not even contain any C, A, or B.

 

  • What are the model parameters?
  • What is/are the independent variable(s)?
  • What is the dependent variable?

 

How does the set of 200 C, A, B values look like? What does the data represent? What are you trying to learn from it?

 

0 Kudos
Message 6 of 34
(3,778 Views)
Solution
Accepted by topic author Vindhyachal.Takniki

For simplicity, let's redefine C=z, A=x, B=y, so  basically you have 200 scattered (xyz) points in space. If these points form some kind of unique plane where for any arbitrary [x,y] a "z" can be estimated, you can fit it to a model that describes this plane. It could be a higher order 2D polynomial or any other model based on an underlying theory. The plane is then defined by the set of model parameters (a0, a1, a2, aN) And for each arbitrary x,y points, a unique Z can be found based on the best fit parameters and a given [x,y]. Do the x,y point form a regular grid?

 

Start reading here.

 

 

OTOH, if the model is discrete and only exists at the given x,y points, you could use a map (requires LabVIEW 2019 or newer!) serving as a lookup table. The key would be a 2D array containing x and y and the value would be z. (Be careful with any key datatype where equal comparisons are questionable (e.g. DBL))

Message 7 of 34
(3,774 Views)

Thanks @

0 Kudos
Message 8 of 34
(3,706 Views)

Can it be used to make equation where:

1. A= fun(x,y,z)  where 4 paramters are known and need to make equation

 

2. Also in above equation generated is quite complex for low power MCU computation, any method where lesser order polynomial can be made. 

In my case error margin of less than +-0.5 is acceptable.

 

 

0 Kudos
Message 9 of 34
(3,701 Views)

@Vindhyachal.Takniki wrote:

Can it be used to make equation where:

1. A= fun(x,y,z)  where 4 paramters are known and need to make equation


Yes, it can be expanded to any number of dimensions. The general technique stays exactly the same.

 


@Vindhyachal.Takniki wrote:

2. Also in above equation generated is quite complex for low power MCU computation, any method where lesser order polynomial can be made. 

In my case error margin of less than +-0.5 is acceptable.


A polynomial in any number of dimensions is not "complex". A polynomial is generic and only defined by the number of terms. Start with low order, the increase the order until the result is withing the desired margins. If it still does not fit with a ~third order, maybe you need to create a model based on some theory.

 

It really depends on the data ±0.5 is excellent if the data is in the millions, but very poor if the data is in the nano or micro range.

 

0 Kudos
Message 10 of 34
(3,674 Views)