LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

regression, y=ax+bx2

Solved!
Go to solution

No, it solves for a linear combination of arbitrarily defined functions of x. None of the function need to be linear.

 

 

(Details)

 

The functions can even be experimental data. For example they could be spectra of compounds a, b, and c.

Simply set up the H matrix with these spectra.

 

Now you can fit a composite spectrum of an unknown mix of these three components and will tells you how much of a, b, and c is in there. Very useful. 😄

0 Kudos
Message 11 of 15
(889 Views)

Indeed.....
But I have to understand the code.

What are you doing in the A x B.Vi ?
And what are the difference between H and Y in the fitting function?

Best wishes 

Michael

0 Kudos
Message 12 of 15
(863 Views)

A x B just simulates data according to the model, i.e. it creates a weighted sum of the two function represented in H (an array of all x and and array of all x². It basically calculates y = ax +bx² given a and b and an array of x. For realism, I add some gaussian noise.

 

(To include an offset term as in the polynomial fit, you could add a third column with all ones to H and use three coefficients, but then you might as well use the polynomial fit, which does the same thing under the hood ;). Once you include an offset, the function typically no longer goes through [0,0] of course)).

 

You would remove that simulation code and substitute your actual data as Y. Remember to generate the H matrix based on the size of your Y array and the x-values of your data.

 

"General linear fit" reverses the operations and tries to get the two coefficients (a and b) back. As you can see, it not only succeds, but the fitted data is also guaranteed to go through (0,0) due to the way H it setup in this special case.

0 Kudos
Message 13 of 15
(855 Views)

could H be an 2-dim array with the measured x and measured y?

0 Kudos
Message 14 of 15
(815 Views)

@Michael.Koppelgaard wrote:

could H be an 2-dim array with the measured x and measured y?


 

No, that would make no sense at all.

 

The input requrements of general linear fit are exactly defined. You cannot just make up your own definitions. Each row correspond to a specific x, and it does not really matter what each x is as long as they are different and the matrix does not get ill posed.

0 Kudos
Message 15 of 15
(805 Views)