Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
S
SGI-Bourgoin-Trachino
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki externe
Code
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de conteneurs
Registre de modèles
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Hugo TRACHINO
SGI-Bourgoin-Trachino
Validations
2e758036
Valider
2e758036
rédigé
Il y a 5 ans
par
Hugo TRACHINO
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
TD1 part1
parent
49e94f60
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
sgi2018/src/tools/matlab.h
+61
-7
61 ajouts, 7 suppressions
sgi2018/src/tools/matlab.h
avec
61 ajouts
et
7 suppressions
sgi2018/src/tools/matlab.h
+
61
−
7
Voir le fichier @
2e758036
...
...
@@ -4,7 +4,7 @@
#include
<iostream>
#include
<fstream>
#include
"../types.h"
#include
<complex>
/*
* Code translated from Matlab base functions
* matlab translation guide : https://eigen.tuxfamily.org/dox/AsciiQuickReference.txt
...
...
@@ -115,27 +115,71 @@ Vector polyval(const Polynomial& pol, const Vector& x)
}
//-------------------------------------------------------------------------------------------------
// RANDOM HELPING FUNCTION
const
unsigned
int
n
=
65535
;
//0xFFFF;
const
unsigned
int
m
=
16807
;
const
unsigned
int
b
=
0
;
static
long
seed
=
43690
;
//0xAAAA;
// generate an uniformaly distributed random number sampled from [0;0x7FFFFFFF]
long
uniform
()
{
long
unsigned
int
hi
=
m
*
(
seed
&
n
);
long
unsigned
int
lo
=
m
*
(
seed
>>
16
);
lo
+=
(
hi
&
32767
)
<<
16
;
lo
+=
hi
>>
15
;
if
(
lo
>
2147483647
)
//0x7FFFFFFF)
lo
-=
2147483647
;
//0x7FFFFFFF;
seed
=
(
long
)
lo
;
return
seed
;
}
//--------------------------------------------------------------------------------------------------
// RANDOM
// generate an uniformaly distributed random number sampled from [-1;1]
inline
number
randu
()
{
throw
std
::
logic_error
(
"Function not yet implemented."
);
//on le veut entre -1 et 1 / pour l'instant on l'a entre 0 et 1
number
result
=
uniform
()
/
2147483647
;
//(double)0x7FFFFFFF;
// number result = (uniform() - (number)3xFFFFFFF.8)/(number)3xFFFFFFF.8);
return
result
;
// throw std::logic_error("Function not yet implemented.");
}
// generates a vector of the given size, the entries of the vector are all complex number
// their real and imaginary parts are uniformaly distributed random number sampled from [-1;1]
ComplexVector
randu
(
int
size
)
{
// NOTE: this can be built on the previous function
throw
std
::
logic_error
(
"Function not yet implemented."
);
ComplexVector
complexVector
(
size
);
std
::
complex
<
number
>
mycomplex
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
std
::
complex
<
number
>
mycomplex
(
randu
(),
randu
());
complexVector
(
i
)
=
mycomplex
;
}
return
complexVector
;
//throw std::logic_error("Function not yet implemented.");
}
// generate a normally distributed random number
// sampled from a distribution with mean 0 and std 1
inline
number
randn
()
{
throw
std
::
logic_error
(
"Function not yet implemented."
);
number
res
;
number
U0
=
uniform
()
/
2147483647
;
//(double)0x7FFFFFFF;
number
U1
=
uniform
()
/
2147483647
;
//(double)0x7FFFFFFF;
res
=
sqrt
(
-
2
*
log
(
U0
))
*
cos
(
2
*
M_PI
*
U1
);
return
res
;
// throw std::logic_error("Function not yet implemented.");
}
// generates a vector of the given size, the entries of the vector are all complex number
...
...
@@ -143,9 +187,19 @@ inline number randn()
ComplexVector
randn
(
int
size
)
{
// NOTE: this can be built on the previous function
throw
std
::
logic_error
(
"Function not yet implemented."
);
ComplexVector
complexVector
(
size
);
std
::
complex
<
number
>
mycomplex
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
std
::
complex
<
number
>
mycomplex
(
randn
(),
randn
());
complexVector
(
i
)
=
mycomplex
;
}
return
complexVector
;
//throw std::logic_error("Function not yet implemented.");
}
//-------------------------------------------------------------------------------------------------
// IMPORT
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter