Skip to Content

LORENZ

Overview

The LORENZ function numerically solves the classic Lorenz system of ordinary differential equations, a model for chaotic dynamics in atmospheric science and nonlinear systems. The Lorenz system describes the evolution of three variables (X, Y, Z) governed by three parameters: Prandtl number (sigma), Rayleigh number (rho), and a geometric factor (beta). The equations are:

dXdt=σ(YX)dYdt=X(ρZ)YdZdt=XYβZ\begin{align*} \frac{dX}{dt} &= \sigma (Y - X) \\ \frac{dY}{dt} &= X (\rho - Z) - Y \\ \frac{dZ}{dt} &= X Y - \beta Z \end{align*}

The function uses SciPy’s ODE solver (scipy.integrate.solve_ivp ) to integrate the system from t_start to t_end. Only the classic three-variable Lorenz system is exposed; extensions and external forcing are not supported. The integration method can be selected from several common solvers, but only the most used options are exposed. This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=LORENZ(x_initial, y_initial, z_initial, sigma, rho, beta, t_start, t_end, [timesteps], [solve_ivp_method])
  • x_initial (float, required): Initial value for X.
  • y_initial (float, required): Initial value for Y.
  • z_initial (float, required): Initial value for Z.
  • sigma (float, required): Prandtl number.
  • rho (float, required): Rayleigh number.
  • beta (float, required): Geometric factor.
  • t_start (float, required): Start time for integration.
  • t_end (float, required): End time for integration.
  • timesteps (int, optional, default=10): Number of timesteps to solve for.
  • solve_ivp_method (string (enum), optional, default=‘RK45’): Integration method. Valid options: RK45, RK23, DOP853, Radau, BDF, LSODA.

The function returns a 2D array (table) with columns: t, X, Y, Z, representing time and the three variables at each step. If the input is invalid or integration fails, a string error message is returned.

Examples

Example 1: Classic Lorenz, Default Method

Inputs:

x_initialy_initialz_initialsigmarhobetat_startt_endtimesteps
1.01.01.010.028.02.6670.02.010

Excel formula:

=LORENZ(1.0, 1.0, 1.0, 10.0, 28.0, 2.667, 0.0, 2.0, 10)

Expected output:

tXYZ
0.01.01.01.0
0.2228.31617.136.414
0.4448.48-7.11739.99
0.667-6.458-8.34525.27
0.889-9.589-10.2327.69
1.111-7.985-6.74427.98
1.333-7.666-8.67624.54
1.556-9.831-9.72628.8
1.778-7.42-6.50926.95
2.0-8.168-9.51824.67

Example 2: Classic Lorenz, RK23 Method

Inputs:

x_initialy_initialz_initialsigmarhobetat_startt_endtimestepssolve_ivp_method
1.01.01.010.028.02.6670.02.010RK23

Excel formula:

=LORENZ(1.0, 1.0, 1.0, 10.0, 28.0, 2.667, 0.0, 2.0, 10, "RK23")

Expected output:

tXYZ
0.01.01.01.0
0.2228.30817.116.397
0.4448.413-7.00239.78
0.667-6.407-8.3225.05
0.889-9.69-10.3127.81
1.111-7.897-6.64427.91
1.333-7.694-8.75924.48
1.556-9.823-9.62628.91
1.778-7.373-6.5526.78
2.0-8.29-9.63624.85

Example 3: Short Time Span

Inputs:

x_initialy_initialz_initialsigmarhobetat_startt_endtimesteps
0.01.02.010.028.02.6670.00.110

Excel formula:

=LORENZ(0.0, 1.0, 2.0, 10.0, 28.0, 2.667, 0.0, 0.1, 10)

Expected output:

tXYZ
0.00.01.02.0
0.0110.1051.0041.942
0.0220.2011.0381.887
0.0330.2921.0971.835
0.0440.3811.1831.786
0.0560.4711.2931.739
0.0670.5651.4291.696
0.0780.6641.5921.657
0.0890.7721.7841.622
0.10.892.0061.592

Example 4: Different Parameters

Inputs:

x_initialy_initialz_initialsigmarhobetat_startt_endtimesteps
2.03.04.014.035.03.00.01.010

Excel formula:

=LORENZ(2.0, 3.0, 4.0, 14.0, 35.0, 3.0, 0.0, 1.0, 10)

Expected output:

tXYZ
0.02.03.04.0
0.1118.11316.096.988
0.22224.1726.3750.63
0.3333.532-10.1945.24
0.444-6.605-8.59335.25
0.556-8.298-9.28131.51
0.667-10.36-11.8831.98
0.778-11.82-11.7536.03
0.889-10.16-8.51936.45
1.0-8.303-7.88132.76

Python Code

import micropip await micropip.install(['scipy', 'numpy']) from scipy.integrate import solve_ivp import numpy as np def lorenz(x_initial, y_initial, z_initial, sigma, rho, beta, t_start, t_end, timesteps=10, solve_ivp_method='RK45'): """ Numerically solves the Lorenz system of ordinary differential equations for chaotic dynamics. Args: x_initial: Initial x value. y_initial: Initial y value. z_initial: Initial z value. sigma: Prandtl number. rho: Rayleigh number. beta: Geometric factor. t_start: Start time of integration. t_end: End time of integration. timesteps: Number of timesteps to solve for. Default is 10. solve_ivp_method: Integration method ('RK45', 'RK23', 'DOP853', 'Radau', 'BDF', 'LSODA'). Default is 'RK45'. Returns: 2D list with header row: t, X, Y, Z. Each row contains time and variable values, or an error message (str) if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate input types and ranges try: x0 = float(x_initial) y0 = float(y_initial) z0 = float(z_initial) sig = float(sigma) rh = float(rho) bet = float(beta) t0 = float(t_start) t1 = float(t_end) ntp = int(timesteps) except Exception: return "Invalid input: All initial values, parameters, and timesteps must be numbers." if t1 <= t0: return "Invalid input: t_end must be greater than t_start." if ntp <= 0: return "Invalid input: timesteps must be a positive integer." if solve_ivp_method not in ['RK45', 'RK23', 'DOP853', 'Radau', 'BDF', 'LSODA']: return "Invalid input: solve_ivp_method must be one of 'RK45', 'RK23', 'DOP853', 'Radau', 'BDF', 'LSODA'." # Create time array for evaluation t_eval = np.linspace(t0, t1, ntp) # Lorenz system definition def lorenz_ode(t, xyz): x, y, z = xyz dxdt = sig * (y - x) dydt = x * (rh - z) - y dzdt = x * y - bet * z return [dxdt, dydt, dzdt] # Integrate ODE try: sol = solve_ivp( lorenz_ode, [t0, t1], [x0, y0, z0], method=solve_ivp_method, dense_output=False, t_eval=t_eval ) except Exception as e: return f"Integration error: {e}" if not sol.success: return f"Integration failed: {sol.message}" # Format output: header row then data rows result = [['t', 'X', 'Y', 'Z']] for i in range(len(sol.t)): t_val = float(sol.t[i]) x_val = float(sol.y[0][i]) y_val = float(sol.y[1][i]) z_val = float(sol.y[2][i]) # Disallow nan/inf if any([ not isinstance(t_val, float) or not isinstance(x_val, float) or not isinstance(y_val, float) or not isinstance(z_val, float), t_val != t_val or x_val != x_val or y_val != y_val or z_val != z_val, # NaN check abs(t_val) == float('inf') or abs(x_val) == float('inf') or abs(y_val) == float('inf') or abs(z_val) == float('inf') ]): return "Invalid output: nan or inf detected." result.append([t_val, x_val, y_val, z_val]) return result

Example Workbook

Link to Workbook 

Last updated on