Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
func cholesky(matrix) {
|
||||
var chol = matrix.len.of { matrix.len.of(0) }
|
||||
for row in ^matrix {
|
||||
for col in (0..row) {
|
||||
var x = matrix[row][col]
|
||||
for i in (0..col) {
|
||||
x -= (chol[row][i] * chol[col][i])
|
||||
}
|
||||
chol[row][col] = (row == col ? x.sqrt : x/chol[col][col])
|
||||
}
|
||||
}
|
||||
return chol
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
var example1 = [ [ 25, 15, -5 ],
|
||||
[ 15, 18, 0 ],
|
||||
[ -5, 0, 11 ] ];
|
||||
|
||||
say "Example 1:";
|
||||
cholesky(example1).each { |row|
|
||||
say row.map {'%7.4f' % _}.join(' ');
|
||||
}
|
||||
|
||||
var example2 = [ [ 18, 22, 54, 42],
|
||||
[ 22, 70, 86, 62],
|
||||
[ 54, 86, 174, 134],
|
||||
[ 42, 62, 134, 106] ];
|
||||
|
||||
say "\nExample 2:";
|
||||
cholesky(example2).each { |row|
|
||||
say row.map {'%7.4f' % _}.join(' ');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue