Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Linear Algebra and the C Language/a0el

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

__NOTOC__ Install and compile this file in your working directory. /* ------------------------------------ */ /* Save as : c00a.c */ /* ------------------------------------ */ #include "v_a.h" /* The zero row and the zero column are not used!!! In the row zero you have an index for the columns. In the columns zero you have the size of the matrix. see the pall_mR(); function. ********************* The size of the rows is into A[R_SIZE][C0] = A[R0][C0] The size of the columns is into A[C_SIZE][C0] = A[R1][C0] ********************* The first element of the matrix is: A[R1 ][ C1] For a 10x10 matrix the last element is: A[R10][C10] ********************* */ /* ------------------------------------ */ /* ------------------------------------ */ double **x_i_mR( int r, int c ) { double **A; int ar; int ac; int i; if(r<R1||c<C1) { printf(" The size of the matrix must be positive integers.\n\n"); printf(" double **i_mR(); \n\n"); fflush(stdout); getchar(); exit(EXIT_FAILURE); } ar = r + R1; /* I add a row. The row zero */ ac = c + C1; /* I add a column. The column zero */ /* *************** */ A = malloc(ar * sizeof(*A)); if(!A) { printf(" I was unable to allocate the memory you requested.\n\n"); printf(" double **i_mR(); \n\n"); printf(" **A = malloc(ar * sizeof(*A));\n\n"); fflush(stdout); getchar(); exit(EXIT_FAILURE); } A[0] = malloc(ar * ac * sizeof(**A) ); if(!A[0]) { printf(" I was unable to allocate the memory you requested.\n\n"); printf(" double **i_mR();\n\n"); printf(" A[0] = malloc(ar * ac * sizeof(**A) );\n\n"); fflush(stdout); getchar(); exit(EXIT_FAILURE); } for(i=R1; i<ar; i++) A[i] = A[0]+i*ac; /* *************** */ A[R_SIZE][C0] = ar; /* I copy the number of lines */ A[C_SIZE][C0] = ac; /* I copy the number of columns */ for(r=R2; r<A[R_SIZE][C0]; r++) /* I set the zero column to zero */ /* without touching the size of */ A[r][C0] = 0.; /* the matrix. */ for(c=C1; c<A[C_SIZE][C0]; c++) /* I put the index in the row zero*/ A[R0][c] = c; m0_mR(A); /* Set all coefficients to zero */ return(A); } /* ------------------------------------ */ /* ------------------------------------ */ void fun(int r,int c) { double **A = i_mR(r,c); clrscrn(); printf(" A[R%d,C%d]: p_mR();",rsize_R(A),csize_R(A)); p_mR(A, S4,P0,C8); printf("\n\n"); printf(" A[R%d,C%d]: pall_mR();\n",rsize_R(A),csize_R(A)); pall_mR(A, S4,P0,C9); f_mR(A); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); do fun(rp_I(R4),rp_I(C8)); while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ You can see matrices of different sizes with their internal structures. Screen output example: A[R4,C4]: p_mR(); +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 A[R4,C4]: pall_mR(); +5 +1 +2 +3 +4 +5 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 Press return to continue Press X return to stop