Hi guys help pls I am in an exam I could'nt solve this question

1 visualización (últimos 30 días)
ahmet bal
ahmet bal el 31 de Mayo de 2020
Comentada: Walter Roberson el 20 de En. de 2021
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 comentarios
Zeynep Kiyak
Zeynep Kiyak el 20 de En. de 2021
Editada: Walter Roberson el 20 de En. de 2021
I need C ++ code to answer this question.
Walter Roberson
Walter Roberson el 20 de En. de 2021
Zeynep Kiyak: C++ code is not a MATLAB question.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 31 de Mayo de 2020
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)

Categorías

Más información sobre Get Started with Control System Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by