LU decomposition: Difference between revisions
Content added Content deleted
(→{{header|Go}}: add gonum/matrix version) |
(→Library gonum/matrix: update for library change, also improve output formatting a bit.) |
||
Line 1,233: | Line 1,233: | ||
1, 1, 0, |
1, 1, 0, |
||
})) |
})) |
||
fmt.Println() |
|||
showLU(mat64.NewDense(4, 4, []float64{ |
showLU(mat64.NewDense(4, 4, []float64{ |
||
11, 9, 24, 2, |
11, 9, 24, 2, |
||
Line 1,241: | Line 1,242: | ||
} |
} |
||
func showLU( |
func showLU(a *mat64.Dense) { |
||
fmt.Printf(" |
fmt.Printf("a: %v\n\n", mat64.Formatted(a, mat64.Prefix(" "))) |
||
var lu mat64.LU |
|||
lu.Factorize(a) |
|||
⚫ | |||
var l, u mat64.TriDense |
|||
⚫ | |||
l.LFrom(&lu) |
|||
u.UFrom(&lu) |
|||
} |
|||
⚫ | |||
⚫ | |||
type M struct{ mat64.Matrix } |
|||
fmt.Println("p:", lu.Pivot(nil)) |
|||
}</lang> |
|||
func (m M) Format(f fmt.State, c rune) { mat64.Format(m, 0, 0, f, c) }</lang> |
|||
{{out}} |
{{out}} |
||
Pivot format is a little different here. |
Pivot format is a little different here. (But library solutions don't really meet task requirements anyway.) |
||
<pre> |
<pre> |
||
⚫ | |||
m: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
l: |
|||
⎢ 0.50000 1.00000 0.00000⎥ |
|||
⎣ 0.50000 -1.00000 1.00000⎦ |
|||
⎣ 0.50000 -1.00000 1.00000⎦ |
|||
u: ⎡ 2.00000 4.00000 7.00000⎤ |
|||
u: |
|||
⎢ 0.00000 1.00000 1.50000⎥ |
|||
⎣ 0.00000 0.00000 -2.00000⎦ |
|||
⚫ | |||
p: [1 0 2] |
p: [1 0 2] |
||
m: |
|||
⎡11 9 24 2⎤ |
a: ⎡11 9 24 2⎤ |
||
⎢ 1 5 2 6⎥ |
⎢ 1 5 2 6⎥ |
||
⎢ 3 17 18 1⎥ |
⎢ 3 17 18 1⎥ |
||
⎣ 2 5 7 1⎦ |
⎣ 2 5 7 1⎦ |
||
l: |
|||
⎡1.00000 0.00000 0.00000 0.00000⎤ |
l: ⎡1.00000 0.00000 0.00000 0.00000⎤ |
||
⎢0.27273 1.00000 0.00000 0.00000⎥ |
⎢0.27273 1.00000 0.00000 0.00000⎥ |
||
⎢0.09091 0.28750 1.00000 0.00000⎥ |
⎢0.09091 0.28750 1.00000 0.00000⎥ |
||
⎣0.18182 0.23125 0.00360 1.00000⎦ |
⎣0.18182 0.23125 0.00360 1.00000⎦ |
||
u: |
|||
⎡11.00000 9.00000 24.00000 2.00000⎤ |
u: ⎡11.00000 9.00000 24.00000 2.00000⎤ |
||
⎢ 0.00000 14.54545 11.45455 0.45455⎥ |
⎢ 0.00000 14.54545 11.45455 0.45455⎥ |
||
⎢ 0.00000 0.00000 -3.47500 5.68750⎥ |
⎢ 0.00000 0.00000 -3.47500 5.68750⎥ |
||
⎣ 0.00000 0.00000 0.00000 0.51079⎦ |
⎣ 0.00000 0.00000 0.00000 0.51079⎦ |
||
p: [0 2 1 3] |
p: [0 2 1 3] |
||
</pre> |
</pre> |