10.4: Exercises
- Page ID
- 84739
Before you go on, you might want to work on the following exercise.
Based on the examples we’ve seen so far, you’d think that all ODEs describe population as a function of time, but that’s not true.
For example, the Lorenz system is a system of differential equations based on a model of fluid dynamics in the atmosphere (see https://greenteapress.com/matlab/lorenz). It turns out to be interesting in part because its solutions are chaotic; that is, small changes in the initial conditions yield big differences in the solutions.
The system is described by these differential equations: \[\begin{aligned} x_t &=& \sigma (y - x) \\ y_t &=& x (r - z) - y \\ z_t &=& xy - b z\end{aligned}\] Common values for the parameters are \(\sigma = 10\), \(b = 8/3\), and \(r=28\).
Use ode45
to estimate a solution to this system of equations.
- Create a file named lorenz.m with a top-level function named
lorenz
and a helper function namedrate_func
. - The rate function should take
t
andV
as input variables, where the components ofV
are understood to be the current values ofx
,y
, andz
. It should compute the corresponding derivatives and return them in a single column vector. - Test the function by calling it from the top-level function with values like \(t=0\), \(x=1\), \(y=2\), and \(z=3\). Once you get your function working, you should make it a silent function before calling
ode45
. - Use
ode45
to estimate the solution for the time span \([0, 30]\) with the initial condition \(x=1\), \(y=2\), and \(z=3\). - Plot the results as a time series, that is, each of the variables as a function of time.
- Use
plot3
to plot the trajectory of \(x\), \(y\), and \(z\).