Linear Algebra and the C Language/a0eg


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */   
void x_isquare_mR(
double **A,
char function[],
char matrices[]
)
{
   if ( A[R_SIZE][C0] != A[C_SIZE][C0] )
    {
     printf("\n Error : %s\n",function);
     printf("\n Matrix %s must be square.  \n",matrices);
     stop();
     exit(EXIT_FAILURE);
    }
}
/* ------------------------------------ */
int main(void)
{  
double **A     = i_mR(R5,R6);

  clrscrn();
  
  printf(" A[R%d,C%d]:",rsize_R(A),csize_R(A));
  p_mR(A, S4,P0,C6);

  isquare_mR(A,"det_R();","(A)");
  
  f_mR(A);
        
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
The isquare_mR(); function  checks if the matrix is ​​square. If the matrix is ​​not square, I chose to stop the program.

You can provide the name of the function that calls it. You can also provide the name of the matrix that is causing the problem. Example of use: rdiag_mR();, rsymmetric_mR();.

Screen output example:

                                                                                       
 A[R5,C6]:
  +0   +0   +0   +0   +0   +0 
  +0   +0   +0   +0   +0   +0 
  +0   +0   +0   +0   +0   +0 
  +0   +0   +0   +0   +0   +0 
  +0   +0   +0   +0   +0   +0 


 Error : det_R();

 Matrix (A) must be square.  
 Press return to continue.