Determinanten nebenlaeufig

master
Max 5 years ago
parent c8f5db7bb7
commit 0a3054877e

@ -27,30 +27,15 @@ func checkMat(mat [][]int) {
func getDet(mat [][]int) int { func getDet(mat [][]int) int {
if len(mat) > 1 { if len(mat) > 1 {
erg := 0 erg := 0
neg := 0 neg := false
var ch = make(chan int)
for i := 0; i < len(mat); i++ { for i := 0; i < len(mat); i++ {
mat1 := [][]int{} go singleDet(mat, neg, i, ch)
for j := 0; j < len(mat); j++ { neg = !neg
if j == i { }
continue for i := 0; i < len(mat); i++ {
} zw := <-ch
mat1 = append(mat1, []int{}) erg = erg + zw
for k := 1; k < len(mat[j]); k++ {
if j < i {
mat1[j] = append(mat1[j], mat[j][k])
} else {
mat1[j-1] = append(mat1[j-1], mat[j][k])
}
}
}
if neg == 0 {
erg = erg + mat[i][0]*getDet(mat1)
neg = 1
} else {
erg = erg - mat[i][0]*getDet(mat1)
neg = 0
}
} }
return erg return erg
} else { } else {
@ -59,6 +44,31 @@ func getDet(mat [][]int) int {
} }
func singleDet(mat [][]int, neg bool, i int, ch chan int) {
erg := 0
mat1 := [][]int{}
for j := 0; j < len(mat); j++ {
if j == i {
continue
}
mat1 = append(mat1, []int{})
for k := 1; k < len(mat[j]); k++ {
if j < i {
mat1[j] = append(mat1[j], mat[j][k])
} else {
mat1[j-1] = append(mat1[j-1], mat[j][k])
}
}
}
if !neg {
erg = erg + mat[i][0]*getDet(mat1)
} else {
erg = erg - mat[i][0]*getDet(mat1)
}
ch <- erg
}
func outMat(mat [][]int) { func outMat(mat [][]int) {
for i := 0; i < len(mat); i++ { for i := 0; i < len(mat); i++ {
for j := 0; j < len(mat[0]); j++ { for j := 0; j < len(mat[0]); j++ {

Loading…
Cancel
Save