-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlorenz.bas
More file actions
52 lines (43 loc) · 1.45 KB
/
lorenz.bas
File metadata and controls
52 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
' Lorenz System
Option _Explicit
Dim Shared As Double x, y, z, sigma, rho, beta, h
Dim As Integer x_scr, y_scr, co
Dim As Double x_low, x_high, y_low, y_high, z_low, z_high
Dim title As String
Dim As Long N, k
Const XMAX = 1300, YMAX = 900 ' image dimensions
title = "Lorenz System"
Screen _NewImage(XMAX, YMAX, 32): _Title title
Cls
sigma = 10 ' parameters Lorenz system
beta = 8 / 3
rho = 28
x = 1.0: y = 1.0: z = 0.0 'initial cond.
h = 0.005 ' time step for euler method
N = 40000 ' number of steps
x_low = -22: x_high = 22 ' viewing window
y_low = -20: y_high = 20
z_low = -1: z_high = 53
For k = 0 To N - 1 ' main loop for drawing
euler_lorenz
x_scr = XMAX * norm(x, x_low, x_high)
y_scr = YMAX * (1 - norm(z, z_low, z_high))
co = 255 * norm(y, y_low, y_high) ' variable y is used for color
If k = 0 Then
PSet (x_scr, y_scr)
End If
Line -(x_scr, y_scr), _RGB(255 - co, Abs(co - 127) * 2, co)
Next k
Sleep
Sub euler_lorenz ' calculate next x,y,z values using Euler method
Dim As Double dx_dt, dy_dt, dz_dt
dx_dt = sigma * (y - x) ' lorenz system with three 1st order diff. eq.
dy_dt = x * (rho - z) - y
dz_dt = x * y - beta * z
x = x + dx_dt * h ' Euler method
y = y + dy_dt * h
z = z + dz_dt * h
End Sub
Function norm (v As Double, v_low As Double, v_high As Double) ' map value v in 0..1 interval
norm = (v - v_low) / (v_high - v_low)
End Function