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];
}
}
}
}
'if (i! = J && i
alinsoar
Ä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. –
Veröffentlichen Sie den vollständigen Code in einem Beispielprogramm, das das Problem zeigt – chqrlie