⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (682 Bytes)
Feature #1047
» bm_hilbert_matrix.rb
rogerdpack (Roger Pack)
, 03/20/2010 01:45 AM
# Submitted by M. Edward (Ed) Borasky
require
'mathn'
# also brings in matrix, rational and complex
# return a Hilbert matrix of given dimension
def
hilbert
(
dimension
)
rows
=
Array
.
new
(
1
..
dimension
).
each
do
|
i
|
row
=
Array
.
new
(
1
..
dimension
).
each
do
|
j
|
row
.
push
(
1
/
(
i
+
j
-
1
))
end
rows
.
push
(
row
)
end
return
(
Matrix
.
rows
(
rows
))
end
def
run_hilbert
(
dimension
)
m
=
hilbert
(
dimension
)
print
"Hilbert matrix of dimension
#{
dimension
}
times its inverse = identity? "
k
=
m
*
m
.
inv
print
"
#{
k
==
Matrix
.
I
(
dimension
)
}
\n
"
m
=
nil
# for the garbage collector
k
=
nil
end
a
=
[]
50_000_000
.
times
{
a
<<
1
}
[
10
,
20
].
each
do
|
n
|
run_hilbert
(
n
)
end
« Previous
1
2
3
4
5
Next »
(2-2/5)
Loading...