Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,47 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Complex_Text_IO; use Ada.Complex_Text_IO;
|
||||
with Ada.Numerics.Complex_Types; use Ada.Numerics.Complex_Types;
|
||||
with Ada.Numerics.Complex_Arrays; use Ada.Numerics.Complex_Arrays;
|
||||
procedure ConTrans is
|
||||
subtype CM is Complex_Matrix;
|
||||
S2O2 : constant Float := 0.7071067811865;
|
||||
|
||||
procedure Print (mat : CM) is begin
|
||||
for row in mat'Range(1) loop for col in mat'Range(2) loop
|
||||
Put(mat(row,col), Exp=>0, Aft=>4);
|
||||
end loop; New_Line; end loop;
|
||||
end Print;
|
||||
|
||||
function almostzero(mat : CM; tol : Float) return Boolean is begin
|
||||
for row in mat'Range(1) loop for col in mat'Range(2) loop
|
||||
if abs(mat(row,col)) > tol then return False; end if;
|
||||
end loop; end loop;
|
||||
return True;
|
||||
end almostzero;
|
||||
|
||||
procedure Examine (mat : CM) is
|
||||
CT : CM := Conjugate (Transpose(mat));
|
||||
isherm, isnorm, isunit : Boolean;
|
||||
begin
|
||||
isherm := almostzero(mat-CT, 1.0e-6);
|
||||
isnorm := almostzero(mat*CT-CT*mat, 1.0e-6);
|
||||
isunit := almostzero(CT-Inverse(mat), 1.0e-6);
|
||||
Print(mat);
|
||||
Put_Line("Conjugate transpose:"); Print(CT);
|
||||
Put_Line("Hermitian?: " & isherm'Img);
|
||||
Put_Line("Normal?: " & isnorm'Img);
|
||||
Put_Line("Unitary?: " & isunit'Img);
|
||||
end Examine;
|
||||
|
||||
hmat : CM := ((3.0+0.0*i, 2.0+1.0*i), (2.0-1.0*i, 1.0+0.0*i));
|
||||
nmat : CM := ((1.0+0.0*i, 1.0+0.0*i, 0.0+0.0*i),
|
||||
(0.0+0.0*i, 1.0+0.0*i, 1.0+0.0*i),
|
||||
(1.0+0.0*i, 0.0+0.0*i, 1.0+0.0*i));
|
||||
umat : CM := ((S2O2+0.0*i, S2O2+0.0*i, 0.0+0.0*i),
|
||||
(0.0+S2O2*i, 0.0-S2O2*i, 0.0+0.0*i),
|
||||
(0.0+0.0*i, 0.0+0.0*i, 0.0+1.0*i));
|
||||
begin
|
||||
Put_Line("hmat:"); Examine(hmat); New_Line;
|
||||
Put_Line("nmat:"); Examine(nmat); New_Line;
|
||||
Put_Line("umat:"); Examine(umat);
|
||||
end ConTrans;
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
function conjugate-transpose($a) {
|
||||
$arr = @()
|
||||
if($a) {
|
||||
$n = $a.count - 1
|
||||
if(0 -lt $n) {
|
||||
$m = ($a | foreach {$_.count} | measure-object -Minimum).Minimum - 1
|
||||
if( 0 -le $m) {
|
||||
if (0 -lt $m) {
|
||||
$arr =@(0)*($m+1)
|
||||
foreach($i in 0..$m) {
|
||||
$arr[$i] = foreach($j in 0..$n) {@([System.Numerics.complex]::Conjugate($a[$j][$i]))}
|
||||
}
|
||||
} else {$arr = foreach($row in $a) {[System.Numerics.complex]::Conjugate($row[0])}}
|
||||
}
|
||||
} else {$arr = foreach($row in $a) {[System.Numerics.complex]::Conjugate($row[0])}}
|
||||
}
|
||||
$arr
|
||||
}
|
||||
|
||||
function multarrays-complex($a, $b) {
|
||||
$c = @()
|
||||
if($a -and $b) {
|
||||
$n = $a.count - 1
|
||||
$m = $b[0].count - 1
|
||||
$c = @([System.Numerics.complex]::new(0,0))*($n+1)
|
||||
foreach ($i in 0..$n) {
|
||||
$c[$i] = foreach ($j in 0..$m) {
|
||||
[System.Numerics.complex]$sum = [System.Numerics.complex]::new(0,0)
|
||||
foreach ($k in 0..$n){$sum = [System.Numerics.complex]::Add($sum, ([System.Numerics.complex]::Multiply($a[$i][$k],$b[$k][$j])))}
|
||||
$sum
|
||||
}
|
||||
}
|
||||
}
|
||||
$c
|
||||
}
|
||||
|
||||
function identity-complex($n) {
|
||||
if(0 -lt $n) {
|
||||
$array = @(0) * $n
|
||||
foreach ($i in 0..($n-1)) {
|
||||
$array[$i] = @([System.Numerics.complex]::new(0,0)) * $n
|
||||
$array[$i][$i] = [System.Numerics.complex]::new(1,0)
|
||||
}
|
||||
$array
|
||||
} else { @() }
|
||||
}
|
||||
|
||||
function are-eq ($a,$b) { -not (Compare-Object $a $b -SyncWindow 0)}
|
||||
|
||||
function show($a) {
|
||||
if($a) {
|
||||
0..($a.Count - 1) | foreach{ if($a[$_]){"$($a[$_])"}else{""} }
|
||||
}
|
||||
}
|
||||
function complex($a,$b) {[System.Numerics.complex]::new($a,$b)}
|
||||
|
||||
$id2 = identity-complex 2
|
||||
$m = @(@((complex 2 7), (complex 9 -5)),@((complex 3 4), (complex 8 -6)))
|
||||
$hm = conjugate-transpose $m
|
||||
$mhm = multarrays-complex $m $hm
|
||||
$hmm = multarrays-complex $hm $m
|
||||
"`$m ="
|
||||
show $m
|
||||
""
|
||||
"`$hm = conjugate-transpose `$m ="
|
||||
show $hm
|
||||
""
|
||||
"`$m * `$hm ="
|
||||
show $mhm
|
||||
""
|
||||
"`$hm * `$m ="
|
||||
show $hmm
|
||||
""
|
||||
"Hermitian? `$m = $(are-eq $m $hm)"
|
||||
"Normal? `$m = $(are-eq $mhm $hmm)"
|
||||
"Unitary? `$m = $((are-eq $id2 $hmm) -and (are-eq $id2 $mhm))"
|
||||
|
|
@ -1,69 +1,39 @@
|
|||
conjugate_transpose<- function(M){
|
||||
t(Conj(M))}
|
||||
conj_t <- function(mat) t(Conj(mat))
|
||||
|
||||
is_hermitian <- function(M,eps=10**-10){
|
||||
all(abs(M-conjugate_transpose(M))<eps)
|
||||
near_eq <- function(x, y, eps=10^-10) all(abs(x-y)<eps)
|
||||
|
||||
is_hermitian <- function(mat) near_eq(mat, conj_t(mat))
|
||||
|
||||
is_normal <- function(mat){
|
||||
mat_h <- conj_t(mat)
|
||||
near_eq(mat%*%mat_h, mat_h%*%mat)
|
||||
}
|
||||
|
||||
is_normal <-function(M,eps=10**-10){
|
||||
conjugate <- conjugate_transpose(M)
|
||||
all(abs(M%*%conjugate- conjugate%*%M)<eps)
|
||||
is_unitary <- function(mat){
|
||||
id <- diag(nrow(mat))
|
||||
near_eq(mat%*%conj_t(mat), id)
|
||||
}
|
||||
|
||||
is_unitary <-function(M,eps=10**-10){
|
||||
all(abs(M%*% conjugate_transpose(M)-diag(nrow(M)))<eps)
|
||||
mat1 <- matrix(c(3+0i, 2-1i, 2+1i, 1+0i), nrow=2)
|
||||
|
||||
mat2 <- matrix(complex(real=c(1, 0, 1, 1, 1, 0, 0, 1, 1),
|
||||
imaginary=0),
|
||||
nrow=3)
|
||||
|
||||
s <- sqrt(2)/2
|
||||
mat3 <- matrix(complex(real=c(s, 0, 0, s, rep(0, 5)),
|
||||
imaginary=c(0, -s, 0, 0, s, 0, 0, 0, 1)),
|
||||
nrow=3)
|
||||
|
||||
conj_tests <- function(mat){
|
||||
cat("\nChosen matrix:\n")
|
||||
print(mat)
|
||||
cat("\nConjugate transpose:\n")
|
||||
print(conj_t(mat))
|
||||
test_funs <- c(is_hermitian, is_normal, is_unitary)
|
||||
results <- sapply(test_funs, function(f) f(mat))
|
||||
queries <- c("Hermitian?", "Normal?", "Unitary?")
|
||||
writeLines(paste(queries, results))
|
||||
}
|
||||
|
||||
M1 = matrix(c(3+0i,2-1i,
|
||||
2+1i,1+0i),nrow=2)
|
||||
cat("M1")
|
||||
cat("\n")
|
||||
print(M1)
|
||||
cat("\n")
|
||||
Conj_M1 = conjugate_transpose(M1)
|
||||
cat("Conjugate transpose of M1")
|
||||
cat("\n")
|
||||
print(Conj_M1)
|
||||
cat(paste0("Hermitian ? ", is_hermitian(M1)))
|
||||
cat("\n")
|
||||
cat(paste0("Normal ? ", is_normal(M1)))
|
||||
cat("\n")
|
||||
cat(paste0("Unitary ? ", is_unitary(M1)))
|
||||
|
||||
|
||||
M2 = matrix(c(1+0i,0+0i,1+0i,
|
||||
1+0i,1+0i,0+0i,
|
||||
0+0i,1+0i,1+0i),nrow=3)
|
||||
cat("\n")
|
||||
cat("M2")
|
||||
cat("\n")
|
||||
print(M2)
|
||||
cat("\n")
|
||||
Conj_M2 = conjugate_transpose(M2)
|
||||
cat("Conjugate transpose of M2")
|
||||
cat("\n")
|
||||
print(Conj_M2)
|
||||
cat(paste0("Hermitian ? ", is_hermitian(M2)))
|
||||
cat("\n")
|
||||
cat(paste0("Normal ? ", is_normal(M2)))
|
||||
cat("\n")
|
||||
cat(paste0("Unitary ? ", is_unitary(M2)))
|
||||
|
||||
|
||||
M3 = matrix(c(sqrt(2)/2+0i,0-(sqrt(2)/2)*1i,0+0i,
|
||||
sqrt(2)/2+0i,0+(sqrt(2)/2)*1i,0+0i,
|
||||
0+0i,0+0i,0+1i),ncol=3)
|
||||
cat("\n")
|
||||
cat("M3")
|
||||
cat("\n")
|
||||
print(M3)
|
||||
cat("\n")
|
||||
Conj_M3 = conjugate_transpose(M3)
|
||||
cat("Conjugate transpose of M3")
|
||||
cat("\n")
|
||||
print(Conj_M3)
|
||||
cat(paste0("Hermitian ? ", is_hermitian(M3)))
|
||||
cat("\n")
|
||||
cat(paste0("Normal ? ", is_normal(M3)))
|
||||
cat("\n")
|
||||
cat(paste0("Unitary ? ", is_unitary(M3)))
|
||||
sapply(list(mat1, mat2, mat3), conj_tests) |> invisible()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue