Mathc matrices/Fichiers h : z s
Installer ce fichier dans votre répertoire de travail.
z_r.h |
---|
/* ------------------------------------ */
/* Save as : z_r.h */
/* ------------------------------------ */
/* ------------------------------------
Call : time_t t;
int i;
srand(time(&t));
i = r_I(9);
------------------------------------ */
/* ------------------------------------
positive and negative numbers without zero
------------------------------------ */
int r_I(
int maxI)
{
int x;
x = (rand() % maxI) + 1; /* + 1 : not zero */
x *= pow(-1,rand());
return(x);
}
/* ------------------------------------
positive numbers without zero
------------------------------------ */
int rp_I(
int maxI)
{
return((rand() % maxI) + 1); /* + 1 : not zero */
}
/* ------------------------------------
positive and negative numbers with zero
------------------------------------ */
int r0_I(
int maxI)
{
int x;
x = rand()%maxI;
if(x) x*=pow(-1,rand());
return(x);
}
/* ------------------------------------
positive numbers with zero
------------------------------------ */
int rp0_I(
int maxI)
{
return(rand() % maxI);
}
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------
positive and negative floating point number without zero
e= 1E-0 -> 1234
e = 1E-1 -> 123.4
e = 1E-2 -> 12.34
e = 1E-3 -> 1.234
------------------------------------ */
double r_E(
int maxI,
double e)
{
double x;
x = (rand() % maxI) + 1 ; /* + 1 : not zero */
x *= pow(-1,rand()) * e;
return(x);
}
/* ------------------------------------ */
/* ------------------------------------
positive and negative floating point number with zero
e= 1E-0 -> 1234
e = 1E-1 -> 123.4
e = 1E-2 -> 12.34
e = 1E-3 -> 1.234
------------------------------------ */
double r0_E(
int maxI,
double e)
{
double x;
x = (rand() % maxI);
x *= pow(-1,rand()) * e;
return(x);
}
/* ------------------------------------ */
/* ------------------------------------
positive floating point number without zero
e= 1E-0 -> 1234
e = 1E-1 -> 123.4
e = 1E-2 -> 12.34
e = 1E-3 -> 1.234
------------------------------------ */
double rp_E(
int maxI,
double e /* 1E-1 1E-0 1E+1 */
)
{
double x;
x = (rand() % maxI) + 1 ; /* + 1 : not zero */
x *= e;
return(x);
}
/* ------------------------------------ */
/* ------------------------------------ */
Nous allons utiliser ses fonctions pour donner des valeurs aléatoires aux matrices.