Linear Algebra and the C Language/a09c
Code study: GJ_TP_mR(Ab);
- The algorithm consists of checking whether the matrix A is not singular (det_R(A) != 0). If it is not singular we call the function gj_TP_mR(Ab);
- If the matrix has more columns than rows, we take a submatrix which has r rows and r columns where r is the number of rows of the matrix to calculate the determinant. Then if the submatrix is not singular we call the function gj_TP_mR(Ab);
- If the matrix has more columns than rows the program stops.
/* ------------------------------------ */
/* ------------------------------------ */
double **GJ_TP_mR(
double **Ab
)
{
double **A;
if(Ab[R_SIZE][C0] == Ab[C_SIZE_A][C0])
{
A = i_RC_mR(Ab[R_SIZE][C0],Ab[C_SIZE_A][C0]);
c_Ab_A_mR(Ab,A);
if(det_R(A)) gj_TP_mR(Ab);
f_mR(A);
}
else if(Ab[R_SIZE][C0] < Ab[C_SIZE_A][C0])
{
A = i_RC_mR(Ab[R_SIZE][C0],Ab[R_SIZE][C0]);
c_Ab_subArxr_mR(Ab,A);
if(det_R(A)) gj_TP_mR(Ab);
f_mR(A);
}
else if(Ab[R_SIZE][C0] > Ab[C_SIZE_A][C0])
{
printf("\n Error : GJ_TP_mR();\n");
printf("\n The number of colums\n");
printf("\n must be superior or egal\n");
printf("\n to the number of rows\n");
printf("\n Press return to continue.\n");
fflush(stdout);
getchar();
exit(EXIT_FAILURE);
}
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */