Linear Algebra and the C Language/a06h
Inverse: Code study
First, I check the determinant. Then, I calculate the adjoint. Finally, I multiply all rows of the adjoint by the inverse of the determinant in a for() loop.
/* ------------------------------------ */
/* ------------------------------------ */
double **inv_mR(
double **A,
double **InvA
)
{
double det = det_R(A);
double invdet = 1;
int r;
if(!det)
{
printf("\n inv_mR error - The determinant is Zero");
printf("\n Press return to continue.\n");
fflush(stdout);
getchar();
exit(EXIT_FAILURE);
}
adjoint_mR(A,InvA);
invdet /= det;
for(r=R1; r<A[R_SIZE][C0]; r++)
mulR_mR(InvA,invdet,r);
return(InvA);
}
/* ------------------------------------ */
/* ------------------------------------ */