:orphan:
# MatProductCreateWithMat
Set a given matrix to have its values computed via matrix-matrix operations on other matrices. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatProductCreateWithMat(Mat A, Mat B, Mat C, Mat D)
```
Collective


## Input Parameters

- ***A -*** the first matrix
- ***B -*** the second matrix
- ***C -*** the third matrix (optional, use `NULL` if not needed)
- ***D -*** the matrix whose values are to be computed via a matrix-matrix product operation





## Notes
Use `MatProductCreate()` if the matrix you wish computed (the `D` matrix) does not already exist

See `MatProductCreate()` for details on the usage of the matrix-matrix product operations

Any product data currently attached to `D` will be cleared


## See Also
 [](ch_matrices), `MatProduct`, `Mat`, `MatProductType`, `MatProductSetType()`, `MatProductAlgorithm`,
`MatProductSetAlgorithm`, `MatProductCreate()`, `MatProductClear()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matproduct.c.html#MatProductCreateWithMat">src/mat/interface/matproduct.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/interface/matproduct.c)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
