This is the scrollytelling version of Tutorial 1: the same content, laid out as a pinned stage of figures, videos and live Python next to text cards that scroll past. Compare the two to decide which layout suits your material.
neuromatch academy
Tutorial 2: Linear dynamical systems¶
Week 2, Day 3: Linear Systems¶
Content Creators: Bing Wen Brunton, Alice Schwarze
Content Reviewers: Norma Kuhn, Karolina Stosio, John Butler, Matthew Krause, Ella Batty, Richard Gao, Michael Waskom
Production editors: Gagana B, Spiros Chavlis
In this tutorial, we will¶
Explore and understand the behavior of such systems where is a single variable
Consider cases where is a state vector representing two variables
Video 1: Linear Dynamical Systems
Video available at https://
Video available at https://
Video 2: Oscillatory Solutions
Video available at https://
Video available at https://
Video 3: Multi-Dimensional Dynamics
Video available at https://
Video available at https://
Summary
What we learned¶
How to simulate the trajectory of a dynamical system specified by a differential equation using a forward Euler integration scheme.
The behavior of a one-dimensional linear dynamical system is determined by , which may be a complex valued number. Knowing , we know about the stability and oscillatory dynamics of the system.
The dynamics of high-dimensional linear dynamical systems can be understood using the same intuitions, where we can summarize the behavior of the trajectories using the eigenvalues and eigenvectors of .
Tutorial objectives
Tutorial objectives¶
Estimated timing of tutorial: 1 hour
In this tutorial, we will be learning about behavior of dynamical systems -- systems that evolve in time -- where the rules by which they evolve in time are described precisely by a differential equation.
Differential equations express the rate of change of the state variable , written as the derivative :
Today, the focus is on linear dynamics, where is a linear function of .
Section 1
Section 1: One-dimensional differential equations¶
This video introduces dynamical systems as the mathematics of things that change in time, including timescales relevant for neuroscience. It covers the definition of a linear system and walks through solutions to one-dimensional, deterministic dynamical systems, their behaviors, and stability criteria.
This section is a recap of Tutorials 2 and 3 of the pre-course calculus day.
Simulation
Forward Euler integration¶
We can simulate an ODE by treating time as a list of steps with . From the definition of the derivative, the small change over is
So at each step we add that small change to the previous value:
This scheme, forward Euler integration, works well when is small and the equation is simple. It struggles with noisy dynamics or sudden big jumps in (as in models of excitable neurons). For our system it works just fine.
Coding Exercise 1
Implement forward Euler¶
Referred to as Exercise 1B in video
Complete integrate_exponential to compute the solution of with forward Euler integration, then run it to plot the solution over time.
If you skip ahead, the cells after this one use the reference solution, so they still work.
Result
Euler against the exact solution¶
With a small step, forward Euler sits on top of the exact solution . With bigger steps, it becomes choppy and drifts away from it.
Interactive Demo 1
Forward Euler integration¶
What happens when you change ? Try values where and .
is the step size of the forward Euler integration. Try and increase . What happens to the numerical solution when you increase ?
Section 2
Section 2: Oscillatory dynamics¶
Estimated timing to here from start of tutorial: 20 min
We will now explore what happens when is a complex number and has a non-zero imaginary component.
Interactive Demo 2
Oscillatory dynamics¶
Referred to as exercise 1B in video
Change the real and imaginary parts of (so = real + imaginary ).
What values of produce dynamics that both oscillate and grow?
What value of is needed to produce a stable oscillation of 0.5 Hertz (cycles/time units)?
Section 3
Section 3: Deterministic linear dynamics in two dimensions¶
Estimated timing to here from start of tutorial: 33 min
This video introduces two-dimensional, deterministic dynamical systems written as a vector-matrix equation. It covers stream plots and how to connect phase portraits with the eigenvalues and eigenvectors of the transition matrix A.
Recap
Two variables¶
Adding a second variable (or dimension) adds more variety of behaviors, for example in systems of several neurons. Two variables in isolation evolve as
To make things interesting, we add interaction terms and . The two equations then become one vector-valued linear ODE, where has two elements and is a matrix.
Coding Exercise 3
Sample trajectories in 2 dimensions¶
Referred to in video as step 1 and 2 of exercise 1C
We simulate trajectories of the system
and plot how and evolve in time. An integrator from scipy does the solving, and the helper plot_trajectory draws the result. Write the system function for a linear system with two variables.
Interactive Demo 3A
Varying A¶
Pick different options for . What kinds of qualitatively different dynamics do you observe?
Hint: Keep an eye on the x-axis and y-axis!
Interactive Demo 3B
Varying initial conditions¶
Now vary the initial conditions for a fixed :
What kinds of qualitatively different dynamics do you observe? Hint: Keep an eye on the x-axis and y-axis!
Section 4
Section 4: Stream plots¶
Estimated timing to here from start of tutorial: 45 min
Plotting trajectories one initial condition at a time is tedious. A stream plot shows how a whole grid of initial conditions evolves.
Think of an initial condition as a position in a space. At each position , a stream plot draws a small arrow for and connects the arrows into stream lines. Since , the stream line through shows .
Think! 4
Interpreting eigenvalues and eigenvectors¶
Here are the stream plots for each option of A from Demo 3A, with the eigenvectors of as a red line (1st eigenvalue) and a blue line (2nd eigenvalue).
What is special about the direction in which the principal eigenvector points? And how does the stability of the system relate to the corresponding eigenvalues? (Hint: from your introduction to linear algebra, for matrices with real eigenvalues, the eigenvectors are the lines on which is parallel to , and the eigenvalues are the factors by which is stretched or shrunk compared to .)