improving speed of simulation using random numbers

• To: mathgroup at smc.vnet.net
• Subject: [mg128662] improving speed of simulation using random numbers
• From: felipe.benguria at gmail.com
• Date: Thu, 15 Nov 2012 03:56:34 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net

```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,
Felipe

```

• Prev by Date: Re: Euclidean distance of all pairwise combinations (redundants)
• Next by Date: Re: Relational operators on intervals: bug?
• Previous by thread: Re: System of second-order nonlinear ordinary differential equations
• Next by thread: Re: improving speed of simulation using random numbers