NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
14-numcxx-lapack-sharedptr.cxx

Use of lapack solver for sparse matrices, shared pointer idiom

#include <iostream>
#include <limits>
int main(void)
{
int n=5000;
// Here, we need to derefernce the smart pointer to references
// in order to use the () operator in a convenient way.
auto &A=*pA;
auto &F=*pF;
auto &U=*pU;
F=1.0;
for (int i=0;i<n;i++)
{
A(i,i)=3.0;
if (i>0) A(i,i-1)=-1;
if (i<n-1) A(i,i+1)=-1;
}
pLapack->solve(U,F);
double residual=normi(A*U-F);
std::cout << "residual:" << residual << std::endl;
}