12#ifndef BELFEM_FN_BZ_POLYFIT_HPP
13#define BELFEM_FN_BZ_POLYFIT_HPP
24 template<
typename T >
29 "Legnths of X and Y vectors do not match ( %lu and %lu )",
30 (
long unsigned int ) aX.length(),
31 (
long unsigned int ) aY.length() );
33 BELFEM_ASSERT( aX.length() > aN,
"not enough samples in vector to create a polynomial of degree %u",
34 (
unsigned int ) aN );
40 index_t tNumSamples = aX.length();
50 T tXref = ( tNumSamples - 1 ) / ( aX( tNumSamples - 1 ) - aX( 0 ) );
53 for(
index_t k=0; k<tNumSamples; ++k )
56 T tX = aX( k ) * tXref;
59 tVandermonde( k, aN ) = 1.0;
61 for(
int i=aN-1;
i>=0; --
i )
63 tVandermonde( k, i ) = tVandermonde( k, i+1 ) * tX ;
73 gels( tVandermonde, tRHS, tWork );
76 aCoeffs.set_size( tN );
80 for(
int i=aN;
i>=0; --
i )
82 aCoeffs( i ) = tRHS( i ) * tScale;
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Dense column-major matrix.
Definition cl_BZ_Matrix.hpp:28
Column vector.
Definition cl_BZ_Vector.hpp:41
Least-squares or minimum-norm solution of a full-rank system (LAPACK ?gels).
USER GUIDES:
Definition cl_Capacitor.cpp:16
int_t gels(Matrix< T > &A, Vector< T > &B, Vector< T > &Work, const bool AbortOnError=true)
solve the least squares problem min || A * x - b || via LAPACK ?gels ( QR or LQ factorization,...
Definition fn_gels.hpp:278
@ T
Definition cl_Material.hpp:122
unsigned int uint
Definition typedefs.hpp:30
void polyfit(const Vector< T > &aX, const Vector< T > &aY, const uint &aN, Vector< T > &aCoeffs)
Definition fn_AR_polyfit.hpp:25
uint32_t index_t
Definition typedefs.hpp:52