Borrar filtros
Borrar filtros

How to test the MATLAB code in Monte carlo simulation?

3 visualizaciones (últimos 30 días)
DhanaLakshmiR
DhanaLakshmiR el 15 de Dic. de 2017
Comentada: Steven Lord el 10 de Nov. de 2020
I have written the code for UAV travelling along the trajectory including it avoids the obstacle along the travelling path.I have executed the MATLAB code it runs properly. Now, how to test these codes in Monte carlo simulation? I don't know my question is right or not.I don't know about Monte carlo simulation.

Respuesta aceptada

Image Analyst
Image Analyst el 15 de Dic. de 2017
Monte Carlo means getting random values to use in your process, and then doing it a bunch of times (a bunch of experiments) to see all the different outcomes that you may get. Each run (experiment) will give a different outcome because random values were used in the process. For example you may get the mean outcome or find the max and min outcomes, or get a distribution of outcomes.
See attached Monte Carlo and random walk demos that I've written. Adapt as needed.
  8 comentarios
Image Analyst
Image Analyst el 10 de Nov. de 2020
Editada: Image Analyst el 10 de Nov. de 2020
  1. Yes, of course. just because you seed the random number generator with some number does not mean that the simulation is no good. Let's say you called rng(0) and then got a million numbers and used them to do your simulation. That simulation is fine. It's usable. See this demo:
r1 = rand(1, 3)
r2 = rand(1, 3)
rng(0)
r3 = rand(1, 3)
rng(0)
r4 = rand(1, 3)
r1 =
0.91338 0.63236 0.09754
r2 =
0.2785 0.54688 0.95751
r3 =
0.81472 0.90579 0.12699
r4 =
0.81472 0.90579 0.12699
Note that sets r3 and r4 are the same set of numbers because I called rng(0) before generating each one, while r1 and r2 have different numbers because I didn't call rng(0). But either r4 or r3 are perfectly valid sets of numbers to use in your simulation.
2. The Monte Carlo simulation generates a bunch of results - one for each random number. So you'll have a distribution of results. You could histogram those results to see that distribution, or you could take the mean of the results if you just wanted the mean.
3. You don't get any better or worse results by using rng(0). It simply gives you a repeatable set of numbers. So if you got a million numbers in one run (a million experiments), and then wanted to repeat that, then if you used rng(0) before the first million runs, and before the second million runs, then both sets of million runs would give the same distribution and mean because both sets of a million random numbers are identical. If you did not use rng(0), then the distributions and means from the second run of a million experiments would be similar to but not exactly the same as the first run because the random numbers would be different.
I see no reason why using rng(0) before a run would give you better results than not using it, as you say. If you did a small number of runs, like say 3, then you have 3 results and it's possible that you can rank them from "closest" to "farthest away" from some theoretical result, and it's possible that the one with rng(0) is closest but it would just be a coincidence. I mean, out of some number of runs, one of them is always closest, isn't it? Of course. It may just be a conincidence that using rng(0) makes that run closest to your theoretical result. If you did many more runs without using rng(0), then it's likely some different run would be closer, like the 10th one or 2000th run or whatever.
Steven Lord
Steven Lord el 10 de Nov. de 2020
One of the main purposes behind rng is repeatability. If you initialize the pseudorandom number generator to a known state using rng before running a simulation, if something "interesting" happens during that simulation you can set the generate back to that known state and rerun the simulation until the "interesting" thing happens.
While 0 is probably the most common "known state" to use in initializing the pseudorandom number generator, you could choose another state.
figure
rng(0)
plot(rand(1, 10))
title('0')
figure
rng(42)
plot(rand(1, 10))
title('42')
figure
rng(2020)
plot(rand(1, 10))
title('2020')
figure
rng(42)
plot(rand(1, 10))
title('42 again')

Iniciar sesión para comentar.

Más respuestas (1)

Omoniyi Tope
Omoniyi Tope el 8 de Feb. de 2020
Hello, I am trying to write a Monte Carlo simulation to create damages in a bridge and its really difficult. Please could you provide some assistance.
  1 comentario
Image Analyst
Image Analyst el 8 de Feb. de 2020
Sure. We'll try, if you give us something to work with and not be so vague. Please read this link and then write back with a new question since your "Answer" is definitely not an answer to Dhana's question on Monte Carlo simulation.

Iniciar sesión para comentar.

Categorías

Más información sobre Monte-Carlo 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