44
votes
Accepted
Random polyhedra walk
Usage
Just use this function with any polyhedron in in form:
GraphicsComplex[pts_, Polygon[vertices_, ___]].
When I find time and motivation maybe I will add ...

Kuba♦
- 135k
41
votes
Accepted
Gillespie Stochastic Simulation Algorithm
Yes you can. Below is a fairly general, Mathematica-compiled, fast and robust version.
Examples
1. Michaelis-Menten kinetics
Michaelis-Menten kinetics for enzyme-directed substrate conversion. The ...
38
votes
Accepted
37
votes
Accepted
Modeling the spread of an infection in networked computers
If it is at all an option to represent the grid as a 2D list instead of a list of infected coordinates, I would model this is a cellular automaton. What you've essentially got is an outer totalistic ...
33
votes
Accepted
Interstellar Image Effects
This was a fun question to answer, even considering that I know nothing about general relativity. It's all a matter of translating the equations presented in this paper by Oliver James, Eugenie von ...
32
votes
Accepted
Simulating molecular dynamics efficiently
Okay, here is a way to compute the forces much faster: We create a CompiledFunction (called getForces). It eats a list of points ...
31
votes
Accepted
Computational Bayesian analysis in Mathematica: Any plans to develop MCMC?
Update: 2/7/2019 I have just released a new version of the package: MathematicaStan v2.0
I just have released a beta version of MathematicaStan, a package to interact with CmdStan.
https://github....
28
votes
Computational Bayesian analysis in Mathematica: Any plans to develop MCMC?
For the sake of completeness let me advertise someone else's code which implements MCMC in mathematica.
Josh Burkart has implemented Mathematica Markov Chain Monte Carlo
which is available on github....
28
votes
Accepted
Bouncy Bubbles animation
This is my port of the Processing code that you referenced. It doesn't try to optimize, so I didn't try it either, for example I didn't use Nearest to find ...
26
votes
Accepted
How to define a distribution that 90% of the time gives me 0?
BernoulliDistribution is a perfect fit for this.
RandomVariate[BernoulliDistribution[1 - 0.1], {50}]
{1, 1, 1, 0, 1, 1, 0, ...
25
votes
Bouncy Bubbles animation
data generates n balls, here: 10
Note that it might be wise to make the box larger, if ...
24
votes
Accepted
Simulation of diffusion in a grid
You can use ListConvolve to simulate a single diffusion time step and build a simulation out of that. I'll show a simple example: Let's say we start with simple ...
23
votes
Accepted
18
votes
Accepted
Writing compiled functions as fast as Python's Numba
Based on the experience obtained here:
...
17
votes
Accepted
How to make a Cahn–Hilliard model GIF
I am delighted by this problem mostly because I was not aware of the underlying physical model of phase separation (the Cahn–Hilliard equation)!
Anyway, here is an approximation of a somewhat similar ...
16
votes
Accepted
How best to simulate n-body systems in a functional way?
In version 12.0 you can use NBodySimulation for that:
...
14
votes
Computational Bayesian analysis in Mathematica: Any plans to develop MCMC?
This answer gives explicitly a (parallel) MCMC implementation in mathematica following closely this Wolfram Demonstrations Project. This basically involves only a few lines:
...
14
votes
Partial Differential Equation in Parallel
The Finite Element solver in Mathematica does run in parallel, both element computation and the linear solve process are spread over the CPU cores available.
Additionally, the option "...
14
votes
How to make a Cahn–Hilliard model GIF
Taken from the Matlab code here http://www.math.utah.edu/~eyre/computing/matlab-intro/ch.txt with slight modifications:
...
14
votes
Accepted
Beam deformation due to localized force distribution
Here is an example with a force that pushes down between the stretch defined by 2<=x<=3 && y==1 and a fixation at the point ...
13
votes
Accepted
Simulating a "Coin Tossing" Game
Let's say that both players start with 10 dollars. We can represent the game state with a list:
start = {10, 10};
Create a function which plays one round of the ...
13
votes
Two bouncing balls in 1 dimension, issues with two different methods?
General comments on dealing with impacts Your are dealing with a low number of contact points (two). For low number of contact constraints (typically, <10), event driven methods are known to be ...
13
votes
Accepted
Efficiency in calculation on graphs: Compile?
The following should be 150 times faster. Too many micro changes to comment on all of them. Major speedup came from using Ordering to find ...
12
votes
Partial Differential Equation in Parallel
The open source Wolfram Research FEMAddOns package has a domain decomposition solver called DecompositionNDSolveValue. You can install the paclet with evaluating:
<...
12
votes
How to simulate the true reflective movement of a particle bouncing around in an ellipse?
@Kuba has provided an excellent solution. Here we follow his idea and use another approach like WhenEvent to get the particle tracing.
...
12
votes
Battery charge simulation not clipping properly as it iterates
Your code shows you are somewhat confused about the indices. Here is some code that is more Mathematica idiomatic and which makes keeping the indices straight much easier. I am running the simulation ...
12
votes
Modeling the spread of an infection in networked computers
Non CellularAutomaton solution, using @MartinEnder's suggestion of FixedPointList as opposed to ...
12
votes
Simulating molecular dynamics efficiently
To expand on @HenrikSchumacher's comment, compare:
...
12
votes
Animating wave motion in water
This is, as J.M. pointed out, a trochoidal wave. I'm going to provide an implementation based on this. This is slightly different compared to what Kuba did. The advantage is that this parametrization ...
11
votes
Accepted
How to model rolling a pair of dice 100 times (Monte Carlo)
In Mathematica it is natural to approach such a task with list operations and pattern matching.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
simulation × 268random × 50
differential-equations × 49
physics × 34
plotting × 27
probability-or-statistics × 26
performance-tuning × 18
animation × 17
list-manipulation × 12
programming × 12
finite-element-method × 12
numerical-integration × 11
equation-solving × 10
graphics × 10
modeling × 10
stochastic-calculus × 10
astronomy × 9
graphics3d × 8
manipulate × 8
distributions × 7
numerics × 6
control-systems × 6
functions × 5
code-request × 5
matrix × 4