-
-
Save randsina/ffe02f7a4ba9cb2aea6c to your computer and use it in GitHub Desktop.
lab for math analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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