04-18-2015 04:12 AM
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. 😄
04-19-2015 01:18 PM
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
04-19-2015 01:51 PM
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.
04-20-2015 07:38 AM
could H be an 2-dim array with the measured x and measured y?
04-20-2015 11:08 AM - edited 04-20-2015 11:09 AM
@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.