Class: Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/avsd.rb

Instance Method Summary collapse

Instance Method Details

#[]=(i, j, x) ⇒ Object


8
9
10
# File 'lib/avsd.rb', line 8

def []=(i, j, x)
@rows[i][j] = x
end

#flattenObject


64
65
66
67
68
69
70
71
72
# File 'lib/avsd.rb', line 64

def flatten
	arr = []
	for col in 0..self.column_size - 1
		for row in 0..self.row_size - 1
			arr << self[col, row]
		end
	end
	arr
end

#flipObject


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/avsd.rb', line 52

def flip
	m = self.flatten.max + 1
	for col in 0..self.column_size - 1
		for row in 0..self.row_size - 1
			next if self[col, row] == 0
			self[col, row] -= m
			self[col, row] *= -1
		end
	end
	self
end

#foldObject


12
13
14
15
16
17
18
19
20
21
# File 'lib/avsd.rb', line 12

def fold
	for col in 0..self.column_size - 1
		for row in col..self.row_size - 1
			sum = self[row, col] + self[col, row]
			self[row, col] = sum
			self[col, row] = sum
		end
	end
	self
end

#mirror_diagonalObject


35
36
37
38
39
40
41
42
43
# File 'lib/avsd.rb', line 35

def mirror_diagonal
	self.fold
	for col in 0..self.column_size - 1
		for row in 0..self.row_size - 1
			self[col, row] /= 2.0
		end
	end
	self
end

#showObject


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/avsd.rb', line 23

def show
	puts [self.column_size, self.row_size].inspect
	for col in 0..self.column_size - 1
		for row in 0..self.row_size - 1
			print self[row, col] == nil ? "n" : self[row, col]
			print "  "
		end
		puts
	end
	self
end

#zero_diagonalObject


45
46
47
48
49
50
# File 'lib/avsd.rb', line 45

def zero_diagonal
	for col in 0..self.column_size - 1
		self[col, col] = 0
	end
	self
end