# KSPComputeEigenvalues
Computes the extreme eigenvalues for the preconditioned operator. Called after or during `KSPSolve()`. 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPComputeEigenvalues(KSP ksp, PetscInt n, PetscReal r[], PetscReal c[], PetscInt *neig)
```
Not Collective


## Input Parameters

- ***ksp -*** iterative context obtained from `KSPCreate()`
- ***n -*** size of arrays r and c. The number of eigenvalues computed (neig) will, in
general, be less than this.



## Output Parameters

- ***r -*** real part of computed eigenvalues, provided by user with a dimension of at least n
- ***c -*** complex part of computed eigenvalues, provided by user with a dimension of at least n
- ***neig -*** actual number of eigenvalues computed (will be less than or equal to n)



## Options Database Keys

- ***-ksp_view_eigenvalues -*** Prints eigenvalues to stdout



## Notes
The number of eigenvalues estimated depends on the size of the Krylov space
generated during the `KSPSolve()` ; for example, with
CG it corresponds to the number of CG iterations, for GMRES it is the number
of GMRES iterations SINCE the last restart. Any extra space in r[] and c[]
will be ignored.

`KSPComputeEigenvalues()` does not usually provide accurate estimates; it is
intended only for assistance in understanding the convergence of iterative
methods, not for eigenanalysis. For accurate computation of eigenvalues we recommend using
the excellent package SLEPc.

One must call `KSPSetComputeEigenvalues()` before calling `KSPSetUp()`
in order for this routine to work correctly.

Many users may just want to use the monitoring routine
`KSPMonitorSingularValue()` (which can be set with option -ksp_monitor_singular_value)
to print the singular values at each iteration of the linear solve.

`KSPComputeRitz()` provides estimates for both the eigenvalues and their corresponding eigenvectors.




## See Also
 [](chapter_ksp), `KSPSetComputeEigenvalues()`, `KSPSetComputeSingularValues()`, `KSPMonitorSingularValue()`, `KSPComputeExtremeSingularValues()`, `KSP`, `KSPComputeRitz()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPComputeEigenvalues">src/ksp/ksp/interface/itfunc.c</A>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/cgeig.c.html#KSPComputeEigenvalues_CG">KSPComputeEigenvalues_CG in src/ksp/ksp/impls/cg/cgeig.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/fetidp/fetidp.c.html#KSPComputeEigenvalues_FETIDP">KSPComputeEigenvalues_FETIDP in src/ksp/ksp/impls/fetidp/fetidp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/gmreig.c.html#KSPComputeEigenvalues_GMRES">KSPComputeEigenvalues_GMRES in src/ksp/ksp/impls/gmres/gmreig.c</A><BR>


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


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