Mathc complexes/Fichiers h : vbm

Un livre de Wikilivres.

Bibliothèque

Installer ce fichier dans votre répertoire de travail.

wbm.h
/* ------------------------------------ */
/*  Save as :  wbm.h                    */
/* ------------------------------------ */
double **add_mZ(
double **A,
double **B,
double **AplsB
)
{
int r;
int c;

  dif_sizes_mZ(A,B,    "add_mZ();","(A or B)");
  dif_sizes_mZ(A,AplsB,"add_mZ();","(AplsB)");

  for   ( r=R1; r<A[R_SIZE][C0]; r++)
    for ( c=C1; c<A[C_SIZE][C0]; c++)

          AplsB[r][c] = A[r][c] + B[r][c];
                 
 return(AplsB);
}
/* ------------------------------------ */
double **sub_mZ(
double **A,
double **B,
double **AmnsB
)
{
int r;
int c;

  dif_sizes_mZ(A,B,    "sub_mZ();","(A or B)");
  dif_sizes_mZ(A,AmnsB,"sub_mZ();","(AmnsB)");

  for   ( r=R1; r<A[R_SIZE][C0]; r++)
    for ( c=C1; c<A[C_SIZE][C0]; c++)

          AmnsB[r][c] = A[r][c] - B[r][c];

  return(AmnsB);
}
/* ------------------------------------ */
double **mul_mZ(
double **A,
double **B,
double **AB
)
{
int i,n;
int j;
int k;

nb_Z a;
nb_Z b;
nb_Z ab;
nb_Z abplsab;

  canImul_mZ(A,B,AB,"mul_mR();","(A or B or AB)");

              /* Work on the rows k */
              for(k= R1; k < A[R_SIZE][C0]; k++)
                  /* Work on the cols j */
                  for(j=C1; j<B[C_SIZE][C0]; j += C2)
                   {
                    abplsab = i_Z(0,0);
                    /* Compute AB(k,j)    */
                    for(i=C1,n=R1; i<A[C_SIZE][C0]; i += C2,n++)
                      {
                       a = i_Z(A[k][i],
                               A[k][i+C1]);

                       b = i_Z(B[n][j],
                               B[n][j+C1]);

                      ab = mul_Z(a,b);

                 abplsab = add_Z(abplsab,ab);
                        }
                          AB[k][j]    = abplsab.r;
                          AB[k][j+C1] = abplsab.i;
                   }

 return(AB);
}
/* ------------------------------------ */
double **smul_mZ(
double   s,
double **A,
double **sA
)
{
int r;
int c;

  dif_sizes_mZ(A,sA,"smul_mZ();","(A or sA)");

  for (   r=R1; r<A[R_SIZE][C0]; r++)
    for ( c=C1; c<A[C_SIZE][C0]; c++)
    
         sA[r][c] = s * A[r][c];

 return(sA);
}
/* ------------------------------------ */
double **zmul_mZ(
nb_Z z,
double **A,
double **zA
)
{
nb_Z a;
nb_Z b;
int r;
int c;

  dif_sizes_mZ(A,zA,"zmul_mZ();","(A or zA)");

  for (   r=R1; r<A[R_SIZE][C0]; r++)
    for ( c=C1; c<A[C_SIZE][C0]; c+=C2)
         {
          a = i_Z(A[r][c   ],
                  A[r][c+C1]);

          b = mul_Z(z,a);

          zA[r][c   ] = b.r;
          zA[r][c+C1] = b.i;
         }

  return(zA);
}
/* ------------------------------------ */
double **pow_mZ(
int      n,
double **A,
double **A_n
)
{
double **T;
int      i;

  isquare_mZ(A,      "pow_mZ();","(A)");
  dif_sizes_mZ(A,A_n,"pow_mZ();","(A or A_n)");

  T = i_RC_mZ(A[R_SIZE][C0],A[C_SIZE][C0]);

 c_mZ(A,A_n);

 if(!n) eye_mZ(A_n);
 else    for(i=n-1; i; i--)
            {
             mul_mZ(A_n,A,T);
             c_mZ(T,A_n);
            }
  f_mZ(T);
  
  return(A_n);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **sqrt_svd_mZ(
double **A,
double **sqrtA
)
{
int r;

  dif_sizes_mZ(A,sqrtA,"sqrt_mR();","(A or sqrtA)");
  
  for (   r=R1; r<A[R_SIZE][C0]; r++)
         {
          sqrtA[r][C1] = sqrt(A[r][C1]);
          sqrtA[r][C2] = 0;                    
         }
  
 return(sqrtA);
}
/* ------------------------------------ */
/* ------------------------------------ */


Il y a les fonctions addition, soustraction, multiplication... des matrices.