-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linalg
eig
: generalized eigenvalue problem (#909)
- Loading branch information
Showing
7 changed files
with
480 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
! Eigendecomposition of a real square matrix for the generalized eigenproblem | ||
program example_eig_generalized | ||
use stdlib_linalg, only: eig, eye | ||
implicit none | ||
|
||
integer :: i | ||
real, allocatable :: A(:,:), B(:,:) | ||
complex, allocatable :: lambda(:), vectors(:,:) | ||
|
||
! Matrices for the generalized eigenproblem: A * v = lambda * B * v | ||
! NB Fortran is column-major -> transpose input | ||
A = transpose(reshape([ [2, 2, 4], & | ||
[1, 3, 5], & | ||
[2, 3, 4] ], [3,3])) | ||
|
||
B = eye(3) | ||
|
||
! Allocate eigenvalues and right eigenvectors | ||
allocate(lambda(3), vectors(3,3)) | ||
|
||
! Get eigenvalues and right eigenvectors for the generalized problem | ||
call eig(A, B, lambda, right=vectors) | ||
|
||
do i = 1, 3 | ||
print *, 'Eigenvalue ', i, ': ', lambda(i) | ||
print *, 'Eigenvector ', i, ': ', vectors(:,i) | ||
end do | ||
|
||
end program example_eig_generalized | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
! Eigenvalues of a general real/complex matrix for the generalized eigenproblem | ||
program example_eigvals_generalized | ||
use stdlib_linalg, only: eigvals, eye | ||
implicit none | ||
|
||
real, allocatable :: A(:,:), B(:,:), lambda(:) | ||
complex, allocatable :: cA(:,:), cB(:,:), clambda(:) | ||
|
||
! NB Fortran is column-major -> transpose input | ||
A = transpose(reshape([ [2, 8, 4], & | ||
[1, 3, 5], & | ||
[9, 5,-2] ], [3,3])) | ||
|
||
B = eye(3) | ||
|
||
! Real generalized eigenproblem | ||
lambda = eigvals(A, B) | ||
print *, 'Real generalized matrix eigenvalues: ', lambda | ||
|
||
! Complex generalized eigenproblem | ||
cA = cmplx(A, -2*A) | ||
cB = cmplx(B, 0.5*B) | ||
clambda = eigvals(cA, cB) | ||
print *, 'Complex generalized matrix eigenvalues: ', clambda | ||
|
||
end program example_eigvals_generalized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.