Linear Algebra and the C Language/a0j7
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_c_withR0_mR(
double **A,
double **B
)
{
int r;
int c;
for (r=R0; r<A[R_SIZE][C0]; r++)
for (c=C1; c<A[C_SIZE][C0]; c++)
B[r][c] = A[r][c];
return(B);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r,int c)
{
double **A = r_mR(i_mR(r,c),99.);
double **B = i_mR(r,c);
clrscrn();
printf(" A:\n");
pall_mR(swapC_withR0_mR(A,C1,C2), S5,P0,C10);
printf(" B: c_withR0_mR(A,B);\n");
pall_mR(c_withR0_mR(A,B), S5,P0,C10);
f_mR(A);
f_mR(B);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
int i;
do
{
i = rp_I(R3)+R1;
fun(i,i+C1);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
If the index of the columns of matrix A has been modified, and if we copy A into B, this function allows us to preserve the position of the indices of A in B.
Screen output example:
A:
+5 +2 +1 +3 +4 +5
+6 -58 -71 +71 -28 -96
+0 -97 +59 -33 +87 -20
+0 -88 -14 +10 -35 -46
+0 +57 -26 +4 -40 +31
B: c_withR0_mR(A,B);
+5 +2 +1 +3 +4 +5
+6 -58 -71 +71 -28 -96
+0 -97 +59 -33 +87 -20
+0 -88 -14 +10 -35 -46
+0 +57 -26 +4 -40 +31
Press return to continue
Press X return to stop