Biocybernetics lab
Polly Vacher 184 on Mon 08-11-2021
Use matlab to draw some Lissajou curves. These are parametric equations of the form
\[ x_1=A_1\sin(\omega_1 t-\delta_1) \]\[ x_2=A_2\sin(\omega_2 t-\delta_2) \]set up t to be a vector
>> t=0:.05:50;
Choose some values for $A$, $\omega$ and $\delta$ and plot. You might as well set $A_1=1$, $\omega_1=1$ and $\delta_1=0$. Decide if you would like to use radians in which case
>> plot(sin(t),A2*sin(omega2*t+delta2))
or degrees
>> plot(sind(t),A2*sind(omega2*t+delta2))
You can also try a three dimensional Lissanjou curve so that
>> plot3(sin(t),A2*sin(omega2*t+delta2),A3*sin(omega3*t+delta3))
Use matlab to plot out some first order systems. Try positive and negative values for alpha
>> t=0:.1:10;
>> alpha=choose a value (positive and/or negative)
>> y=exp(alpha*t);
>> plot(t,exp(alpha*t))
use
>> hold on
to plot multiple values then free the plot with
>> hold off
Do a numerical integration of the equation
\[ \dot{y}=\alpha y \]>> mystatespacefn=@(t,x) alpha*x;
>> [tp,yp]=ode45(mystatespacefn,[0 10],1.1);
>> plot(tp,yp,t,y)
ode45
and mystatespacefun
are doingsemilog
functionWith alpha set to a negative value, plot out the function
\[ y=(1-e^{ \alpha t }) \]More on numerical integration.
The equation for a simple pendulum with damping is
\[ 0=ml\ddot\theta+mg\sin\theta+B\dot\theta \]where $m$ is the mass of the bob, $\theta$ is the angle between the gravity vector $g$ and the pendulum and $B$ is a linear term to represent friction and damping. The equation arises by summing all the forces that are applied to the bob.
To integrate the equation we need to first rewrite it with the highest differential as the dependent variable.
\begin{equation} \ddot\theta=-\frac{g}{l}\sin\theta-\frac{B}{ml}\dot\theta \end{equation}To simplify things further we will set $\frac{g}{l}=1$, and write the equation in a statespace form, that is let
\begin{align*} x_1=\theta\\ x_2=\dot\theta \end{align*}which means that
\begin{align*} \dot{x}_1=\dot\theta\\ \dot{x}_2=\ddot\theta \end{align*}so we can write equation 1 in statespace form as
\[ \begin{bmatrix} \dot{x}_1\\ \dot{x}_2 \end{bmatrix} = \begin{bmatrix} x_2\\ -\sin(x_1)-\frac{B}{ml}x_2 \end{bmatrix} \]>> Bom=.02;
>> mypendulumfn=@(t,x) [x(2);-sin(x(1))-Bom*x(2)];
>> [t,y]=ode45(mypendulumfn,[0 30],[icForTheta;icForThetadot]);
Put some values in for the initial conditions icFortheta;icForThetadot
. See what plots you can make. Does the data make sense?
Command | typical use | |
---|---|---|
help | help command | an alternative to google to find out about matlab commands |
diary | diary file/off | keeps a log. Useful to review what you did. |
edit | edit filename | Try out live scripts (New/Live Script) |
publish | A good way to keep track of files e.g. publish('myfile','pdf'). Look for your output in the html directory | |
atan2 | ||
eig | ||
exp | ||
figure | figure(number) | |
hold | hold off | hold on
fix a figure so future plot commands do not start a new graph. |
mesh | mesh(X,Y,Z) | |
ode45 | ||
plot | ||
plot3 | ||
shg | ||
sin/sind/cos/cosd | ||
sqrt | ||
log/log10 |