Matlab
Here are some Matlab samples.
1) TWO MASSES CONNECTED BY A SPRING. 1D Dynamics. A force
is applied to the right mass.
A version of this was written in lecture on Friday
Sept 7, 2012.
Here is a quick version, approximately what was done in lecture. This is not good enough to show to others. But it shows that the code is not very comlex.
Here is a commented version with some explanation. Really it's no more complicated than the code above. The comments just make it look longer.
2) TWO MASSES CONNECTED BY A ROD
This set of DAEs was setup on the
blackboard in lecture on 9/10/2012
The key of this code is the use of backslash to solve for accelerations and constraints together.
3) CONTROLLING ODE ERRORS using abstol and reltol. Sample.
4) EVENTS. How to stop integrating when something happens rather than at some time.
The key is the 'events' option in ODESET. You turn it on with 'events' and give the name of the events function. The events function says when to stop. You calculate a value, integration stops when that value is zero. You can specify if you only want integration to stop if passing through zero is from above or below.
5) ANIMATION. A simple example showing a house rotating and displacing in time (See 2D rotations in Ruina/Pratap).
See also lecture notes on rotations (Sept 17 and 19).
6) DOUBLE PENDULUM zipped folder. (updated Dec 1, 2012, Correction on 12/3/04 "j=i:n" chnaged to "j=1:n" in doublependerrive2.m). The script files in it were described in lecture on Wed Oct 3. (). In it you will find:
doublependdriver.m run this to see what happens, it runs the other script files. Uncomment one of the animations.
doublependerive.m this uses symbolic algebra to derive the equations of motion.
It writes them into doublependrhs.m
In terms of core course material, doublependderive is most important.
doublependerive2.m Same as above, but using JACOBIAN to extract a mass matrix.
doublependrhs.m this is the rhs of the odes. It has huge equations in it. It is written by matlab!
doublependanimate1.m this is an animation using plot plot plot and plot again
doublependanimate1.m this is an animation using the plot and set commands ("handle graphics")
doublependanimate1.m this is an animation using the line and set commands ("handle graphics")
graphicstest.m A scratch file to use to play with line and set. Not related to files above.
7) SYMBOLIC LAGRANGE EQUATIONS. I have not tried this. But
I found it on the www. No guarantees. No help, even.
But, in principle, it should be a short cut. It has worked for some students
in this class.
8) NORMAL MODES. Simple 2-mass example, shown in lecture on Oct 19, 2012. This compares direct integration of the ODEs with solution using 'normal modes' found the primitive way (using M^(-1)).
9) NORMAL MODES. Simple 2-masses connected by a spring in
2D. example,
shown in lecture on Nov 2, 2012. This calculated normal modes of this 4 DoF
structure.
Only one has non-zero frequency. This is the idea that goes into the example
below.
10) VIBES OF A GENERAL 1D, 2D or 3D truss. This was partially demonstrated on Nov 2, 2012. You need to well understand the example above, first. For 2D trusses modes of vibration are animated.
11) Solution of prelim 2, problem 2. Just showing that the code posted in the solutions works.