-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into matrix_inverse
- Loading branch information
Showing
18 changed files
with
1,066 additions
and
140 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
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,50 @@ | ||
! Singular Value Decomposition | ||
program example_svd | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: svd | ||
implicit none | ||
|
||
real(dp), allocatable :: A(:,:),s(:),u(:,:),vt(:,:) | ||
character(*), parameter :: fmt = "(a,*(1x,f12.8))" | ||
|
||
! We want to find the singular value decomposition of matrix: | ||
! | ||
! A = [ 3 2 2] | ||
! [ 2 3 -2] | ||
! | ||
A = transpose(reshape([ 3, 2, 2, & | ||
2, 3,-2], [3,2])) | ||
|
||
! Prepare arrays | ||
allocate(s(2),u(2,2),vt(3,3)) | ||
|
||
! Get singular value decomposition | ||
call svd(A,s,u,vt) | ||
|
||
! Singular values: [5, 3] | ||
print fmt, ' ' | ||
print fmt, 'S = ',s | ||
print fmt, ' ' | ||
|
||
! Left vectors (may be flipped): | ||
! [Ã2/2 Ã2/2] | ||
! U = [Ã2/2 -Ã2/2] | ||
! | ||
print fmt, ' ' | ||
print fmt, 'U = ',u(1,:) | ||
print fmt, ' ',u(2,:) | ||
|
||
|
||
! Right vectors (may be flipped): | ||
! [Ã2/2 Ã2/2 0] | ||
! V = [1/Ã18 -1/Ã18 4/Ã18] | ||
! [ 2/3 -2/3 -1/3] | ||
! | ||
print fmt, ' ' | ||
print fmt, ' ',vt(1,:) | ||
print fmt, 'VT= ',vt(2,:) | ||
print fmt, ' ',vt(3,:) | ||
print fmt, ' ' | ||
|
||
|
||
end program example_svd |
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 @@ | ||
! Singular Values | ||
program example_svdvals | ||
use stdlib_linalg_constants, only: dp | ||
use stdlib_linalg, only: svdvals | ||
implicit none | ||
|
||
real(dp), allocatable :: A(:,:),s(:) | ||
character(*), parameter :: fmt="(a,*(1x,f12.8))" | ||
|
||
! We want to find the singular values of matrix: | ||
! | ||
! A = [ 3 2 2] | ||
! [ 2 3 -2] | ||
! | ||
A = transpose(reshape([ 3, 2, 2, & | ||
2, 3,-2], [3,2])) | ||
|
||
! Get singular values | ||
s = svdvals(A) | ||
|
||
! Singular values: [5, 3] | ||
print fmt, ' ' | ||
print fmt, 'S = ',s | ||
print fmt, ' ' | ||
|
||
end program example_svdvals |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ADD_EXAMPLE(ord_sort) | ||
ADD_EXAMPLE(sort) | ||
ADD_EXAMPLE(sort_index) | ||
ADD_EXAMPLE(radix_sort) | ||
ADD_EXAMPLE(sort_bitset) | ||
ADD_EXAMPLE(sort_bitset) |
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,15 @@ | ||
program example_sort_index | ||
use stdlib_sorting, only: sort_index | ||
implicit none | ||
integer, allocatable :: array(:) | ||
integer, allocatable :: index(:) | ||
|
||
array = [5, 4, 3, 1, 10, 4, 9] | ||
allocate(index, mold=array) | ||
|
||
call sort_index(array, index) | ||
|
||
print *, array !print [1, 3, 4, 4, 5, 9, 10] | ||
print *, index !print [4, 3, 2, 6, 1, 7, 5] | ||
|
||
end program example_sort_index |
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.