# MatProductCreateWithMat
Setup a given matrix as a matrix product of other matrices 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatProductCreateWithMat(Mat A, Mat B, Mat C, Mat D)
```
Collective on Mat


## Input Parameters

- ***A -*** the first matrix
- ***B -*** the second matrix
- ***C -*** the third matrix (optional, use `NULL` if not needed)
- ***D -*** the matrix which will be used to hold the product





## 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 MatProduct routines

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


## See Also
 `Mat`, `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](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
