Setup sparse matrix and solving laplace equation

(Petras Vestartas) #1


I am new to mathdotnet but I would like to learn how to setup sparsematrix and solve laplace equation Lx = b.

Before I was using Eigen library in C++

And the syntax looked like this for solving equation Lx = B: - x is unknown

Eigen::SparseMatrix<double> L(n, n); // nonzero elements of L as triplets: (row, column, value)
Eigen::MatrixXd rhs(Eigen::MatrixXd::Zero(n, 1)); //B matrix

Then I setup L matrix from triplets
std::vector< Eigen::Triplet<double> > triplets_L;
build sparse matrix from triplets
L.setFromTriplets(triplets_L.begin(), triplets_L.end());

and solve matrix

Eigen::SparseLU< Eigen::SparseMatrix<double> > solver(L);
Eigen::MatrixXd x = solver.solve(rhs);

So the final result I seek is X matrix is there similar workflow in math dot net?
Or can someone point me to how to setup Ax = B equation for solving sparse matrix?