Attribute VB_Name = "Module2"
'********************************************************************
' DEMO: Lorenz and Roessler attractors *
'* ---------------------------------------------------------------- *
'* Until recently, the only known attractors were: the fixed point, *
'* the limit cycle and the torus. In 1963, Edwards Lorenz, a M.I.T. *
'* meteorologist, discovered a concrete example of a simple dynamic *
'* system presenting a complex behavior. To adapt them to the avail-*
'* able computers at that time, he began simplifying the equations *
'* of meteorology to finally obtain a numerical model composed of 3 *
'* differential equations with 3 unknowns, x, y, z, with 3 parame- *
'* ters, a, b and c: *
'* *
'* dx / dt = - a x + a y *
'* dy / dt = b x - y - x z *
'* dz / dt = -c z + x y *
'* *
'* During very long simulations on computer, Lorenz had the idea, *
'* to verify some results, to restart a calculation at mid course, *
'* to spare time. For that purpose, he injected into the machine the*
'* intermediate results obtained before. He had the great surprise *
'* that the new results were completely different! After suspecting *
'* some computer failure, Lorenz finally understood that the big *
'* differences between both solutions came from very small differen-*
'* ces in numerical data. These small initial perturbations were *
'* exponentially amplifying, by doubling every 4 days in simulated *
'* time, so after two months the results were totally different! *
'* *
'* Lorenz then realized that it would be very hard to make meteo- *
'* rological forecasts in the long range, the slightest change in *
'* starting conditions will give an atmosphere evolution radically *
'* different. That still occurs today even with much more sophisti- *
'* cated models of atmosphere. *
'* *
'* None of the three attractors known at that time could allow des- *
'* cribing the behaviour of such a dynamical system. Lorenz had just*
'* discovered a "strange and chaotic" attractor to which his name *
'* was given. *
'* *
'* The Roessler attractor is similar to the Lorenz one with another *
'* set of differential equations. *
'* *
'* Visual Basic Release By J-P Moreau. *
'* (www.jpmoreau.fr) *
'********************************************************************
'To be used with attract.frm and gr2d.bas
Public A, B, CC, x3, y3, z3 As Double
Public xx, yy, z As Double
Sub f()
Const delta = 0.005
Dim dx, dy, dz As Double
dx = -(y3 + z3)
dy = x3 + y3 * A
dz = B + z3 * (x3 - CC)
x3 = x3 + delta * dx
y3 = y3 + delta * dy
z3 = z3 + delta * dz
End Sub
Public Sub RunRoessler()
Form1.Cls
A = 0.2: B = 0.2: CC = 5.7
x3 = -10: y3 = -1: z3 = -1
flag = 0
Fenetre -10, 12, -15, 55
cloture 250, MaxX - 250, 250, MaxY - 250
Bordure
Display 500, 500, "ROESSLER ATTRACTOR"
Roessler (flag)
flag = 1
End Sub
Sub Roessler(flag%)
Dim i As Double
i = 0
f
If flag% = 0 Then
Do
f
i = i + 1#
Loop Until i > 1000
End If
MoveXY x3, y3 + z3 + z3
i = 0
Do
f
i = i + 1#
LineXY x3, y3 + z3 + z3
Loop Until i > 33000#
Beep
End Sub
Sub Lorentz()
f
MoveXY xx, z
n% = 0
Do
n% = n% + 1
f1
LineXY xx, z
Loop Until n% >= 5000
End Sub
Sub f1()
Const delta = 0.01
Dim dx, dy, dz As Double
dx = A * (yy - xx)
dy = xx * (B - z) - yy
dz = xx * yy - CC * z
xx = xx + delta * dx
yy = yy + delta * dy
z = z + delta * dz
End Sub
Public Sub RunLorentz()
'DEMO LORENTZ ATTRACTOR
' J-P Moreau
Form1.Cls
Display MaxX - 2500, MaxY - 750, "LORENTZ ATTRACTOR"
A = 10: B = 30: CC = 2.6666
xx = 1: yy = 1: z = 1
Fenetre -22, 25, -8, 60
cloture 250, MaxX - 250, 250, MaxY - 250
Bordure
Lorentz
Beep
End Sub