September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
44
Task/Matrix-arithmetic/Go/matrix-arithmetic-2.go
Normal file
44
Task/Matrix-arithmetic/Go/matrix-arithmetic-2.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(ryser([][]float64{
|
||||
{1, 2},
|
||||
{3, 4}}))
|
||||
fmt.Println(ryser([][]float64{
|
||||
{2, 9, 4},
|
||||
{7, 5, 3},
|
||||
{6, 1, 8}}))
|
||||
}
|
||||
|
||||
func ryser(m [][]float64) (d float64) {
|
||||
gray := 0
|
||||
csum := make([]float64, len(m))
|
||||
sgn := float64(len(m)&1<<1 - 1)
|
||||
n2 := uint32(1) << uint(len(m))
|
||||
for i := uint32(1); i < n2; i++ {
|
||||
r := [...]byte{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
||||
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9,
|
||||
}[i&-i*0x077CB531>>27]
|
||||
b := 1 << r
|
||||
if gray&b == 0 {
|
||||
for c, e := range m[r] {
|
||||
csum[c] += e
|
||||
}
|
||||
} else {
|
||||
for c, e := range m[r] {
|
||||
csum[c] -= e
|
||||
}
|
||||
}
|
||||
gray ^= b
|
||||
p := sgn
|
||||
for _, e := range csum {
|
||||
p *= e
|
||||
}
|
||||
d += p
|
||||
sgn = -sgn
|
||||
}
|
||||
return
|
||||
}
|
||||
17
Task/Matrix-arithmetic/Go/matrix-arithmetic-3.go
Normal file
17
Task/Matrix-arithmetic/Go/matrix-arithmetic-3.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/skelterjohn/go.matrix"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(matrix.MakeDenseMatrixStacked([][]float64{
|
||||
{1, 2},
|
||||
{3, 4}}).Det())
|
||||
fmt.Println(matrix.MakeDenseMatrixStacked([][]float64{
|
||||
{2, 9, 4},
|
||||
{7, 5, 3},
|
||||
{6, 1, 8}}).Det())
|
||||
}
|
||||
17
Task/Matrix-arithmetic/Go/matrix-arithmetic-4.go
Normal file
17
Task/Matrix-arithmetic/Go/matrix-arithmetic-4.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gonum/matrix/mat64"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat64.Det(mat64.NewDense(2, 2, []float64{
|
||||
1, 2,
|
||||
3, 4})))
|
||||
fmt.Println(mat64.Det(mat64.NewDense(3, 3, []float64{
|
||||
2, 9, 4,
|
||||
7, 5, 3,
|
||||
6, 1, 8})))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue