Jump to content

Cholesky decomposition: Difference between revisions

Added Wren
(Updated to work with version 1.4 of Nim. Improved output formatting. Added a generic type Matrix.)
(Added Wren)
Line 3,655:
End Function
</lang>
 
=={{header|Wren}}==
{{libheader|Wren-matrix}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/matrix" for Matrix
import "/fmt" for Fmt
 
var arrays = [
[ [25, 15, -5],
[15, 18, 0],
[-5, 0, 11] ],
 
[ [18, 22, 54, 42],
[22, 70, 86, 62],
[54, 86, 174, 134],
[42, 62, 134, 106] ]
]
 
for (array in arrays) {
System.print("Original:")
Fmt.mprint(array, 3, 0)
System.print("\nLower Cholesky factor:")
Fmt.mprint(Matrix.new(array).cholesky(), 8, 5)
System.print()
}</lang>
 
{{out}}
<pre>
Original:
| 25 15 -5|
| 15 18 0|
| -5 0 11|
 
Lower Cholesky factor:
| 5.00000 0.00000 0.00000|
| 3.00000 3.00000 0.00000|
|-1.00000 1.00000 3.00000|
 
Original:
| 18 22 54 42|
| 22 70 86 62|
| 54 86 174 134|
| 42 62 134 106|
 
Lower Cholesky factor:
| 4.24264 0.00000 0.00000 0.00000|
| 5.18545 6.56591 0.00000 0.00000|
|12.72792 3.04604 1.64974 0.00000|
| 9.89949 1.62455 1.84971 1.39262|
</pre>
 
=={{header|zkl}}==
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.