The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: improving speed of simulation using random numbers
Replies: 1   Last Post: Nov 16, 2012 1:57 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 5
Registered: 9/27/12
improving speed of simulation using random numbers
Posted: Nov 15, 2012 4:03 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear all,

I am trying to compute an expected value using simulation.
I have a random number x with density function d[x]. I want to compute the expected value of function f[x], which is equal to the integral of f[x] times
d[x] over x.
In my case, it is difficult to compute the integral so I simulate N values for x and compute the average of f[x] over all N simulated values.

My problem is that my code takes to long for my purposes: this is a part of a larger program and is making it unfeasible in terms of time.

The following code provides an example of the situation, and my question is how could I reduce the time this takes. THanks a lot for your help

g[x_]:= x^2

mydensity[myparameter_]:= ProbabilityDistribution[myparameter*(t)^(-myparameter - 1), {t, 1, Infinity}]

randomnum[myparameter_] := RandomVariate[draw[myparameter], 50]

Timing[Sum[g[randomnum[5][[i]]], {i, 1, 50}]]

Out[1353]= {0.64, 81.7808}

This takes 0.6 seconds in my computer and that is way too long for my full program ( I do this many times).

Thanks again,

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.