Skip to content

Instantly share code, notes, and snippets.

@randsina
Created March 31, 2015 00:22
Show Gist options
  • Save randsina/ffe02f7a4ba9cb2aea6c to your computer and use it in GitHub Desktop.
Save randsina/ffe02f7a4ba9cb2aea6c to your computer and use it in GitHub Desktop.
lab for math analysis
require 'matrix'
matrix_A = [[3, 2, 1], [-2, 3, -2], [1, -4, 4]]
vector_B = [-1, 1, 6]
p matrix_A
p vector_B
1.upto(matrix_A.size - 1) do |index|
current_element = matrix_A[index - 1][index - 1]
p current_element
factor = matrix_A[index][index - 1].fdiv(current_element)
puts matrix_A[index][index - 1]
puts factor
p '*' * 50
index.upto(matrix_A.size - 1) do |i|
matrix_A[i].map!.with_index { |e, j| e - factor * matrix_A[index - 1][j] }
vector_B[i] -= factor * matrix_A[index - 1][i]
end
end
p matrix_A
p vector_B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment