-
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.
Merge branch 'fortran-lang:master' into activations
- Loading branch information
Showing
12 changed files
with
867 additions
and
13 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 @@ | ||
! This example demonstrates the Schur decomposition for a complex-valued matrix. | ||
program example_schur_complex | ||
use stdlib_linalg, only: schur | ||
use stdlib_linalg_constants, only: dp | ||
implicit none | ||
|
||
integer, parameter :: n = 3 | ||
complex(dp), dimension(n,n) :: A, T, Z | ||
|
||
! Initialize a complex-valued square matrix | ||
A = reshape([ (1, 2), (3,-1), (4, 1), & | ||
(0,-1), (2, 0), (1,-2), & | ||
(2, 3), (1, 1), (0,-1) ], shape=[n,n]) | ||
|
||
! Compute the Schur decomposition: A = Z T Z^H | ||
call schur(A, T, Z) | ||
|
||
! Output results | ||
print *, "Original Matrix A:" | ||
print *, A | ||
print *, "Schur Form Matrix T:" | ||
print *, T | ||
print *, "Unitary Matrix Z:" | ||
print *, Z | ||
|
||
! Test factorization: Z*T*Z^H = A | ||
print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, conjg(transpose(Z)))) - A)) | ||
|
||
end program example_schur_complex | ||
|
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,32 @@ | ||
! This example includes eigenvalue computation in addition to | ||
! the Schur decomposition for a randomly generated matrix. | ||
program example_schur_eigenvalues | ||
use stdlib_linalg, only: schur | ||
use stdlib_linalg_constants, only: dp | ||
implicit none | ||
|
||
integer, parameter :: n = 5 | ||
real(dp), dimension(n,n) :: A, T, Z | ||
complex(dp), dimension(n) :: eigenvalues | ||
|
||
! Create a random real-valued square matrix | ||
call random_number(A) | ||
|
||
! Compute the Schur decomposition and eigenvalues | ||
call schur(A, T, Z, eigenvalues) | ||
|
||
! Output results | ||
print *, "Random Matrix A:" | ||
print *, A | ||
print *, "Schur Form Matrix T:" | ||
print *, T | ||
print *, "Orthogonal Matrix Z:" | ||
print *, Z | ||
print *, "Eigenvalues:" | ||
print *, eigenvalues | ||
|
||
! Test factorization: Z*T*Z^T = A | ||
print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, transpose(Z))) - A)) | ||
|
||
end program example_schur_eigenvalues | ||
|
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,29 @@ | ||
! This example computes the Schur decomposition of a real-valued square matrix. | ||
program example_schur_real | ||
use stdlib_linalg, only: schur | ||
use stdlib_linalg_constants, only: dp | ||
implicit none | ||
integer, parameter :: n = 3 | ||
real(dp), dimension(n,n) :: A, T, Z | ||
|
||
! Initialize a real-valued square matrix | ||
A = reshape([ 0, 2, 2, & | ||
0, 1, 2, & | ||
1, 0, 1], shape=[n,n]) | ||
|
||
! Compute the Schur decomposition: A = Z T Z^T | ||
call schur(A, T, Z) | ||
|
||
! Output results | ||
print *, "Original Matrix A:" | ||
print *, A | ||
print *, "Schur Form Matrix T:" | ||
print *, T | ||
print *, "Orthogonal Matrix Z:" | ||
print *, Z | ||
|
||
! Test factorization: Z*T*Z^T = A | ||
print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, transpose(Z))) - A)) | ||
|
||
end program example_schur_real | ||
|
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
Oops, something went wrong.