//====================================================================[include] #include ``cpplapack.h'' //======================================================================[solve] void solve(int N, CPPL::dcovector& x, CPPL::dcovector& y) { //// make dgematrix A //// CPPL::dgematrix A(x.l,N+1); for(int i=0; i<A.m; i++){for(int j=0; j<A.n; j++){ A(i,j) = std::pow(x(i), (double)j); }} //// solve Ak=y //// A.dgels(y); } //=======================================================================[main] /*! main */ int main(int argc, char** argv) { //// make dcovector x,y //// CPPL::dcovector x(4), y(4); x(0)=0; y(0)=-4.04; x(1)=1; y(1)=-1.98; x(2)=2; y(2)=2.02; x(3)=3; y(3)=13.86; //// solve //// solve(3,x,y); //// print //// for(int i=0; i<3; i++){ std::cout << ``k'' << i << ``='' << y(i) << std::endl; } return 0; }
k0=-4.04 k1=3.05667 k2=-1.98