Determinant of a 3x3 matrix

3

Hello good night I have a question about how to do the operation to obtain the result of a 3x3 determinant, I have been looking for ideas on how to put it in my code but I can not understand it: /, until now I only have the matrix printed, I just want explain to me please, there is no need for me to do the code.

#include <stdlib.h>
#include <conio.h>
#include <time.h>

    int main()
    {   
    int matriz[3][3];
    int i,j;
    for (i=0;i<=2;i++)  //Llenado de matriz
    {
        for (j=0;j<=2;j++)
        {
            printf ("Ingrese el valor de la matriz");
            scanf ("%d",&matriz[i][j]);
        }
    }
    for (i=0;i<=2;i++)  //Imprime la matriz 3x3
    {
        for (j=0;j<=2;j++)
        {
            printf (" %d",matriz[i][j]);
        }
        printf ("\n");
    }






}
    
asked by Arturo 03.08.2018 в 03:20
source

3 answers

1

to obtain the determinant of a matrix of order 3X3 you can apply 2 methods:

  • Sarrus: It is oriented to matrices only in this order. The strategy is to add the first 2 rows of the matrix to the end of the matrix and multiply each element of each diagonal (by left and right) creating a subset of each side. The subtraction of the left subset and the right gives you the determinant. Here is an example of what I just explained to make it more useful.

    Suppose you have this matrix:

      1  2  0
      3 -1  4
      5  2 -2
    

    1) Copy the first 2 rows at the end of the matrix

      1     2      0
      3    -1      4
      5     2     -2
      1     2      0
      3    -1      4
    

    2) The part of creating the aforementioned subsets would be as follows      link (apology for quality)

    Both the left and the right side obtain 3 sub sets.    (1, -1, -2), (3, 2, 0) and (5, 2, 4) by the left

    (0, -1, 5), (4, 2, 1) and (-2, 2, 3) by the right

    3) As a third step you have to multiply the elements within each subset and add the subsets that are on the same side.

    Left side: from this side, the values are obtained from each multiplication:     2, from the first left subset, 0, from the second and 40 from the third. Adding these values you get the number 42. That is to say that the left subset has a value of 42.

    Then we do the same with the right: we get 0 of the first subset, 8 of the second and -12 of the third. Adding these values (8 + (-12)) = -4. That is to say that the right subset has a value of -4.

    4) As a last step subtract the values of the left subset with the right.       Left subset - Right subset = determinant

              42            -            (-4)     =     46
    
  • In conclusion, the determinant of the matrix is 46.

  • As a second option you can apply the LaPlace method that is oriented to arrays of order NxN or simply of order N. Such that N> = 3 since in lower matrices (such as those of order 2) the determinant is calculated making the product of the main diagonal minus that of the secondary, which will be used later. This theory says that the sum of the products of each element of a region (row or column) by the determinant of its attached matrix (it would be a matrix of order N-1) results in the determinant of it.

    Using the matrix from the previous example:

      1  2  0
      3 -1  4
      5  2 -2
    

    1) Select a row or column of any matrix (for ease of choice, choose the one with the most elements in 0). The row 1 (1, 2, 0) will be chosen.

    2) To calculate the determinant of the matrix of order 2 (the one attached to the original), what is done is to "cover" the selected row and the column that owns the current element that is multiplying it. That is, if I have the number 1 of the row I select, I fill in column 1, if I have 2, I cap column 2 and if I have the 0 I cap column 3.

    This would look like this:

    1 * C11 + 2 * c12 + 0 * c13

  • Where the subindices of c correspond to the row and column to be covered by the matrix and Cxy is the determinant of the remaining portion.

    C11 = det (

     -1  4 
      2 -2 
    

    ) = (-1 * -2) - (2 * 4) = -6 * element cofactor = 1 - > -6

    C12 = det (

      3  4      
      5 -2
    

    ) = (3 * -2) - (5 * 4) = -26 * element cofactor = -1 - > 26

    C13 = det (

      3 -1
      5  2
    

    ) = (3 * 2) - (5 * -1) = 11 * element cofactor = 1 - > 11

    PD: the cofactor of the element has been adding the subindices x and y and if the result is an even number, the value is 1, otherwise it is -1.

    Entonces para concluir, el determinante es:
    

    1 * (-6) + 2 * (26) + 0 * 11 = -6 + 52 = 46

        
    answered by 03.08.2018 / 06:30
    source
    2

    You would have to do Sarrows and for that, go through the matrix diagonally. I leave you a link where there is a for code to do this.

    IZQ - DER route

    for(i =0; i<f; i++){
     for (int i = 0; i < f; i++) {
        for (int j = 0; j < c-i ; j++) {
        }
    }
    

    DER - LEFT

    route
        for (int i = 0; i < f; i++) {
           for (int j = c-i; j<c; j++) {
        }
    }
    
        
    answered by 03.08.2018 в 04:37
    0

    Add to the beginning the declaration of the following variables:

    int x, y; 
    int determinante = 0;
    

    According to the distribution of the figures in the matrix, you can add the following cycle for the obtaining of the determinant:

    for (j=0; j<=2; j++){
    
    if (j==0) {
    x=1;
    y=2;    
    }
    
    if (j==1) {
    x=0;
    y=2;    
    }
    
    if (j==2) {
    x=0;
    y=1;    
    }
    
     determinante += matriz[0][j]*(matriz[1][x]*matriz[2][y]-matriz[1][y]*matriz[2][x]);
    }
    
    printf("El determinante es: %d", determinante);
    
        
    answered by 03.08.2018 в 06:44