I want to find the determinant of a square 4x4 matrix using a minor and cofactor.
And I want those in three seperate functions where i is the number of rows and j is the number of columns:
double minor(double a[][4], int row, int column);
Done by removing a row and column from the matrix. I know it's possible without pointers or classes, but I don't know how.
double cofactor(double a[][4], int row, int column);
The cofactor is the minor*(-1)^(i+j)
How does one do that exactly.
double det_c(double a[][4]
Specifically using a column so it goes this way:
-selecting a column
-multiply each element of that column by its cofactor
-Add the products obtained in the previous step
I do know how to make a matrix and print it on the screen:
#include <iostream>
using namespace std;
//Definieren van de maximale grootte van de matrix
#define MAX_SIZE 4
//Definieren van het type voor de matrix
typedef double matrix[MAX_SIZE][MAX_SIZE];
//Functie prototype
void lees_matrix(matrix a, int k, int l);
void print_matrix(matrix c, int k,int j);
//double minor(matrix a, int rij, int kolom);
//double cofactor(matrix a, int i, int j);
int main()
{
//Declaraties
matrix a;
int rij, kolom;
cout <<"Voer het aantal rijen en kolommen voor de matrix in" << endl;
cin >> rij >> kolom;
if(rij>MAX_SIZE || kolom>MAX_SIZE)
{
cout << "De maximale grootte van de rijen of kolommen wordt overschreden." << endl;
exit(1);
}
lees_matrix(a, rij, kolom);
print_matrix(a, rij, kolom);
minor(a, rij, kolom);
system("PAUSE");
return 0;
}
/*------------------------------------------------------------*/
//Function for reading matrix
void lees_matrix(matrix a, int k, int l)
{
int rij, kolom;
for (rij=0; rij<k; rij++)
{
cout << "Voer de data in voor rij "<< rij+1 << endl;
for(kolom=0; kolom<l; kolom++)
{
cin >> a[rij][kolom];
}
}
cout << endl;
return;
}
/*------------------------------------------------------------*/
//Function for printing a matrix
void print_matrix(matrix a, int k,int j)
{
int rij, kolom;
for(rij=0; rij<k; rij++)
{
for(kolom=0; kolom<j; kolom++)
{
cout << a[rij][kolom] << " ";
}
cout << endl;
}
return;
}
I'm Dutch, so not everything might be clear, but I guess you can find out what I did here. (rij=row, kolom=column)