Skip to main content
16 votes

How can I generate the same random number in Mathematica and MATLAB?

If it is solely for regression testing, the quality of the random numbers doesn't matter very much. You can substitute a better random number generator once you know the Mathematica version matches ...
mikado's user avatar
  • 16.8k
16 votes

Generating random sequence of integers with ordering constraints

Perhaps have a look at DiscreteMarkovProcess using an appropriate transition matrix embedding your constraints? Here's a simple example, implementing 1-5 above, to ...
George Varnavides's user avatar
13 votes
Accepted

Modelling snowfall as a random walk with a drift

I don't think Accumulate is powerful enough. Rather, you should use FoldList. ...
m_goldberg's user avatar
  • 108k
10 votes
Accepted

Survival Probability for Random Walks

Something seems odd to me about your code. You are summing twice, once with Accumulate and once with FoldList. If this is ...
Mr.Wizard's user avatar
  • 272k
9 votes
Accepted

How to simulate a random walk to randomly generated particle to another particle fixed at the center of a grid?

So, here is my reformulations of C.E.'s code. What has changed: I use reservoirs rand and randpts of large random arrays; ...
Henrik Schumacher's user avatar
9 votes

Record Statistics for Discrete Random Walks

Here's one take: path = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 1000]]; records = FoldList[Max, path]; ListPlot[{ path, records }] ...
C. E.'s user avatar
  • 70.8k
9 votes
Accepted

RandomPoint inside mesh for walk-on-spheres Monte Carlo PDE solver

Thanks to Henrik Schumacher I got this to work with NestWhileList and visualized the walk on spheres. The other outputs of ...
flinty's user avatar
  • 25.6k
9 votes
Accepted

Animating a random walk of 3D water molecules?

all the molecules have the same orientation at any time, and I think I see why Because at each timestep you are are computing only a single angle and using it to rotate every molecule. In this ...
Jason B.'s user avatar
  • 69k
7 votes

Survival Probability for Random Walks

We can do this using an implementation of FoldWhileList. First, implement FoldWhileList using this great answer. ...
Carl Lange's user avatar
  • 13.1k
6 votes
Accepted

Driving a system of differential equations with an AR1-Process

You need to use RandomFunction[ItoProcess[]] instead of NDSolve. The syntax is a frustratingly a little different than ...
Chris K's user avatar
  • 20.3k
6 votes

Record Statistics for Discrete Random Walks

Let's generate data from a random walk first SeedRandom[42] walkdata = Accumulate[RandomVariate[LaplaceDistribution[0, 1], 100]] , then one way to get what you ...
Thies Heidecke's user avatar
6 votes

What is this this application of KalmanEstimator doing?

First consider the response of the antenna to a sinusoid. The response is attenuated and has a delay. (This can also be seen from the BodePlot, if need be.) ...
Suba Thomas's user avatar
  • 8,776
6 votes
Accepted

Joint Moments of Stochastic Process at Different Times

You can use Expectation: ...
Domen's user avatar
  • 27.3k
5 votes
Accepted

How to generate Markov chains with given length and end state?

A random transition matrix for a 6-state Markov process: SeedRandom[1234]; T = Normalize[#, Total] & /@ RandomReal[{0, 1}, {6, 6}]; Calculate the ...
Roman's user avatar
  • 48.3k
5 votes

Need to calculate total distance traveled in a 2D random walk

SeedRandom[1] s = 0; path = Table[s += RandomReal[{-0.5, 0.5}, 2], {100}]; You can use ArcLength or ...
kglr's user avatar
  • 398k
5 votes

Survival Probability for Random Walks

It seems to me that this is a problem to which Catch and Throw can be usefully applied. ...
m_goldberg's user avatar
  • 108k
5 votes

How do I create a random point on the surface of a cube?

We simply need a MeshRegion that represents the boundary of the unit cube. Then we apply RandomPoint to it. The following shows ...
Henrik Schumacher's user avatar
5 votes
Accepted

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

You may do this using "SmoothKernelDistribution". Here is a simple example. We first create some data from a Normal Distribution: ...
Daniel Huber's user avatar
  • 53.1k
5 votes

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

This is precisely what RandomChoice does: choosing numbers according to weights. For example, if your histogram is ...
Roman's user avatar
  • 48.3k
5 votes
Accepted

Plotting Individual Variables from RandomFunction

As J.M. stated in the comments, sample["PathComponents"] allows me to isolate the variables.
Cameron F.'s user avatar
5 votes
Accepted

How can I improve this code?

...
N.J.Evans's user avatar
  • 5,093
5 votes

How to use first time generated randomly matrix?

You might be looking for memoization: V[i_, j_] := V[i, j] = Table[RandomInteger[{-10 i, 10 j}], {3}, {3}]
lericr's user avatar
  • 30.2k
5 votes

How to use first time generated randomly matrix?

You can call your function once to generate the matrix, and store the result in a different variable... ...
MelaGo's user avatar
  • 8,751
4 votes

How to simulate a random walk to randomly generated particle to another particle fixed at the center of a grid?

This is like what you described, except that I also made sure that the particle didn't wander outside of the region $-100 \leq x, y \leq 100$ to ensure that convergence wouldn't take too long. ...
C. E.'s user avatar
  • 70.8k
4 votes
Accepted

How can I generate monotonic random real numbers

...
kglr's user avatar
  • 398k
4 votes
Accepted

Reverse graph generation

Using IGraph/M, to check if a degree sequence is graphical (i.e. if there's a simple graph with that degree sequence): IGGraphicalQ[degseq] To generate a single ...
Szabolcs's user avatar
  • 236k
4 votes

Combine WienerProcess and WhiteNoiseProcess

Which part of the IMU are you trying to simulate...just the signals of ax, ay, az, gx, gy, gz? Or Maybe them fused together to get an angle of some kind? You didn't post all of your code, so I can't ...
DrMrstheMonarch's user avatar
4 votes

Ito Process sourced by Gaussian Process?

It is not a solution, but some comparison two different approach to the same problem (oscillator with random force). What we expecting from ItoProcess in this case? ...
Alex Trounev's user avatar
  • 45.8k
4 votes

How can I improve this code?

First, get rid of AppendTo and replace it with a preallocation of the array because you know the size in advance. Second, use ...
Domen's user avatar
  • 27.3k
4 votes
Accepted

Stochastic process: Understanding Ornstein Uhlenbeck Process

You have different x axes. For the correlation function the x axis is 0,1,2,... And for the Table you have 0,0.1,0.2,0.3,... (Note: f is not defined, I set it to f=0.1) If we change the x axis of the ...
Daniel Huber's user avatar
  • 53.1k

Only top scored, non community-wiki answers of a minimum length are eligible