LORENZ_SIMULATION is a MATLAB program which computes and displays solutions to the Lorenz equations for various initial conditions.
The Lorenz equations are an extremely simplified model of the weather, in which three differential equations describe the evolution of three variables. There are also three parameters whose values play the role of physical constants.
It was while studying these equations that Edward Lorenz discovered what he called "deterministic chaos". That is, at least for certain values of the parameters, solutions were extremely sensitive to the initial conditions.
The Lorenz equations are often written as
x' = sigma * ( y - x ) y' = x * ( rho - z ) - y z' = x * y - beta * zwhere the parameters are positive. Typical values for the parameters are
sigma = 10 beta = 8 / 3 = 2.666... rho = 28The value of rho has a strong influence on the behavior of solutions. The value rho=28 results in chaotic solutions, whereas rho=99.96 yields a regular pattern.
The LORENZ_SIMULATION program shows a 3D plot of the behavior of a solution to the Lorenz equations. The initial condition is varied randomly each time the user runs the program.
There is actually already a Lorenz demonstration program, called lorenzdemo, which is part of the MATLAB demo set.
We modified the original program because we wanted to be able to vary the initial condition for the integration. This turned out to be far more difficult than we realized, since the lorenzdemo program is full of code that looks important, but actually is not used.
The key is that the lorenzdemo displays some buttons, and as soon as you push a button, it calls "lorenz", which is a built in MATLAB function. This function is probably the same as lorenzdemo. However, if you change lorenzdemo, you have not changed "lorenz"! In other words, you can make all the changes you want to lorenzdemo, but most of them will have no effect whatsoever, since lorenzdemo actually calls "lorenz".
It is inadvertently cryptic coding like this that fills the wards of our hospitals with bitter, disillusioned people who have lost all faith in their ability to understand programming.
This version, with the slightly altered name "lorenz_simulation", calls itself. Thus, if you change this code, you will see a change when you run it. For our purposes, we were able to change the initial condition Y0, and have that effect the calculation as we wanted.
Note, also, that the ordering of the variables is somewhat different than is to be seen in other contexts. For LORENZ_SIMULATION, the equations are
x' = y * z - beta * x y' = sigma * ( z - y ) z' = y * ( rho - x ) - z
lorenz_simulationruns the program, picking an initial condition at random.
BROWNIAN_MOTION_SIMULATION, a MATLAB program which simulates Brownian motion in an M-dimensional region.
DICE_SIMULATION, a MATLAB program which simulates N tosses of M dice, making a histogram of the results.
DUEL_SIMULATION, a MATLAB program which simulates N repetitions of a duel between two players, each of whom has a known firing accuracy.
FOREST_FIRE_SIMULATION, a C program which simulates the occurrence of fires and regrowth in a forest, displaying the results using X Windows, by Michael Creutz.
GAMBLERS_RUIN_SIMULATION, a MATLAB program which simulates the game of gambler's ruin.
HIGH_CARD_SIMULATION, a MATLAB program which simulates a situation in which you see the cards in a deck one by one, and must select the one you think is the highest and stop.
ISING_2D_SIMULATION, a MATLAB program which carries out a Monte Carlo simulation of an Ising model, a 2D array of positive and negative charges, each of which is likely to "flip" to be in agreement with neighbors.
LORENZ_EQUATIONS, a MATHEMATICA file which demonstrates how solutions to the Lorenz equations can be synchronized.
POISSON_SIMULATION, a MATLAB library which simulates a Poisson process in which events randomly occur with an average waiting time of Lambda.
RANDOM_WALK_1D_SIMULATION, a MATLAB program which simulates a random walk in a 1-dimensional region.
RANDOM_WALK_2D_AVOID_SIMULATION, a MATLAB program which simulates a self-avoiding random walk in a 2-dimensional region.
RANDOM_WALK_2D_SIMULATION, a MATLAB program which simulates a random walk in a 2-dimensional region.
RANDOM_WALK_3D_SIMULATION, a MATLAB program which simulates a random walk in a 3-dimensional region.
REACTOR_SIMULATION, a FORTRAN90 program which is a simple Monte Carlo simulation of the shielding effect of a slab of a certain thickness in front of a neutron source. This program was provided as an example with the book "Numerical Methods and Software."
SIR_SIMULATION, a MATLAB program which simulates the spread of a disease through a hospital room of M by N beds, using the SIR (Susceptible/Infected/Recovered) model.
THREE_BODY_SIMULATION, a MATLAB program which simulates the behavior of three planets, constrained to lie in a plane, and moving under the influence of gravity, by Walter Gander and Jiri Hrebicek.
TRAFFIC_SIMULATION, a MATLAB program which simulates the cars waiting to get through a traffic light.
TRUEL_SIMULATION, a MATLAB program which simulates N repetitions of a duel between three players, each of whom has a known firing accuracy.
You can go up one level to the MATLAB source codes.