Here are some Matlab samples.
1) TWO MASSES CONNECTED BY A SPRING. 1D Dynamics. A force is applied to the right mass.
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 is a set of DAEs.
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).
6) DOUBLE PENDULUM zipped folder. 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. A better version, using Jacobian will be posted.
8) NORMAL MODES. Simple 2-mass example. 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. 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. HERE. You need to well understand the example above, first. For 2D trusses modes of vibration are animated.
11) Solution of prelim 2, problem 2, fall 2013. Just showing that the code posted in the solutions works.