LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Which command (function) in Advanced Analysis Library I can use for least square fit method (ie: Curve Fitting)?

I have to use the Gauss-Jordan elimination to solve the linear equation system when the degree polymonial degree is greater than 1. The problem is I am the end-programmer: means I will receive 3 parameters to do this function:
 
1. An array of X coordinate of M points
2. An array of Y coordinate of M points
3. The dgree of polymonial request for the approximation (N)
 
Then return an coeffficient array that contains (N+1) of the polymonial
 
ie:  arr_coeff = myfunctionLeastSquareFit( arr_x, arr_y, 1);  // where arr_x = [0,1,2,3] arr_y = [0,1,2,3]
 
Which closest command I should use in Advanced Analysis Library to comply this function?
 
Note: Just for more info. this function return, will use for the next function:   interpolate(arr_coeff, data);  // where data[5,6]
 
Thanks for any help
0 Kudos
Message 1 of 6
(3,711 Views)
I'm not so fond on matrix calculations as to get its connections with curve fitting, but PoliFit is the function I normally use to perform curve fitting on array of measures; it uses the least square method and returns both the array of coefficients and the curve already fitted. It's possibly what you're looking for...


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,693 Views)
I did try the PolyFit as you suggested, but the result is not good for order of 3 (3rd degree).
 
1.  After calling sci_leastSquareFit(...) the db_arrRet contains 4 coefficiences not the same with the General Poly fit.vi in LabView
 
2. Then after using the values to work with my sci_interpolate(...), the responses are bad ... you can run my attached project to see the weird graph after applying function calls
 
*) However with Labview: they are working well after applying the Labview result with Interpolate.vi
 
I do not what I have done incorrectely? Can you take a look ... since you mentioned that you did use them OK?
 
Thanks
0 Kudos
Message 3 of 6
(3,665 Views)

I'm not sure why you explicitly assign the coefficient values to db_arrM[] in sci_interpolate(), but you have made a mistake with the sign of the fourth coefficient db_arrM[3].

If you comment out the lines:

//db_arrM[0] = -0.27;
//db_arrM[1] = 2.807;
//db_arrM[2] = -0.52;
//db_arrM[3] = -0.02;

then the second graph has a typical cubic shape that is a reasonable match to your orignal curve (see attached screenshot).

--
Martin
Certified CVI Developer
0 Kudos
Message 4 of 6
(3,653 Views)
I second Martin suggestion, confirming that coefficients calculated by CVI PolyFit funcion are the same as those calculated by LV General Polynomial Fit.VI. As an additional notice, every time I compared them in the past PolyFit returned almost the same coefficients as "Add trendline" facility in Excel.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 6
(3,640 Views)
The real story is on Friday afternoon, after trying some thing does not work well, I did assigned those constant values from Labview to verify my functions ... and somehow I mexed-up & forget to remove it! Thanks for pointing out these, now I feel better ... because I did verify many times those functions & could not find the errors (my real program, I call functions not in the same locations in Graph.c ... that was why I did not see those assign in main program
 
Thanks again
0 Kudos
Message 6 of 6
(3,635 Views)