Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2013-03-08 13:59:55

bobbym

Online

Simulations

Hi;

This problem appears in the Devore book "Probability and Statistics" and has various answers on the internet.

The weekly demand for propane gas (in thousands of gallons) from a particular facility is a random variable X with PDF

What is the expected usage for gas for the coming week?

A number of different answers are given. How can we get the answer using a CAS and simulating the process?

1) Define the PDF in mathematica as:

Code:

`myPDF[]=ProbabilityDistribution[2(1-1/x^2),{x,1,2}];`

2) Run the simulation a million times.

Code:

`data=RandomVariate[myPDF[],10^6];`

Below is a histogram of data.

3) Get the expected value:

Code:

`Mean[data]`

1.61357 is returned. So the facility expects to use about 1613 gallons of propane this week.

Last edited by bobbym (2013-03-08 14:35:57)

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#2 2013-03-08 20:04:34

anonimnystefy
Real Member

Offline

Re: Simulations

And it agrees with my answer of 3-2ln(2).

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#3 2013-03-08 20:12:25

bobbym

Online

Re: Simulations

More importantly were you able to duplicate the answer with your package?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#4 2013-03-08 20:14:32

anonimnystefy
Real Member

Offline

Re: Simulations

I will try later.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#5 2013-03-08 20:17:50

bobbym

Online

Re: Simulations

Okay, you will find it interesting.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#6 2013-03-08 20:57:29

anonimnystefy
Real Member

Offline

Re: Simulations

What kind of distribution would that be?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#7 2013-03-08 21:08:50

bobbym

Online

Re: Simulations

The one given in post #1 of course!

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#8 2013-03-08 21:11:16

anonimnystefy
Real Member

Offline

Re: Simulations

Yes, but what kind is it? Maxima needs me to specify if it is a normal, geometrical, exponential,...

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#9 2013-03-08 21:36:38

bobbym

Online

Re: Simulations

It is none of them.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#10 2013-03-08 21:41:35

anonimnystefy
Real Member

Offline

Re: Simulations

I am not sure how to do it, then.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#11 2013-03-08 21:43:05

bobbym

Online

Re: Simulations

Would you like one way how?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#12 2013-03-08 21:45:55

anonimnystefy
Real Member

Offline

Re: Simulations

Yes.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#13 2013-03-08 21:49:02

bobbym

Online

Re: Simulations

Hi;

I am playing with a method right now but do not have all the kinks ironed out of it. I will post what I have.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#14 2013-03-08 21:50:20

anonimnystefy
Real Member

Offline

Re: Simulations

That is okay.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#15 2013-03-08 22:02:23

bobbym

Online

Re: Simulations

I want to draw random numbers from the PDF y = 3x^2 from 0 to 1.

So I solve for x

Follow?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#16 2013-03-08 22:02:56

anonimnystefy
Real Member

Offline

Re: Simulations

Yes.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#17 2013-03-08 22:08:25

bobbym

Online

Re: Simulations

Then I take the RHS of that equation where I solved for x and integrate wrt y.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#18 2013-03-08 22:12:27

anonimnystefy
Real Member

Offline

Re: Simulations

Okay. What now?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#19 2013-03-08 22:13:42

bobbym

Online

Re: Simulations

I replace each y in the answer with a random variable that is uniformly distributed between 0 and 1.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#20 2013-03-08 22:31:29

anonimnystefy
Real Member

Offline

Re: Simulations

Hm, why does it work?

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#21 2013-03-08 22:33:31

bobbym

Online

Re: Simulations

It doesn't, I think I have it now though. To follow you must know how to generate random numbers between a and b in maxima. Do you follow?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#22 2013-03-08 22:36:42

anonimnystefy
Real Member

Offline

Re: Simulations

Yes. I have the function.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#23 2013-03-08 22:38:30

bobbym

Online

Re: Simulations

Okay a little theory before we go any further. If you generate 10000 random numbers between 0 and 1 what do you call that distribution?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

#24 2013-03-08 22:40:37

anonimnystefy
Real Member

Offline

Re: Simulations

Uniform.

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

#25 2013-03-08 22:41:31

bobbym

Online

Re: Simulations

You will need to know how to get a histogram of those 10000 points with 10 boxes. Do you know how?

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.