Skip to main content
42 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 ...
István Zachar's user avatar
39 votes
Accepted

Animating wave motion in water

...
Kuba's user avatar
  • 137k
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 ...
Martin Ender's user avatar
  • 8,774
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 ...
Henrik Schumacher's user avatar
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....
Picaud Vincent's user avatar
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....
chris's user avatar
  • 23.1k
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 ...
C. E.'s user avatar
  • 70.9k
25 votes

Bouncy Bubbles animation

data generates n balls, here: 10 Note that it might be wise to make the box larger, if ...
Feyre's user avatar
  • 8,617
24 votes
Accepted

Obtaining a 3D animation as a drop in a liquid surface

Thanks to J.M. ...
Kuba's user avatar
  • 137k
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 ...
Thies Heidecke's user avatar
21 votes

Gravitation simulation and interaction of N (1000) massive objects

And I was somewhat lying in wait for this kind of question... In I have been working on Barnes-Hut-like code for the so-called tangent-point energies in the last couple of years. This is a family of ...
Henrik Schumacher's user avatar
20 votes
Accepted

Multiple reflections of a laser beam in a triangle

Based on some geometric operations such as reflection and line-line intersection (LLI), I wrote up a small code. Hope this could be a starting point to build a more compact ...
Joo-Haeng Lee's user avatar
19 votes
Accepted

Efficiently Mowing Grass with Mathematica

This is just starting ideas for arbitrary regions. Perhaps you can improve it. Version 1 Define concave region with holes, which can be generalizable to arbitrary complexity: ...
Vitaliy Kaurov's user avatar
18 votes
Accepted

Writing compiled functions as fast as Python's Numba

Based on the experience obtained here: ...
xzczd's user avatar
  • 67.1k
16 votes
Accepted

How best to simulate n-body systems in a functional way?

In version 12.0 you can use NBodySimulation for that: ...
user21's user avatar
  • 40.1k
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: ...
chris's user avatar
  • 23.1k
14 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. ...
cvgmt's user avatar
  • 77.8k
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 ...
anderstood's user avatar
  • 14.4k
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 ...
Henrik Schumacher's user avatar
13 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 ...
C. E.'s user avatar
  • 70.9k
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: <...
user21's user avatar
  • 40.1k
12 votes

Modeling the spread of an infection in networked computers

Non CellularAutomaton solution, using @MartinEnder's suggestion of FixedPointList as opposed to ...
martin's user avatar
  • 8,778
12 votes

Multiple reflections of a laser beam in a triangle

Instead of thinking too hard, we can let NDSolve take care of it, using WhenEvent to handle the reflections. First, set up 3 ...
Chris K's user avatar
  • 20.3k
12 votes

Simulating molecular dynamics efficiently

To expand on @HenrikSchumacher's comment, compare: ...
Carl Woll's user avatar
  • 131k
11 votes

Brownian dynamics simulation

Things we can improve with small changes: You are recomputing a bunch of constants at each iteration, like (1./gm), ...
Marius Ladegård Meyer's user avatar
10 votes
Accepted

Mosteller's First Ace Problem

I would like to choose a slightly different approach here and point out, that this is an example for the Negative Hypergeometric Distribution. Wikipedia does give a nice table for this: While for ...
gwr's user avatar
  • 13.5k
10 votes

Time varying delay differential equations

As noted in my earlier comment, I am unaware of an existing Mathematica function that can solve the variable delay ODE in the question. Certainly, NDSolve objects, ...
bbgodfrey's user avatar
  • 61.8k
10 votes
Accepted

How to extract data points from two graphics and find the intersections between them?

Update 3: With a method based RegionIntersection we can have arbitrary regions instead of vertical lines and get the intersection points conveniently. For example, ...
kglr's user avatar
  • 399k
10 votes
Accepted

Two bouncing balls in 1 dimension, issues with two different methods?

Your first block of code never makes an approximation. Mathematica will do exact arithmetic when passed exact parameters. Your second block of code makes many approximations. By removing the ...
b3m2a1's user avatar
  • 47k
10 votes
Accepted

Schemes for nonlinear advection equation

First of all, if you just want to solve the equation, NDSolve is enough: ...
xzczd's user avatar
  • 67.1k

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