Matrix operation

Hong Zhang hzhang at mcs.anl.gov
Mon Feb 20 16:52:01 CST 2006


Billy,

You can do
MatGetDiagonal(A,diag);
MatMult(A,u,&vtmp);
VecGetArray(diag,diag_array);
VecGetArray(vtmp,vtmp_array);
VecGetArray(u,u_arrar);
VecGetArray(h,h_array);
VecGetLocalSize(h,&n);
for (i=0; i<n; i++){
  h_array[i] += diag_array[i]*u_array[i] - vtmp_array[i];
}
VecRestoreArray(h,h_array);
VecRestoreArray()
...

or you can use VecPointwiseMult() got get
Diag(A)*u.

Hong

On Mon, 20 Feb 2006 billy at dem.uminho.pt wrote:

>
> Hello,
>
> I would like to do the following matrix-vector operation in PETSc:
>
> h += (Diag(A) - A) * u
>
> where A is a matrix, Diag(A) is a matrix and h, u are vectors. It is the
> multiplication of a matrix with diagonals set to zero with a vector.
>
>
> How can I do this in PETSc? because MatGetDiagonal gives a vector not a matrix.
>
>
> Billy.
>
>
>




More information about the petsc-users mailing list