src/sparse_matrix.rb
# The cofactor is the matrix you get if you get the determinant of
# all the minors in a square matrix and multiply the cofactor value by it.
# NOTE: returns an Array
The cofactor is the matrix you get if you get the determinant of
all the minors in a square matrix and multiply the cofactor value by it.
NOTE: returns an Array
The cofactor is the matrix you get if you get the determinant of all the minors in a square matrix and multiply the cofactor value by it . NOTE : returns an Array
def cofactor
        co_array = Array.new(@height)
        co_array.each_with_index {|row, row_num|
            co_array[row_num] = Array.new(@width, 0)
        }
        co_array.each_with_index {|row, row_num|
            row.each_with_index {|column, column_num|
                det_val = SparseMatrix.new(get_minor(row_num, column_num)).determinant()
                co_val = (-1) ** ((row_num + 1) + (column_num + 1)) 
                co_array[row_num][column_num] = co_val * det_val
            }
        }
        return co_array
    end
def cofactor co_array = Array . new ( @height ) co_array . each_with_index { | row , row_num | co_array [ row_num ] = Array . new ( @width , 0 ) } co_array . each_with_index { | row , row_num | row . each_with_index { | column , column_num | det_val = SparseMatrix . new ( get_minor ( row_num , column_num ) ) . determinant ( ) co_val = ( - 1 ) ** ( ( row_num + 1 ) + ( column_num + 1 ) ) co_array [ row_num ] [ column_num ] = co_val * det_val } } return co_array end
The cofactor is the matrix you get if you get the determinant of
all the minors in a square matrix and multiply the cofactor value by it.
The cofactor is the matrix you get if you get the determinant of all the minors in a square matrix and multiply the cofactor value by it .
# (-1) ^ (i + j)