Y
Y
yana_adamovich2014-12-04 20:08:21
Programming
yana_adamovich, 2014-12-04 20:08:21

How to find matrix determinant by gauss method by column?

Calculation of the matrix determinant by the Gaussian method with the choice of the main element by the column. For testing, find the determinant of a matrix of dimension 4.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cyapa, 2014-12-04
@yana_adamovich

void GetDeterminant(double **matrix, int size, double epsilon)
{
    //Предполагается, что матрица квадратная
    int pivot_index = -1;
    double pivot_value = 0;
    double determinant = 1;
    
    for(int i = 0; i < size; i++)
    {
        for(int j = i; j < size; j++)
        {
            if(abs(matrix[j][i]) > pivot_value)
            {
                pivot_index = j;
                pivot_value = abs(matrix[j][i]);
            }
        }
        
        //Если опорный элемент равен нулю (эпсилон для сброса погрешности)
        if(pivot_value < epsilon)
        {
            //Матрица вырождена
            return 0;
        }
        
        if(pivot_index != i)
        {
            //Обменяем строки местами
            SwapRows(matrix, pivot_index, i)
            determinant *= -1;
        }
        
        for(int j = i + 1; j < size; j++)
        {
            if(matrix[j][i] != 0)
            {
                multiplier = 1 / matrix[i][i] * matrix[j][i];
                
                for(int k = i; k < size; k++)
                {
                    matrix[j][k] -= matrix[i][k] * multiplier;
                }
            }
        }
        
        determinant *= matrix[i][i];
    }
    
    return determinant;
}

Haven't worked with sami for a hundred years, so syntax errors are guaranteed. Especially with types.
But I think the meaning is clear.

A
Armenian Radio, 2014-12-04
@gbg

Using the Gauss method, you can bring the matrix to a triangular form, after which it turns out that its determinant is equal to the product of the elements of the main diagonal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question