One of the readers who attended the introductory Simulink webinar:
http://www.mathworks.com/company/events/webinars/wbnr37271.html
asked me how to implement differential equations in Simulink and visualize the results in a MATLAB plot. This demo attempts to answer those kinds of questions.
Notes on this submission:
1. The approach is to represent the equations using Simulink blocks and then use MATLAB graphics to plot the results. The advantage of using the graphical approach is with the ability to customize the solver configurations and step through the solution in time.
2. The design pattern shows a two stage model in which the integrator plays the role of integrating the ODE. The terms are collected and fed into this integrator.
3. As mentioned in the webinar, we use vector processing capabilities of the integrator to process the three terms simultaneously.
4. The concept of feedback is important as the solver solves for the next step in the simulation based on its current states.
5. We use MATLAB SFunctions to incorporate visualization code for the MATLAB GUI. Also, observe that we move the camera around so that you get a good visual of how the 3D curve looks like. There is also a model that uses a Level1 Sfunction for those who may be interested in it for legacy reasons.
6. Look into the MATLAB SFunction code as to how a red marker that acts like a tracer is created.
7. The SFunction block was modeled as a discrete block with a sampling time so that a high fidelity plot could be obtained(at the cost of performance). There is a performance tradeoff that you should look out for when visualizing results.
8. Look into the code for the various SFunctions and read the comments to understand how the code is structured.
9. Notes on the Lorenz Attractor:
The study of strange attractors began with the publication by E. N. Lorenz "Deterministic nonperiodic flow"(Journal of Atmospheric Science, 20:130141, 1963). In the process of investigating meteorological models, Edward Lorenz found that very small truncation or rounding errors in his algorithms produced large changes in the resulting predictions. This led to the study of "strange" or chaotic attractors.
One crude way to visualize attractors is a set such that if during the evolution of the dynamics of the system, one of the states hits a point in that set, it will continue to remain in that set. From a simulation point of view, it is interesting to see the existence of such sets for certain nonlinear dynamical systems. If this attractor is chaotic meaning it has sensitive dependence on initial conditions, then it is called a strange attractor.
It was particularly an interesting result which he observed that for parameter values sigma=10, beta=8/3, and rho=28, the solutions start revolving about two repelling equilibirum points at (sqrt(72), sqrt(72.27).
The number of times the solution revolves around one equilibirum point before switching to the other has no discernible pattern. More information on this can be obtained in a standard introductory nonlinear systems text.
10. Questions to ponder about:
a. How would you project this 3D trajectory onto a arbitrary plane surface and visualize it during the simulation? Would the trajectory intersect itself?
b. How would you visualize the Poincare map?
c. How would you compute the number of turns the red marker makes around the equilibrium point before switching to the other? Could this number be used to generate random numbers?
