Mathc matrices/Fichiers c : trace1
Apparence
Installer et compiler ce fichier dans votre répertoire de travail.
trace1.c |
---|
/* ------------------------------------ */
/* Save as : trace1.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double trA;
double trB;
double **A = r_mR(i_mR(r,r),9);
double **B = r_mR(i_mR(r,r),9);
double **AplsB = i_mR(r,r);
clrscrn();
printf(" A : ");
p_mR(A,5,0,6);
printf(" B : ");
p_mR(B,5,0,6);
trA = trace_R(A);
trB = trace_R(B);
printf(" Trace(A)+Trace(B) = %+.0f%+.0f \t= %+.0f \n",
trA,
trB,
(trA+trB));
printf(" Trace(A+B) \t\t= %+.0f \n\n",
trace_R(add_mR(A,B,AplsB)));
f_mR(A);
f_mR(B);
f_mR(AplsB);
}
/* ------------------------------------ */
void hello(void)
{
printf("\n ");
printf("\n ");
printf("\n Trace(A+B) = Trace(A) + Trace(B): ");
printf("\n ******************************** ");
printf("\n ");
printf("\n ");
printf("\n \n");
stop();
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
hello();
do{
fun(rp_I(RC4)+RC2);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
La fonction trace se contente d'additionner tous les coefficients sur la diagonale.
Exemple de sortie écran :
A :
-7 -5 +4 -7 -6
-1 +9 -8 -4 +5
-9 -5 +4 +3 +5
+8 +9 -6 -1 +1
-9 -2 +6 +4 +4
B :
-3 +1 +4 -9 +8
+3 -5 -4 -3 -1
-6 -9 -7 -2 +3
-4 +6 +9 +6 +4
-9 +5 +4 -9 +1
Trace(A)+Trace(B) = +9-8 = +1
Trace(A+B) = +1
Press return to continue
Press X to stop