Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- x = var('D1')
- y = var('D2')
- z = var('D3')
- d1 = 0.9 * x + 0.7 * y + 0.8 * z - x == 0
- d2 = 0.05 * x - y == 0
- d3 = 0.05 * x + 0.3 * y + 0.2 * z - z == 0
- d4 = x + y + z == 1
- solution = solve([d1,d2,d3,d4], x,y,z)
- d = solution[0][0].right()
- m = solution[0][1].right()
- j = solution[0][2].right()
- show('D =' + str(round(d,5)) + ', M =' + str(round(m,5)) + ', J =' + str(round(j,5)))
- dico = {"Dormir": 1,"Manger": 2, "Jouer": 3}
- def Markov1pas(etat_init):
- r = random()
- if etat_init == dico["Dormir"]:
- if r <= 0.05:
- return dico["Manger"]
- elif r > 0.05 and r <= 0.1:
- return dico["Jouer"]
- else:
- return dico["Dormir"]
- elif etat_init == dico["Manger"]:
- if r <= 0.3:
- return dico["Jouer"]
- else:
- return dico["Dormir"]
- elif etat_init == dico["Jouer"]:
- if r <= 0.8:
- return dico["Dormir"]
- else:
- return dico["Jouer"]
- else:
- return -1
- def TempsEtats(etat_init, n):
- D = 0
- M = 0
- J = 0
- for i in range(n):
- if etat_init == dico["Dormir"]:
- D += 1
- elif etat_init == dico["Manger"]:
- M += 1
- elif etat_init == dico["Jouer"]:
- J += 1
- etat_init = Markov1pas(etat_init)
- print('Domir : ' + str(D) + ' minutes.')
- print('Manger : ' + str(M) + ' minutes.')
- print('Jouer : ' + str(J) + ' minutes.')
- print('\n')
- print('P(D)= ' + str(round(D/n, 5)))
- print('P(M)= ' + str(round(M/n, 5)))
- print('P(J)= ' + str(round(J/n, 5)))
- TempsEtats(1,6000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement