This is a slide-based introduction to techniques for doing Monte Carlo simulation in Matlab. It comes from a course I teach as part of an online Masters degree program in engineering (mepp.engr.wisc.edu Higher res versions of this video can be found at blanchard.ep.wisc.edu

Note: This is a user submitted video under “User Submitted” Category. Although the submitted content is moderated, RealityPod does not guarantee the accuracy of information provided in posts of this particular category.

Hi,
That is really a great “learn by example”. I was really anxious about approaching Monte Carlo simulation. You made it so clear that I am now going to jump in with lots of enthusiasm!
Thanks!

Hi,
That is really a great “learn by example”. I was really anxious about approaching Monte Carlo simulation. You made it so clear that I am now going to jump in with lots of enthusiasm!
Thanks!

Actually, I just ran a test. Leaving the loop in and pre-allocating the displacement array didn’t save any time (at least not that I could measure). But getting rid of the loop altogether and using what I call the direct approach solved the problem 40 times faster.

@jakeblanchard
how to use Monte carlo integration to simulate Frequency Modulation ?
can u help me with a code fragment..plz
I have to simulate FM n AM in matlab using Monte Carlo method and I know nothing about matlab!
plz help..I m struggling in simulating FM
where
fm(t)=sin(c*t+kf*trap(cos(m*t. a, b, n)
where c=carrier freq,
m=message freq
k=constant
t=time
or any method if ur familier to FM

If force and length are vectors, then force*length tries to do vector multiplication, as you learned in linear algebra. If I do force .* length, then it does element by element math. That is, the first element of the force vector times the first element of the length vector and so on. So the “.” goes with the operator, not with the variables. There is also ./ for element by element division and .^ for powers.

Thank you Professor Blanchard for your explanation. I still have a question though.
I tried the “direct” version in MATLAB. What does the “.”
in “length^3/3.” in the last line (displacement=force.*length^3/3./modulus.inertia;) mean or what is “.” referring to, inertia, modulus, diameter or force?
Thanks so much in advance. I also appreciate answers which are not from Professor Blanchard. ðŸ™‚

In Matlab, rand(1) returns 1 random number, uniformly distributed between 0 and 1. Something like rand(5,1) will give you a list of 5 random numbers, also uniformly distributed between 0 and 1. rand(5,5) will give you a 5 by 5 array of random numbers.

hi Jake,
I did not understand your explanation for the introduction of rand(1) while carrying out the simulation. Can you explain me little more clearly. I am still little confused. I am still naive for these simulation subjects.
thanks,
Pavan

If I interpret your question correctly, you need a sensitivity analysis. Go to wikipedia and search for sensitivity if you want to get an overview of the subject. You can do this with Monte Carlo, but in most situations there are better ways.

Hi,

That is really a great “learn by example”. I was really anxious about approaching Monte Carlo simulation. You made it so clear that I am now going to jump in with lots of enthusiasm!

Thanks!

Hi,

That is really a great “learn by example”. I was really anxious about approaching Monte Carlo simulation. You made it so clear that I am now going to jump in with lots of enthusiasm!

Thanks!

@jakeblanchard

Actually, I just ran a test. Leaving the loop in and pre-allocating the displacement array didn’t save any time (at least not that I could measure). But getting rid of the loop altogether and using what I call the direct approach solved the problem 40 times faster.

@nbsr1

Good point. This is always a good practice and sometimes I’m lazy in this regard.

You might be able to speed up the “for loop” approach a lot by preallocating the displacement vector before the loop.

displacement = zeros(1,nsamples);

Currently the speed is limited by constant reallocation of the vector at each loop iteration.

@bulllsize

I don’t know anything about AM or FM, but I did find an article that might be of interest:

MONTE CARLO SIMULATION OF THE PLL FM DEMODULATOR by Pavel Hasan

@jakeblanchard

how to use Monte carlo integration to simulate Frequency Modulation ?

can u help me with a code fragment..plz

I have to simulate FM n AM in matlab using Monte Carlo method and I know nothing about matlab!

plz help..I m struggling in simulating FM

where

fm(t)=sin(c*t+kf*trap(cos(m*t. a, b, n)

where c=carrier freq,

m=message freq

k=constant

t=time

or any method if ur familier to FM

Nice Video dude

@pikuray001

I have never employed this approach. Sorry, I can’t help you.

could you please demonstrate multi-canonical monte carlo for the same system …. thnx ….

Pr. Blanchard,

Thank you for this very helpful video

@marcofking

No. rand returns a uniform distribution, but randn returns a normal distribution (mean=0, standard deviation=1).

@jakeblanchard Surely not a normal but an uniform distribution?

Thank you so much! I wish my professors in Germany were as engaged as you are. Thank you, thank you, thank you!

@copulapotthoff

If force and length are vectors, then force*length tries to do vector multiplication, as you learned in linear algebra. If I do force .* length, then it does element by element math. That is, the first element of the force vector times the first element of the length vector and so on. So the “.” goes with the operator, not with the variables. There is also ./ for element by element division and .^ for powers.

Thank you Professor Blanchard for your explanation. I still have a question though.

I tried the “direct” version in MATLAB. What does the “.”

in “length^3/3.” in the last line (displacement=force.*length^3/3./modulus.inertia;) mean or what is “.” referring to, inertia, modulus, diameter or force?

Thanks so much in advance. I also appreciate answers which are not from Professor Blanchard. ðŸ™‚

Thanks! Cool stuff.

Very helpful

Thanks!

Thank you!

The randn function will return random numbers with a normal distribution.

Great and useful demo;

I got one question though, if you want to build a normal distribution instead of uniform, how can you do that?

In Matlab, rand(1) returns 1 random number, uniformly distributed between 0 and 1. Something like rand(5,1) will give you a list of 5 random numbers, also uniformly distributed between 0 and 1. rand(5,5) will give you a 5 by 5 array of random numbers.

hi Jake,

I did not understand your explanation for the introduction of rand(1) while carrying out the simulation. Can you explain me little more clearly. I am still little confused. I am still naive for these simulation subjects.

thanks,

Pavan

If I interpret your question correctly, you need a sensitivity analysis. Go to wikipedia and search for sensitivity if you want to get an overview of the subject. You can do this with Monte Carlo, but in most situations there are better ways.

Hello Jake

How can I infer which is the most influencing variable in this design?

Regards, Nestor