- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
I need to make a function that performs the most suitable (in the sense of least squares) polynomial in one variable from Cartesian coordinates.
There is such a function in Matlab - it is called polyfit().
I know that OneMKL has a set of functions that do piecewise linear interpolation using splines.
I cannot figure out how to use OnMKL to make an analogue of the from Matlab's polyfit() function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is C code in an earlier post in this forum for using LapackE-GELS to fit a polynomial in two independent variables, x and y. You can adapt that code by simply removing the portions that contain y and adjusting the indices of the regression matrix A to match.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Given m-vectors x and y, to fit a polynomial of degree n, form the m X (n+1) Vandermonde matrix, and call MKL/Lapack GELS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, mecej4.
Thanks for your reply.
I understood, I need to use MKL/Lapack GELS. Ok.
But could you explain more detail please, how to use, for example dgets().
In my opinion, I should send the input data x() and y() and receive in response the coefficients of the polynomial C0, C1. I don't understand where I should insert my x() and y() data.
// Function prototype
dgels( const char* trans, const MKL_INT* m, const MKL_INT* n,
const MKL_INT* nrhs, double* a, const MKL_INT* lda, double* b,
const MKL_INT* ldb, double* work, const MKL_INT* lwork,
MKL_INT* info );
// I have 2 vectors:
std::vector<double> x = {2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // the size is variable
std::vector<double> y = {10.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0};
// Prepare data for dgels()
#define PolynomOrder 1
int m = x.size(); // number of rows of the matrix A
int n = PolynomOrder + 1; // number of of columns of the matrix A
int nrhs = 1; // the number of columns in B
int lda = std::max(1, m);
int ldb = std::max(std::max(1, m), n);
int lwork = std::min(m, n)+ std::max(std::max(1, m), std::max(n, nrhs));
double work; // What is this?
int info = 0;
// ...form the Vandermonde matrix - mX(n+1) | How to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is C code in an earlier post in this forum for using LapackE-GELS to fit a polynomial in two independent variables, x and y. You can adapt that code by simply removing the portions that contain y and adjusting the indices of the regression matrix A to match.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for accepting as a Solution.
As this issue has been resolved, we will no longer respond to this thread. If you require any additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.
Have a Good day.
Regards
Rajesh
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page