Phase Space Portrait — Nonlinear Dynamics & Chaos Visualizer
Integrate harmonic, damped, Van der Pol, Duffing, and Lorenz systems using RK4. Explore attractors, limit cycles, and chaos — click the canvas to launch trajectories from any initial condition.
How to use
• Click canvas → start trajectory from that point
• Multiple trajectories shown simultaneously
• Adjust parameters to change system behavior
Equations
Trajectories: 0
Integrator: RK4 / dt = 0.01
Visualization
x: 0 y: 0
Theory & Key Formulas
$$\ddot{x} + 2\zeta\omega_n\dot{x} + \omega_n^2 x = F_0\cos(\omega t)$$
The state of a dynamical system is completely determined by its position $x$ and velocity $\dot{x}$. The plane with these as coordinate axes is called phase space, and the time evolution of the system traces out a curve (trajectory) in this space.
Systems and Their Signatures
1. Simple Harmonic Oscillator
$$\dot{x}=y,\quad \dot{y}=-\omega^2 x$$
Energy-conserving system. Phase portrait shows closed ellipses — nested concentric orbits that never cross. The ellipse shape encodes the amplitude and frequency of oscillation.
2. Damped Oscillator
$$\dot{x}=y,\quad \dot{y}=-2\gamma y - \omega^2 x$$
Energy-dissipating system. Trajectories spiral inward toward the origin (stable fixed-point attractor). With $\gamma < \omega$: underdamped spiral; with $\gamma > \omega$: overdamped node.
3. Van der Pol Oscillator
$$\dot{x}=y,\quad \dot{y}=\mu(1-x^2)y - x$$
For $|x|<1$: negative damping (energy pumped in); for $|x|>1$: positive damping (energy removed). All trajectories converge to a stable limit cycle. Models vacuum tube oscillators and cardiac rhythms.
4. Duffing Oscillator (Forced)
$$\dot{x}=y,\quad \dot{y}=-\delta y - \alpha x - \beta x^3 + \gamma\cos(\omega t)$$
Nonlinear spring with periodic forcing. At suitable parameters produces a strange attractor and deterministic chaos. Launch two nearby trajectories to observe exponential divergence (butterfly effect).
Simplified atmospheric convection model. The 3D trajectory is projected onto the x-z plane, revealing the iconic "butterfly" strange attractor. The classic demonstration of deterministic chaos.
Q & A
Student: How is a phase portrait different from a regular time-series plot?
Professor: In a time-series plot you see position versus time — a sine wave for the harmonic oscillator. In phase space, time is eliminated and you plot velocity against position. What you gain is a clear view of the system's qualitative structure: closed orbits mean periodicity, spirals mean decay, and complicated tangles mean chaos. A single glance at the phase portrait tells you more about the system's long-term behavior than pages of time-series data.
Student: So a closed ellipse in phase space always means the motion is periodic?
Professor: Exactly. The Poincare-Bendixson theorem tells us that in 2D phase space, if a trajectory stays bounded and doesn't approach a fixed point, it must approach a closed curve. That's why chaos is impossible in 2D autonomous systems — you need at least 3D (like Lorenz) or an explicit time-dependence (like Duffing with forcing) to get chaotic trajectories.
Student: Why does the Van der Pol limit cycle attract trajectories from both inside and outside?
Professor: The key is the $\mu(1-x^2)y$ term. When $|x|<1$, the factor $(1-x^2)$ is positive, so this term acts like \lt strong style="color:#7dd3fc"\gt negative damping — it injects energy and trajectories spiral outward. When $|x|>1$, the factor becomes negative, giving positive damping — trajectories spiral inward. The limit cycle is the unique closed orbit where these two effects exactly balance. It's a self-sustaining oscillation that doesn't need external forcing.
Student: Is that really how heartbeats work?
Professor: It's a useful model. The cardiac pacemaker cells fire autonomously at a steady rhythm, and if you perturb them slightly, they return to that rhythm — just like a limit cycle attractor. Try cranking up $\mu$ in the simulator. The waveform becomes sharper and more sawtooth-like, resembling a relaxation oscillation. Real ECG signals have a similar character during arrhythmia analysis.
Student: Is chaos the same as randomness? They both seem unpredictable.
Professor: This is a crucial distinction. Chaos is deterministic — the equations are completely fixed, and given identical initial conditions you get identical trajectories every time. The unpredictability comes solely from sensitivity to initial conditions: a tiny difference in starting point grows exponentially. Randomness, on the other hand, is intrinsic — even with perfect knowledge of initial conditions you can't predict the outcome. Weather forecasting fails beyond ~2 weeks not because the atmosphere is random, but because it's chaotic.
What is a Phase Space Portrait?
🙋
What exactly is a "phase space portrait"? I've heard it's used to study chaos, but it just looks like a swirling 3D graph.
🎓
Basically, it's a map of all possible states of a dynamical system. Instead of plotting position vs. time, we plot variables against each other. For instance, in the Lorenz system here, it plots $x$ (convection intensity), $y$ (temperature difference), and $z$ (vertical temperature gradient). Try selecting "Lorenz" from the Select System dropdown above. The famous "butterfly" shape you see is a strange attractor—the system's state forever loops around it, never repeating.
🙋
Wait, really? So that shape is where the system is "attracted" to? What about the simpler wavy lines I see when I pick "Harmonic Oscillator"?
🎓
Exactly! That's a key difference. For the harmonic oscillator, the phase portrait is a perfect ellipse—a limit cycle. That means for a given energy, the motion is perfectly periodic. Now, try changing the Parameters like damping ($\gamma$) in the "Damped Oscillator" system. See how the ellipse spirals into a point? That point is a fixed point attractor, showing the system coming to rest.
🙋
So chaos happens when the attractor isn't a simple point or loop, but this infinitely complex "strange" shape? How do the equations make that happen?
🎓
You've got it. Chaos arises from nonlinear terms in the equations that cause exponential sensitivity to initial conditions—the "butterfly effect." In the Lorenz equations, terms like $xz$ and $xy$ are the culprits. Play with the $\rho$ parameter (try setting it to 14, then 28). You'll see the system's behavior bifurcate from steady loops to chaotic wings. The simulator uses an RK4 integrator to solve these equations step-by-step, tracing out the trajectory you see.
Physical Model & Key Equations
The core of the simulator is solving a set of first-order ordinary differential equations (ODEs) that define the system's dynamics. The general form for each system is:
$$ \dot{\mathbf{x}}= f(\mathbf{x}, t) $$
where $\mathbf{x}$ is the state vector (e.g., $[x, y, z]$) and $\dot{\mathbf{x}}$ is its time derivative. The function $f$ contains the specific physics of the chosen model.
For example, the famous Lorenz system (modeling atmospheric convection) is defined by three coupled, nonlinear ODEs:
$$ \begin{align*}\dot{x}&= \sigma (y - x) \\
\dot{y}&= x (\rho - z) - y \\
\dot{z}&= xy - \beta z
\end{align*} $$
Here, $x$ is convection intensity, $y$ horizontal temperature variation, $z$ vertical temperature variation. The parameters $\sigma$ (Prandtl number), $\rho$ (Rayleigh number), and $\beta$ are constants. The nonlinear terms $xz$ and $xy$ are the source of the chaotic behavior.
Frequently Asked Questions
You can set initial conditions by clicking on the (x, y) coordinates on the screen or by entering values directly in the input fields. Trajectories starting from different initial conditions may converge to different attractors or limit cycles even with the same parameters. In chaotic systems, tiny differences in initial conditions can lead to significantly different trajectories, so trying multiple points helps understand the system's behavior.
You can adjust the time step Δt using the 'Step Size' slider at the bottom of the screen. Smaller values improve calculation accuracy but slow down rendering. Conversely, larger values speed up rendering but may cause trajectory instability due to numerical errors. A practical standard setting is around 0.01 to 0.05.
A limit cycle is a closed periodic orbit where the trajectory repeats the same loop over time. In contrast, chaos exhibits non-periodic patterns where the trajectory never closes and folds in a complex manner. In the Lorenz system, you can observe irregular transitions between two lobes resembling butterfly wings.
The parameters may be in a divergent region. First, use the 'Reset' button to return to the initial state, then gradually increase the damping coefficient or external force amplitude from smaller values (e.g., γ=0.1, F=0.5). Additionally, using the zoom and pan functions to view the entire trajectory can be helpful.
Real-World Applications
Climate & Weather Modeling: The Lorenz system was originally derived from a simplified model of atmospheric convection. It demonstrates why long-term weather prediction is fundamentally limited—tiny errors in initial conditions grow exponentially, a hallmark of chaos studied with tools like this simulator.
Engineering Vibration Control: The Duffing oscillator (a nonlinear spring) models structures like aircraft wings or building frames that experience large deflections. Engineers use phase portraits to identify dangerous resonance conditions and chaotic vibrations that could lead to failure.
Electrical Circuit Design: The Van der Pol oscillator originally modeled circuits with vacuum tubes. Today, it's used to design and analyze oscillators in radios and pacemakers, where understanding the stability of limit cycles is critical for reliable operation.
Biological Rhythms: Nonlinear dynamics models the firing of neurons, the beating of a heart, and population cycles in ecology. Phase space analysis helps determine if a system will settle into a steady rhythm (limit cycle) or exhibit erratic, potentially pathological behavior.
Common Misunderstandings and Points to Note
When you start using this tool, there are a few common pitfalls. First is the case where "the trajectories look the same even when you change the initial conditions". For example, try turning off the forced oscillation and setting damping to zero for the "Duffing oscillator". Even if you change the initial conditions, all trajectories will lie on the same closed curve. This is because it's a conservative system. Since energy is conserved, the system keeps orbiting along a curve of constant energy (like a contour line), determined by the initial "push". The trajectories aren't overlapping; independent trajectories with different energies are drawing separate closed curves. If you add a little "damping" in the parameter settings, you can observe how these trajectories converge in a spiral pattern, so give it a try.
Next is over-reliance on numerical calculation accuracy. While this tool uses a high-precision method called RK4, especially in chaotic systems (like the Lorenz system), even tiny computational errors can be amplified explosively over time (that's the butterfly effect). Therefore, don't consider the detailed trajectories from long-term simulations as "absolute truth". In practice, it's fundamental to use it for observing qualitative behaviors like the "shape" of an attractor or its "properties" (whether it's stable or unstable).
Finally, there's "binge-changing" parameters. If you change a parameter drastically all at once, the system's behavior can change completely, often leaving you wondering "what just happened?". For instance, if you change the nonlinearity parameter $\mu$ for the van der Pol oscillator from 0.1 to 5.0 in one go, the shape changes dramatically. To understand the change, the trick is to change it little by little—0.1, 0.5, 1.0, 2.0…—and track how the limit cycle deforms continuously. This lets you get a feel for the "physical meaning of the parameter".
Select a dynamical system (Lorenz, Duffing, or Van der Pol) from the dropdown menu.
Adjust initial conditions (x₀, y₀, z₀) and system parameters (σ, ρ, β for Lorenz; α, β, γ for Duffing; μ for Van der Pol) using the parameter sliders.
Enable the vector field toggle (showField) to visualize flow direction, then run the integrator to trace phase space trajectories using fourth-order Runge-Kutta (RK4) with adaptive timestep.
Observe attractor geometry, limit cycles, and bifurcation behavior as parameters cross critical thresholds.
Worked Example
For the Lorenz system with σ=10, ρ=28, β=8/3: starting from (x₀=1, y₀=1, z₀=1), the RK4 integrator (dt=0.01s, 10,000 steps) converges to the famous butterfly attractor with fractal dimension ~2.06. At ρ=24.74, the system exhibits a period-doubling cascade; at ρ=28, fully chaotic motion dominates with Lyapunov exponent λ≈0.906 bits/s. The Duffing oscillator (α=1, β=1, γ=0.3, ω=1.2) shows period-1 limit cycles at low forcing amplitudes, transitioning to chaos around γ≈0.4 with basin-of-attraction boundary fractality.
Practical Notes
Lorenz chaos requires ρ>24.74; below this, trajectories collapse to stable fixed points. Use ρ=28-35 for clear butterfly topology.
Van der Pol (μ=5) produces relaxation oscillations with sharp corner structure; increase μ to 20+ for pronounced nonlinear stiffness effects.
Duffing bistability occurs when α and β have opposite signs (e.g., α=-1, β=1); drive frequency ω near 1 Hz with γ>0.3 triggers homoclinic bifurcations.
Enable vector field rendering for visual confirmation of saddle-node connections and heteroclinic orbits near bifurcation points.