-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
834 additions
and
5 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,22 @@ | ||
! Matrix inversion example: function interface | ||
program example_inverse_function | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: inv,eye | ||
implicit none | ||
|
||
real(dp) :: A(2,2), Am1(2,2) | ||
|
||
! Input matrix (NB Fortran is column major! input columns then transpose) | ||
A = transpose(reshape( [4, 3, & | ||
3, 2], [2,2] )) | ||
|
||
! Invert matrix | ||
Am1 = inv(A) | ||
|
||
print *, ' |',Am1(1,:),'|' ! | -2 3 | | ||
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | | ||
|
||
! Final check | ||
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) | ||
|
||
end program example_inverse_function |
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,23 @@ | ||
! Matrix inversion example: in-place inversion | ||
program example_inverse_inplace | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: invert,eye | ||
implicit none | ||
|
||
real(dp) :: A(2,2), Am1(2,2) | ||
|
||
! Input matrix (NB Fortran is column major! input columns then transpose) | ||
A = transpose(reshape( [4, 3, & | ||
3, 2], [2,2] )) | ||
Am1 = A | ||
|
||
! Invert matrix | ||
call invert(Am1) | ||
|
||
print *, ' |',Am1(1,:),'|' ! | -2 3 | | ||
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | | ||
|
||
! Final check | ||
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) | ||
|
||
end program example_inverse_inplace |
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,22 @@ | ||
! Matrix inversion example: operator interface | ||
program example_inverse_operator | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: operator(.inv.),eye | ||
implicit none | ||
|
||
real(dp) :: A(2,2), Am1(2,2) | ||
|
||
! Input matrix (NB Fortran is column major! input columns then transpose) | ||
A = transpose(reshape( [4, 3, & | ||
3, 2], [2,2] )) | ||
|
||
! Invert matrix | ||
Am1 = .inv.A | ||
|
||
print *, ' |',Am1(1,:),'|' ! | -2 3 | | ||
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | | ||
|
||
! Final check | ||
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) | ||
|
||
end program example_inverse_operator |
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,22 @@ | ||
! Matrix inversion example: subroutine interface | ||
program example_inverse_subroutine | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: invert,eye | ||
implicit none | ||
|
||
real(dp) :: A(2,2), Am1(2,2) | ||
|
||
! Input matrix (NB Fortran is column major! input columns then transpose) | ||
A = transpose(reshape( [4, 3, & | ||
3, 2], [2,2] )) | ||
|
||
! Invert matrix | ||
call invert(A,Am1) | ||
|
||
print *, ' |',Am1(1,:),'|' ! | -2 3 | | ||
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 | | ||
|
||
! Final check | ||
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2) | ||
|
||
end program example_inverse_subroutine |
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.