Hi guys help pls I am in an exam I could'nt solve this question
조회 수: 1 (최근 30일)
이전 댓글 표시
When an attacker moves towards his enemy, he moves 2 steps forward with 50% probability and 1 step back with 50% probability. If it reaches its enemy, the dagger will try to neutralize its target with the arrow if it cannot approach. He can defeat his enemy with a probability of 45% with arrow and 90% with dagger. If he could not reach his enemy up to 100 moves, the arrow would otherwise use daggers, so what is the probability of neutralizing his enemy, which is 70 steps away from 100 moves? Write a monte carlo simulation code to answer this question. You can answer the question by repeating 100000 (one hundred thousand) times and averaging it. (It gonna be in script file)
댓글 수: 2
Zeynep Kiyak
2021년 1월 20일
편집: Walter Roberson
2021년 1월 20일
I need C ++ code to answer this question.
답변 (1개)
Image Analyst
2020년 5월 31일
Hint:
x = 0
hasArrow = 1;
hasDagger = 0;
for k = 1 : 100000 % Experiment number
for moves = 1 : 100 % Moves number
p = rand(1)
if p < 10 %............
% more code to count neutralizings depending on weapon.
end
end
end
p = count / 100000 % Average probability of neutralizing
When an attacker moves towards his enemy, he moves 2 steps forward with 50% probability and 1 step back with 50% probability. If it reaches its enemy, the dagger will try to neutralize its target with the arrow if it cannot approach. He can defeat his enemy with a probability of 45% with arrow and 90% with dagger. If he could not reach his enemy up to 100 moves, the arrow would otherwise use daggers, so what is the probability of neutralizing his enemy, which is 70 steps away from 100 moves? Write a monte carlo simulation code to answer this question. You can answer the question by repeating 100000 (one hundred thousand) times and averaging it. (It gonna be in script file)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Control System Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!