2017-06-26 10 views
1

Ich versuche eine Funktion zu machen, um eine Matrix zu transponieren (Adjugate Matrix). Ich habe verschiedene Dinge ausprobiert, aber es stürzt immer noch ab. Hast du irgendwelche Ideen, was könnte das Problem sein?Funktion für eine Transponierung einer 3x3 Matrix in c

P.S nenne ich diese Funktion mit adjoint(a, b);

P.S.S Der Zweck des gesamten Programms ist es, eine Inverse einer Matrix zu schaffen.

Edited Code (größere Teil des Codes ausgesucht und zeigt Funktionen, die das Abstürzen des Programms führen kann)

#include <stdio.h> 
#include <stdlib.h> 
#define SIZE 3 //defining the size of the matrix (3x3) 
#define SIZE2 2 //defining the size of the matrix (2x2) 


//prototyping the functions used to calculate the inverse of the matrix 
void readMatrix(double a[SIZE][SIZE]); 
void printMatrix(double a[SIZE][SIZE]); 
void printMinorMatrix(double b[SIZE2][SIZE2]); 
void selecting(double a[SIZE][SIZE], double b[SIZE2][SIZE2]); 
double calculating(double a[SIZE][SIZE],double m[8]); 
void anArray(double m[8]); 
double convert(double m[8], double [SIZE][SIZE]); 
double determ(double m[8], double n[SIZE][SIZE]); 
double adjoint(double a[SIZE][SIZE],double b[SIZE][SIZE]); 
double multiplyMatrix(double a[SIZE][SIZE], double b[SIZE][SIZE], double 
result[SIZE][SIZE]); 

int main() 
{ 
    double a[SIZE][SIZE]; 
    double b[SIZE2][SIZE2]; 
    double m[8]; 
    double n[SIZE][SIZE]; 
    double d; 
    double q[SIZE][SIZE]; 
    int i,j,k; 



    printf("Adjoint of the Matrix:\n"); 
    printf("_________________________________________\n\n"); 
    adjoint(a,b); 
    printf("\n\n"); 


    printf("Scalar Multiplication:\n"); 
    printf("_________________________________________\n\n"); 
    multiplyMatrix(i,j,k); 
    printf("\n\n"); 

    return 0; 
} 




//Reading a 3x3 Matrix 
void readMatrix(double a[SIZE][SIZE]) 


//Printing a 3x3 Matrix 
void printMatrix(double a[SIZE][SIZE]) 


//Printing a 2x2 Matrix 
void printMinorMatrix(double b[SIZE2][SIZE2]) 


//Selecting a 2x2 Matrix from a 3x3 Matrix 
void selecting(double a[SIZE][SIZE],double b[SIZE2][SIZE2]) 


//Calculating the determinant of a 2x2 matrix 
double calculating(double a[SIZE][SIZE], double m[8]) 



//Printing an Array of Length 9 
void anArray(double m[8]) 


//Calculating the determinant of a 3x3 matrix 
double determ(double m[8], double n[SIZE][SIZE]) 


//Converting an Array into a Matrix 
double convert(double m[8], double K[3][3]) 



//Transposing a Matrix 
double adjoint(double a[SIZE][SIZE],double b[SIZE][SIZE]) 
{ 
    int i,j; 
    for(i=0;i<SIZE;i++) 
    { 
     for(j=0;j<SIZE;j++) 
      if(i!=j&&i<j) 
       { 
         b[i][j]=a[j][i]; 
       } 
      else b[i][j]= a[i][j]; 
    } 
    return b[SIZE][SIZE]; 
} 

//Scalar multiplication 
double multiplyMatrix(double a[SIZE][SIZE], double b[SIZE][SIZE], double result[SIZE][SIZE]) 
{ 
    int i, j, k; 

    for(i=0;i<SIZE;i++) 
    { 
     for(j=0;j<SIZE;j++) 
     { 
      result[i][j]=0.0; 

      for(k=0;k<SIZE;k++){ 
       result[i][j] += a[i][k]*b[k][j]; 
      } 
     } 
    } 
} 
+1

'if (i! = J && i alinsoar

+1

Änderung 'return b [ SIZE] [SIZE] 'to' gibt b [SIZE -1] [SIZE -1] 'zurück. Aber warum willst du einen Wert zurückgeben? Ihr Zweck wird auch ohne das getan. –

+0

Veröffentlichen Sie den vollständigen Code in einem Beispielprogramm, das das Problem zeigt – chqrlie

Antwort

2

Das Problem ist

return b[SIZE][SIZE]; 

Sie einen Wert zurückgeben das gibt es nicht. in-Grenzen der letzte Wert ist

return b[SIZE-1][SIZE-1]; 

im ganzen Code Sehen, Sie viele Warnungen Sohle haben, bevor Sie den Code ausführen ...

Die wichtigste der Vorlagefrage ist, dass.

b Matrix adjoint Funktion übergeben wird 2x2 Matrix statt 3x3 Matrix.

In main deklariert Sie

double a[SIZE][SIZE]; 
double b[SIZE2][SIZE2]; 

wo

#define SIZE 3 //defining the size of the matrix (3x3) 
#define SIZE2 2 //defining the size of the matrix (2x2) 
+0

Sie haben wahrscheinlich Recht Ich habe das geändert, aber leider funktioniert es immer noch nicht; // –

+1

Was meinst du mit _does funktioniert_ ??? – LPs

+0

@JohnSmith Wenn dies nicht funktioniert, dann könnte Fehler in einem anderen Teil des Codes sein.Bitte geben Sie den vollständigen relevanten Code. –

Verwandte Themen