็How can i can write this python code in matlab ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
import random
N = 200
p = 0.02
n = int(input())
wrong_5 = 0
wrong_all = 0
for i in range(n) :
for j in range(N) :
r = random.uniform(0,1)
if r <= p :
wrong_all += 1
if wrong_all <= 5 :
wrong_5 += 1
wrong_all = 0
print(wrong_5 / n)
0 commentaires
Réponses (1)
Bshara Murr
le 25 Nov 2017
N = 200;
p = 0.02;
n = input('enter n:');
wrong_5 = 0;
wrong_all = 0;
for i = 1:n
for j = 1:N
r = rand;
if r <= p
wrong_all = wrong_all+1;
end
if wrong_all <= 5
wrong_5 = wrong_5+1;
end
end
wrong_all = 0;
end
fprintf('wrong_5 / n = %d', wrong_5/n);
0 commentaires
Voir également
Catégories
En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!