:orphan: # MatSetValue Set a single entry into a matrix. This value may be cached, so `MatAssemblyBegin()` and `MatAssemblyEnd()` MUST be called after all calls to `MatSetValue()` have been completed. ## Synopsis ``` #include PetscErrorCode MatSetValue(Mat m,PetscInt i,PetscInt j,PetscScalar va,InsertMode mode) ``` Not Collective ## Input Parameters - ***m -*** the matrix - ***i -*** the row location of the entry - ***j -*** the column location of the entry - ***va -*** the value to insert - ***mode -*** either `INSERT_VALUES` or `ADD_VALUES` ## Note For efficiency one should use `MatSetValues()` and set several values simultaneously. ## See Also [](ch_matrices), `Mat`, `MatAssemblyBegin()`, `MatAssemblyEnd`, `InsertMode`, `MatGetValue()`, `MatSetValues()`, `MatSetValueLocal()`, `MatSetValuesLocal()` ## Level beginner ## Location include/petscmat.h ## Examples src/ksp/ksp/tutorials/ex21.c
src/ksp/ksp/tutorials/ex27.c
src/ksp/ksp/tutorials/ex4.c
src/ksp/ksp/tutorials/ex44f.F90
src/ksp/ksp/tutorials/ex59.c
src/ksp/ksp/tutorials/ex61f.F90
src/ksp/ksp/tutorials/ex73.c
src/ksp/ksp/tutorials/ex76.c
src/mat/tutorials/ex4.c
src/mat/tutorials/ex4f.F90
src/snes/tutorials/ex47cu.cu
--- [Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscmat.h) [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)