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
7 votes
Accepted

Thermodynamics of the 2D Ising model

The energy can be calculated exactly as written in the formula using Sum and correct indices: ...
Domen's user avatar
  • 18.2k
5 votes

Colored plot with Wolfram Mathematica

The option Filling can color the space between plotted lines (see documentation). In your case, where lines do not intersect, it is easier to stack the plots inside ...
Themis's user avatar
  • 768
4 votes
Accepted

Simulating the Conduction of Heat on a Metal Rod

This is basic animation using Manipulate. This can be solved analytically by Mathematica. Once you obtain the analytical solution then Manipulate is used to replace $f(x),L,k$ by any other values ...
Nasser's user avatar
  • 135k
4 votes

Gross-Pitaevskii equation with NDSolve

You can run this with FEM, but it will take a bit of time: ...
user21's user avatar
  • 39.1k
3 votes
Accepted

Simulating a discrete time stochastic process

You can make use of RandomChoice and NestList. Since $\tau_{t+1}$ may depend not only on $\tau_t$ but also on $\tau_{t-1}$, I ...
Domen's user avatar
  • 18.2k
3 votes
Accepted

Need an equation for modeling Tytler's Cycle

The Logistic Equation is used as a model of population growth, but it may be useful for your simulation. This single equation can simulate dad as he ages and tires, and the decline in the third stage. ...
creidhne's user avatar
  • 4,613
2 votes

Simulating the card game War with $m$ suits and $n$ values

This isn't so much an answer as pedagogy. The main reason you can't get your commenceWarCardGame to work is because most of the code in that block isn't part of the ...
lericr's user avatar
  • 22.2k
2 votes

Solving Differential Equation System for HIV Treatment Model

Cesario's answer is almost there, but I'd like to add a couple points of correction/improvement. The problem formulation has constraints on the control (...
Eric Brown's user avatar
  • 4,366
1 vote
Accepted

Simulating the card game War with $m$ suits and $n$ values

Here is a link to some code I wrote to simulate the game. No guarantees. FWIW, it shows a tally of lengths of games for various shuffled decks. Some of these lead to games without ends. https://www....
James Stein's user avatar
1 vote

Evaluating an integral of geometric Brownian motion

You are not replacing P correctly because you are forgeting the "time" argument. Namely, ...
Domen's user avatar
  • 18.2k
1 vote

FEM Capacitor Not Converging with Parallel Plate Model

When modeling capacitors, there are a few things that need to be considered. First, one must decide whether to model the volume and the dielectric region or just the dielectric. By using the first ...
Bastian27's user avatar
  • 131
1 vote
Accepted

FEM Capacitor Not Converging with Parallel Plate Model

In the parallel plate capacitor one plate has a positive electric charge $+q$, and another plate has a negative electric charge $-q$, therefore the total electric charge is zero. To avoid this zero ...
Alex Trounev's user avatar
  • 41.1k
1 vote

Table generation with random variates inside. Mathematica

I would simply make your table explicit, like this: ...
lericr's user avatar
  • 22.2k
1 vote

Optimizing Code N-Body Simulation

Here is a simulation to get you going using the gravitation law without changes. I am using a very simple integration scheme, that fails if the bodies come too close. You may improve this if you like. ...
Daniel Huber's user avatar
  • 45.4k

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