-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFRT_first_return_time.cpp
More file actions
79 lines (57 loc) · 1.21 KB
/
FRT_first_return_time.cpp
File metadata and controls
79 lines (57 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//Vamos a modificar el metodo para modelar tiempo medio de primer paso de la probabilidad de T 0->0
#include<cstdlib>
#include<fstream> //Libreria para grabar cosas en archivos
#include<iostream>
// En la terminal podemos correr ls *.dat > names.txt para hace una lista de archivos
using namespace std;
int Coin(double p){
double val = 1.0*rand()/RAND_MAX;
int out;
if (val<=p){
out = 1;
}
else{
out = 0;
}
return out;
}
int main(){
//Definimos la posicion inicial
int pos = 0;
//Definimos el tiempo
int t = 0;
//Definimos la probabilidad inicia
double p = 0.01;
//Definimos la probabilidad q
double q = 0.3;
srand(time(NULL)); //En la semilla, ponemos el tiempo para generar numeros aleatorios.
//Maneras de guardar el archivo
//string namefile;
//namefile = "FPT_p_" + to_string(p) + ".dat";
ofstream Results ("T00.dat");
for(int j; j <= 50; j += 1)
{
int flag = 0;
for(int i = 0; i<=10000; i++){
pos += Coin(p);
if(pos == 1){
t += 1;
pos = 0;
while(pos == 0){
pos += Coin(q);
t += 1;
}
}
else{
t += 1;
}
Results<<p<<" "<<t<<endl;
t = 0;
pos = 0;
}
p += 0.01;
}
cout<<"Done"<<endl;
Results.close();
return 0;
}