# Linear algebra(Matrix, Vector and Solver) in dolfin

Asked by Xujun Zhao on 2013-04-08

I am developing my own codes on top of dolfin. Now I meet a problem:
I need to solve a linear equation: Ax = b, which is a small size equation.
In the first place, I tried to use Matrix for A and Vector for b and x, but found that it needed a TensorLayout/SparsityPatter to initialize the A before I can set the entries of A matrix, which is inconvenient.( Correct me if I were wrong! )

So I am turning to using uBLASDenseMatrix to store A and uBLASVector for b and x, in which I can declare the dense matrix as A(m,n). After assigning each entries of my matrix A and b, I would like to solve x. Here the problem comes.
I tried the following solvers:
UmfpackLUSolver
LUSolver
PETScLUSolver
...................
But none of the above solvers can give an answer. I tested that A and b have non-zero entries. However,uBLASKrylovSolver returns zeros solution, and the others just crashed down.
Can anyone give me some hints? what is the solution of my problem?

Thank you very much.
XZ

## Question information

Language:
English Edit question
Status:
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2013-04-08
2013-05-09
 Anders Logg (logg) said on 2013-04-09: #1

On Mon, Apr 08, 2013 at 08:41:21PM -0000, Xujun Zhao wrote:
> Question #226223 on DOLFIN changed:
>
> Description changed to:
> I am developing my own codes on top of dolfin. Now I meet a problem:
> I need to solve a linear equation: Ax = b, which is a small size equation.
> In the first place, I tried to use Matrix for A and Vector for b and x, but found that it needed a TensorLayout/SparsityPatter to initialize the A before I can set the entries of A matrix, which is inconvenient.( Correct me if I were wrong! )
>
> So I am turning to using uBLASDenseMatrix to store A and uBLASVector for b and x, in which I can declare the dense matrix as A(m,n). After assigning each entries of my matrix A and b, I would like to solve x. Here the problem comes.
> I tried the following solvers:
> UmfpackLUSolver
> LUSolver
> PETScLUSolver
> ...................
> But none of the above solvers can give an answer. I tested that A and b have non-zero entries. However,uBLASKrylovSolver returns zeros solution, and the others just crashed down.
> Can anyone give me some hints? what is the solution of my problem?
>
> Thank you very much.

If you want help, post a minimal code example and explain clearly what
the expected solution should be.

--
Anders

 Anders Logg (logg) said on 2013-05-09: #2

consult the documentation on the FEniCS web page for where and
how to (re)post your question: http://fenicsproject.org/support/

 Anders Logg (logg) said on 2013-05-09: #3