t50_matriz_dispersa_densa 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Documentacion/Fraccion.html +816 -0
- data/Documentacion/Gemfile.html +109 -0
- data/Documentacion/LICENSE_txt.html +126 -0
- data/Documentacion/Matriz.html +405 -0
- data/Documentacion/Matriz_Dispersa.html +159 -0
- data/Documentacion/Matriz_densa.html +479 -0
- data/Documentacion/Object.html +212 -0
- data/Documentacion/Rakefile.html +114 -0
- data/Documentacion/SparseMatrix.html +775 -0
- data/Documentacion/SparseVector.html +307 -0
- data/Documentacion/T50MatrizDispersaDensa.html +167 -0
- data/Documentacion/TestMatrix.html +467 -0
- data/Documentacion/bin/t50_matriz_dispersa_densa.html +54 -0
- data/Documentacion/created.rid +13 -0
- data/Documentacion/images/brick.png +0 -0
- data/Documentacion/images/brick_link.png +0 -0
- data/Documentacion/images/bug.png +0 -0
- data/Documentacion/images/bullet_black.png +0 -0
- data/Documentacion/images/bullet_toggle_minus.png +0 -0
- data/Documentacion/images/bullet_toggle_plus.png +0 -0
- data/Documentacion/images/date.png +0 -0
- data/Documentacion/images/find.png +0 -0
- data/Documentacion/images/loadingAnimation.gif +0 -0
- data/Documentacion/images/macFFBgHack.png +0 -0
- data/Documentacion/images/package.png +0 -0
- data/Documentacion/images/page_green.png +0 -0
- data/Documentacion/images/page_white_text.png +0 -0
- data/Documentacion/images/page_white_width.png +0 -0
- data/Documentacion/images/plugin.png +0 -0
- data/Documentacion/images/ruby.png +0 -0
- data/Documentacion/images/tag_green.png +0 -0
- data/Documentacion/images/wrench.png +0 -0
- data/Documentacion/images/wrench_orange.png +0 -0
- data/Documentacion/images/zoom.png +0 -0
- data/Documentacion/index.html +172 -0
- data/Documentacion/js/darkfish.js +118 -0
- data/Documentacion/js/jquery.js +32 -0
- data/Documentacion/js/quicksearch.js +114 -0
- data/Documentacion/js/thickbox-compressed.js +10 -0
- data/Documentacion/lib/Fraccion_rb.html +54 -0
- data/Documentacion/lib/gcd_rb.html +52 -0
- data/Documentacion/lib/matriz_densa_rb.html +54 -0
- data/Documentacion/lib/matriz_dispersa_rb.html +58 -0
- data/Documentacion/lib/matriz_rb.html +58 -0
- data/Documentacion/lib/t50_matriz_dispersa_densa/version_rb.html +52 -0
- data/Documentacion/lib/t50_matriz_dispersa_densa_rb.html +72 -0
- data/Documentacion/rdoc.css +763 -0
- data/Documentacion/test/tc_matrix_rb.html +62 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +10 -0
- data/bin/t50_matriz_dispersa_densa +3 -0
- data/lib/Fraccion.rb +128 -0
- data/lib/gcd.rb +7 -0
- data/lib/matriz.rb +71 -0
- data/lib/matriz.rb~ +136 -0
- data/lib/matriz_densa.rb +128 -0
- data/lib/matriz_densa.rb~ +148 -0
- data/lib/matriz_dispersa.rb +276 -0
- data/lib/matriz_dispersa.rb~ +275 -0
- data/lib/t50_matriz_dispersa_densa.rb +27 -0
- data/lib/t50_matriz_dispersa_densa.rb~ +7 -0
- data/lib/t50_matriz_dispersa_densa/version.rb +3 -0
- data/t50_matriz_dispersa_densa.gemspec +19 -0
- data/test/tc_matrix.rb +57 -0
- data/test/tc_matrix.rb~ +57 -0
- metadata +115 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
+
<head>
|
7
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
8
|
+
|
9
|
+
<title>File: tc_matrix.rb [RDoc Documentation]</title>
|
10
|
+
|
11
|
+
<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet" />
|
12
|
+
|
13
|
+
<script src="../js/jquery.js" type="text/javascript"
|
14
|
+
charset="utf-8"></script>
|
15
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript"
|
16
|
+
charset="utf-8"></script>
|
17
|
+
<script src="../js/quicksearch.js" type="text/javascript"
|
18
|
+
charset="utf-8"></script>
|
19
|
+
<script src="../js/darkfish.js" type="text/javascript"
|
20
|
+
charset="utf-8"></script>
|
21
|
+
</head>
|
22
|
+
|
23
|
+
<body class="file file-popup">
|
24
|
+
<div id="metadata">
|
25
|
+
<dl>
|
26
|
+
<dt class="modified-date">Last Modified</dt>
|
27
|
+
<dd class="modified-date">2013-11-26 13:04:40 +0000</dd>
|
28
|
+
|
29
|
+
|
30
|
+
<dt class="requires">Requires</dt>
|
31
|
+
<dd class="requires">
|
32
|
+
<ul>
|
33
|
+
|
34
|
+
<li>Fraccion.rb</li>
|
35
|
+
|
36
|
+
<li>gcd.rb</li>
|
37
|
+
|
38
|
+
<li>matriz_dispersa.rb</li>
|
39
|
+
|
40
|
+
<li>matriz_densa.rb</li>
|
41
|
+
|
42
|
+
<li>test/unit</li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</dd>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
</dl>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
<div id="documentation">
|
53
|
+
|
54
|
+
<div class="description">
|
55
|
+
<h2>Description</h2>
|
56
|
+
|
57
|
+
</div>
|
58
|
+
|
59
|
+
</div>
|
60
|
+
</body>
|
61
|
+
</html>
|
62
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Javier C
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# T50MatrizDispersaDensa
|
2
|
+
|
3
|
+
## Descripción
|
4
|
+
|
5
|
+
Esta es una práctica para la Universidad de La Laguna, realizada por los alumnos Javier Clemente Rodriguez Gómez y Juan Lucas González Hidalgo para la asignatura Lenguajes y Paradigma de la Programación en el curso 2013/2014.
|
6
|
+
|
7
|
+
Gema que contempla la creación de Matrices. Utiliza una representación para matrices densas y otra diferente para matrices dispersas. Se establece una relación de herencia entre las clases que se utilizan para su representación. Se implementan las operaciones básicas, que difieren según el tipo de matriz.
|
8
|
+
|
9
|
+
En la nueva práctica se pide implementar dos métodos max y min que devuelvan el valor máximo y el minimo respectivamente de una matriz.
|
10
|
+
|
11
|
+
|
12
|
+
## Diseño
|
13
|
+
|
14
|
+
El árbol de directorios queda establecido de la siguiente manera:
|
15
|
+
|
16
|
+
├── bin
|
17
|
+
│ └── t50_matriz_dispersa_densa
|
18
|
+
├── lib
|
19
|
+
│ ├── Fraccion.rb
|
20
|
+
│ ├── gcd.rb
|
21
|
+
│ ├── matriz_densa.rb
|
22
|
+
│ ├── matriz_dispersa.rb
|
23
|
+
│ ├── matriz.rb
|
24
|
+
│ ├── matriz.rb~
|
25
|
+
│ ├── t50_matriz_dispersa_densa
|
26
|
+
│ │ └── version.rb
|
27
|
+
│ └── t50_matriz_dispersa_densa.rb
|
28
|
+
├── LICENSE.txt
|
29
|
+
├── Rakefile
|
30
|
+
├── README.md
|
31
|
+
├── t50_matriz_dispersa_densa.gemspec
|
32
|
+
└── test
|
33
|
+
└── tc_matrix.rb
|
34
|
+
|
35
|
+
|
36
|
+
El programa esta en la ruta /lib/t50_matriz_dispersa_densa.rb
|
37
|
+
En version.rb se establece la versión de la gema.
|
38
|
+
Y el ejecutable esta en la ruta /bin/t50_matriz_dispersa_densa
|
39
|
+
|
40
|
+
En el fichero t50_matriz_dispersa_densa.rb se escribira el código que vamos a utilizar dentro de un modulo para la gema. Para llevar a cabo esto se utilizara la herencia de clases en la clase matriz de la práctica anterior. Se crearan clases disperas y densas que heredan de una matriz simple que acepta enteros y fraccionales.
|
41
|
+
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
Add this line to your application's Gemfile:
|
46
|
+
|
47
|
+
gem 't50_matriz_dispersa_densa'
|
48
|
+
|
49
|
+
And then execute:
|
50
|
+
|
51
|
+
$ bundle
|
52
|
+
|
53
|
+
Or install it yourself as:
|
54
|
+
|
55
|
+
$ gem install t50_matriz_dispersa_densa
|
56
|
+
|
57
|
+
## Usage
|
58
|
+
|
59
|
+
Realiza un include de la gema para cargar la gema correctamente.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/Fraccion.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
|
2
|
+
require 'gcd.rb'
|
3
|
+
|
4
|
+
|
5
|
+
class Fraccion
|
6
|
+
include Comparable
|
7
|
+
|
8
|
+
attr_reader :n, :d
|
9
|
+
def initialize (n,d)
|
10
|
+
@n=n
|
11
|
+
@d=d
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
|
16
|
+
"#{@n}/#{@d}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def min
|
20
|
+
a=gcd(@n,@d)
|
21
|
+
|
22
|
+
@n = @n/a
|
23
|
+
@d = @d/a
|
24
|
+
|
25
|
+
if gcd(@n, @d) > 1
|
26
|
+
self.min
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def getn
|
31
|
+
return @n
|
32
|
+
end
|
33
|
+
|
34
|
+
def getd
|
35
|
+
return @d
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_f
|
39
|
+
#puts "Flotante: #{@n.to_f/@d.to_f}"
|
40
|
+
"#{@n.to_f/@d.to_f}"
|
41
|
+
#f4 = Fraccion.new(@n.to_f, @d.to_f)
|
42
|
+
#return f4
|
43
|
+
end
|
44
|
+
|
45
|
+
def abs
|
46
|
+
n = @n
|
47
|
+
d = @d
|
48
|
+
|
49
|
+
if @n < 0
|
50
|
+
n = -@n
|
51
|
+
end
|
52
|
+
|
53
|
+
if @d < 0
|
54
|
+
d = -@d
|
55
|
+
end
|
56
|
+
Fraccion.new(n, d)
|
57
|
+
end
|
58
|
+
|
59
|
+
def reciprocal
|
60
|
+
Fraccion.new(@d,@n)
|
61
|
+
end
|
62
|
+
|
63
|
+
def opuesto
|
64
|
+
Fraccion.new(-@n,@d)
|
65
|
+
end
|
66
|
+
def + (other)
|
67
|
+
if other.instance_of?Fixnum
|
68
|
+
n=(@n*1+(@d*other))
|
69
|
+
d=(@d*1)
|
70
|
+
|
71
|
+
else
|
72
|
+
n=(@n*other.d)+(@d*other.n)
|
73
|
+
d=(@d*other.d)
|
74
|
+
end
|
75
|
+
#"#{f4.n/f4.d}"
|
76
|
+
f4=Fraccion.new(n,d)
|
77
|
+
f4.min
|
78
|
+
return f4
|
79
|
+
end
|
80
|
+
|
81
|
+
def - (other)
|
82
|
+
if other.instance_of?Fixnum
|
83
|
+
n=(@n*1-(@d*other))
|
84
|
+
d=(@d*1)
|
85
|
+
|
86
|
+
else
|
87
|
+
n=(@n*other.d)-(@d*other.n)
|
88
|
+
d=(@d*other.d)
|
89
|
+
end
|
90
|
+
#"#{f4.n/f4.d}"
|
91
|
+
f4=Fraccion.new(n,d)
|
92
|
+
f4.min
|
93
|
+
return f4
|
94
|
+
end
|
95
|
+
|
96
|
+
def * (other)
|
97
|
+
if other.instance_of?Fixnum
|
98
|
+
other = Fraccion.new(other,1)
|
99
|
+
n=(@n *(other.n))
|
100
|
+
d=(@d*1)
|
101
|
+
|
102
|
+
else
|
103
|
+
n=(@n*other.n)
|
104
|
+
d=(@d*other.d)
|
105
|
+
|
106
|
+
end
|
107
|
+
f4=Fraccion.new(n,d)
|
108
|
+
f4.min
|
109
|
+
#"#{f4.n/f4.d}"
|
110
|
+
return f4
|
111
|
+
|
112
|
+
end
|
113
|
+
def / (other)
|
114
|
+
n=@n*other.d
|
115
|
+
d=@d*other.n
|
116
|
+
f4=Fraccion.new(n,d)
|
117
|
+
f4.min
|
118
|
+
"#{f4.n/f4.d}"
|
119
|
+
end
|
120
|
+
def <=>(other)
|
121
|
+
self.to_f<=>other.to_f
|
122
|
+
#self<=>other
|
123
|
+
end
|
124
|
+
|
125
|
+
def coerce(other)
|
126
|
+
return [self,other]
|
127
|
+
end
|
128
|
+
end
|
data/lib/gcd.rb
ADDED
data/lib/matriz.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
require 'matrix'
|
3
|
+
require 'Fraccion.rb'
|
4
|
+
require 'gcd'
|
5
|
+
|
6
|
+
class Matriz
|
7
|
+
attr_reader :m, :f, :c
|
8
|
+
|
9
|
+
def initialize(m)
|
10
|
+
@m=m
|
11
|
+
@f=m.size
|
12
|
+
@c=m[1].size
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(f,c,m)
|
16
|
+
|
17
|
+
@m=m
|
18
|
+
@f=c
|
19
|
+
@c=c
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def +(other)
|
25
|
+
suma = @m
|
26
|
+
for i in 0...@f do
|
27
|
+
for j in 0...@c do
|
28
|
+
suma[i][j]=@m[i][j]+other.m[i][j]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return suma
|
32
|
+
end
|
33
|
+
|
34
|
+
def *(other)
|
35
|
+
|
36
|
+
z = Array.new
|
37
|
+
|
38
|
+
|
39
|
+
for i in 0...@f do
|
40
|
+
z[i] = Array.new
|
41
|
+
for j in 0...@c do
|
42
|
+
z[i][j] = 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
for i in 0...@f do
|
47
|
+
for j in 0...@c do
|
48
|
+
for k in 0...@f do
|
49
|
+
z[i][j] += @m[i][k] * other.m[k][j]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return z
|
54
|
+
end
|
55
|
+
|
56
|
+
def -(other)
|
57
|
+
|
58
|
+
resta = @m
|
59
|
+
for i in 0...@f do
|
60
|
+
for j in 0...@c do
|
61
|
+
resta[i][j] = @m[i][j] - other.m[i][j]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return resta
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
data/lib/matriz.rb~
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
require 'Fraccion.rb'
|
3
|
+
|
4
|
+
class Matriz
|
5
|
+
|
6
|
+
attr_reader :m, :f, :c
|
7
|
+
|
8
|
+
def initialize(m)
|
9
|
+
@m=m
|
10
|
+
@f=m.size
|
11
|
+
@c=m[0].size
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(f,c,m)
|
15
|
+
@m = m
|
16
|
+
@f = f
|
17
|
+
@c = c
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def to_f
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def +(other)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def -(other)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def *(other)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def max(other)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def min(other)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
=begin
|
58
|
+
def +(other)
|
59
|
+
|
60
|
+
r =@m
|
61
|
+
|
62
|
+
for i in 0...@f do
|
63
|
+
for j in 0...@c do
|
64
|
+
r[i][j]=@m[i][j]+other.m[i][j]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return r
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def -(other)
|
72
|
+
rs =@m
|
73
|
+
|
74
|
+
for i in 0...@f do
|
75
|
+
for j in 0...@c do
|
76
|
+
rs[i][j]=@m[i][j]-other.m[i][j]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return rs
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def *(other)
|
84
|
+
z = Array.new
|
85
|
+
for i in 0...@f do
|
86
|
+
z[i] = Array.new
|
87
|
+
for j in 0...@c do
|
88
|
+
z[i][j] = 0
|
89
|
+
end
|
90
|
+
end
|
91
|
+
for i in 0...@f do
|
92
|
+
for j in 0...@c do
|
93
|
+
for k in 0...@f do
|
94
|
+
z[i][j] += @m[i][k] * other.m[k][j]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
return z
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def to_s
|
103
|
+
for i in 0...@f do
|
104
|
+
for j in 0...@c do
|
105
|
+
print @m[i][j]
|
106
|
+
end
|
107
|
+
puts
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
def /(other)
|
113
|
+
#rd=@m
|
114
|
+
##m=Matrix.build(other.f,other.c){|x| other.m}
|
115
|
+
##m.inverse
|
116
|
+
w = Array.new
|
117
|
+
for i in 0...@f do
|
118
|
+
w[i] = Array.new
|
119
|
+
for j in 0...@c do
|
120
|
+
w[i][j] = 0
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
for i in 0...@f do
|
125
|
+
for j in 0...@c do
|
126
|
+
for k in 0...@f - 1 do
|
127
|
+
w[i][j] += @m[i][k] * other.m[i][j]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
return w
|
132
|
+
end
|
133
|
+
=end
|
134
|
+
|
135
|
+
|
136
|
+
end
|