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