## Lab 2 The linear spring

The linear spring is an example of a simple mechainical device that can be analyzed using the methods that we have developed for linear nth order differential equations. Consider the picture shown below:

Here m is the mass of the weight, L0 is the resting length of the spring and x is the position of the spring. A linear spring exerts a force that is proportional to the difference between the resting length and the distance the spring is pulled. The constant of proportionality is called the spring constant. If the spring is stretched so that it is longer than the rest length, the force is negative and pulls the mass back while if the spring is compressed, it pushes it out. There is also frictional force which is proportional to the velocity. Using Newton's laws of motion:

#### m x'' = - k(x-L0)-fm x'

This says that " mass time acceleration equal total force." As you can see, if the distance x exceeds the resting length, then the force is negative and the mass accelerates to the left. If the spring is compressed, the acceleration is positive and to the right.

To simplify the analysis of this, we let y = x-L0 denote the displacement from rest and then divide the quation by the mass obtaining:

#### y'' = - (k/m) y-f y'

The general solution to this is obtained by looking at the roots of the polynomial

P(r) = r^2 + fr + k/m

There are several cases that we will explore. This is an examplw of a one degree of freedom mechanical system. Later in the course we will develop tools to understand all such systems. For now, we will use the linear theory so far developed and also look at the solutions to this computed numerically.

### Analytic tools

Here are some exercises for you that don't require the computer.

• Find the roots of P(r)=0 and assuming that all parameters including friction are positive, show that all solutions decay to zero.
• Show that there are oscillatory solutions in the case when there is no friction and write down the solution to the initial value problem, y(0)=1, y'(0)=0.
• Give a physical interpretation of the initial condition used above. Can you think of how you might set y'(0) which is the velocity of the spring to something that is not zero?
• Show that if the friction is small enough, then the solutions to the differential equation show damped oscillations. However, if the friction is large - we say the spring is over-damped - then the spring decays to the rest length without oscillations. Find the critical value of friction such that there are no more oscillations. (Hint: find the value of f for which the roots to P(r) no longer are complex. But make sure you explain why doing this answers the question.)

### Computer fun

The nonlinear spring can be completely analyzed since it is a linear equation with constant coefficients and the roots of the characteristic equation are known. However, it is instructive to use the computer to look at the solutions in a number of different ways as a sort of practice for system where you cannot explicitly solve the equations. That is what we will do here. As before, we will first create an XPP file to play with on the computer. Since this is a second order system, I will first write it as a pair of first order equations:

y' = yp

yp' = -(k/m)y - f yp

The XPP file, spring.ode is :
```# the linear spring
y'=yp
yp' = -(k/m)*y -f*yp
par k=1,m=1,f=0
@ xp=y,yp=yp,xlo=-1,xhi=1,ylo=-1,yhi=1
@ total=60
done
```
Ok, before beginning, a few explanatory notes. The lines beginning with @ tell XPP/WinPP how to start up. The default is to have time along the x-axis, the first differential equation along the y-axis, etc. These commands simply tell XPP/WinPP to start up with different defaults. Of course, you can change these parameters in the program, but this saves the user a bunch of steps. The first @ line says to put y along the x-axis, yp along the y-axis and tells us the window is (-1,1) by (-1,1). The second line just tells us to integrate up until t=60.

Now, fire up the differential equation. The display is different from what we have seen in the past - the axes are both phase variables. This is called the phaseplane. As you can see, I have set the system up so that the friction is initially zero. From your work above, this means that there are periodic solutions. What does a periodic solution look like in the phaseplane? Click on Init Conds - Mouse (or Run - Mouse in Windows) and click on a point in the plane. You should see a circle. Try it again with different initial conditions.

Here is a picture of the phaseplane I have obtained:

I have marked 4 points on this phaseplane. The origin corresponds to the point where the velocity and the deviation from the rest length are zero.
• What is the position of the spring and the velocity of the spring at each of the 4 marked points relative to the resting position of the spring?
• Using just your intuition, what direction (clockwise or counterclockwise) do solutions go in the phase-plane? Keep in mind that the negative y-direction in our spring is to the left.
• Which of the 4 marked points corresponds to an initial condition in which we compress the spring? stretch the spring?

Click on Dir.field/flow - Dir. Field and accept the defaults (or Phaseplane - Direct Field in WinPP) and see the direction field confirming the basic form of the solutions.

Erase the screen.

• Now add a little bit of friction, say f=.25 and repeat the above. How is the picture different? What does the spring do? Does it continue to oscillate? Does this confirm your analytic results? Does it make physical sense?
• Increase the friction to f=1. Choose initial conditions y=1,y'=0 and solve the equation. Sketch the displacement y(t) as a function of time. You can get XPP/WinPP to do this by clicking on XvsT (or Graphics - XvsTime in WinPP ) but you will lose the phaseplane window. In order to not lose the phaseplane, first open a new graphics window by clicking Makewindow (or Graphics New Window in WinPP.) In UNIX, select between the windows bly clicking on the window and in WinPP click on the little check mark.
• For k=m=1 what value of the friction gives you critical damping? Increase the friction to 2.5 and try a bunch of initial conditions. Does the spring ever over-shoot the equilibrium?

### Fun stuff

We will view an animation of the spring. To do this, you must create an animation file. Rather than type it in, you can download it by clicking here. Alternatively, copy this into a file called spring.ani:

```# spring.ani
PERMANENT
line 0;0;0;.5;\$BLACK;8
# cross hairs for the phaseplane
line .75;1;.75;.5;\$BLUE
line .5;.75;1;.75;\$BLUE
# axis labels
text .8;.95;y'
text .95;.7;y
# axes for the time plot
line 0;.75;.45;.75;\$BLUE
# axis labels
text .425;.7;t
TRANSIENT
# make the spring - it has 10 segments
line 0;.3;(.5+.5*y)/10;.35
line [1..8]*(.5+.5*y)/10;.3-.05*cos([j]*pi);[j+1]*(.5+.5*y)/10;.3+.05*cos([j]*pi)
line 9*(.5+.5*y)/10;.35;(.5+.5*y);.3
# make the mass
frect (.5+.5*y);.25;(.5+.5*y)+.1;.35;\$RED
# phaseplane plot
fcircle .75+.25*y;.75+.25*yp;.02;\$GREEN
# y,y' plot
fcircle t*.45/60;.75+.25*y;.015;\$PURPLE
fcircle t*.45/60;.75+.25*yp;.015;\$ORANGE
end
```

Now set the friction to f=0.1 and solve the equations with the initial condition y=1,y'=0. Click on Viewaxes Toons (or Graphics - Toons in WinPP) A new window will appear. This is the animation window. Click on File (or New File in WinPP) and at the prompt, enter the file spring.ani . You should get a message saying Loaded 21 lines successfully. Click on OK and now you can run the animation. (If the file was not found, make sure it is in the directory that the ode file is running from.) Click on Go (or the forward button |> in WinPP) and the animation should run. There are 3 different animations going simultaneously. At the bottom is a picture of the physical device. The upper left is the time evolution of y(t) in purple and y'(t) in orange. The upper right panel is a representation of the phase-plane with a green circle showing the projection in the phase plane. Thus, you can match the physical pendulum with the phase-space projection and with the time series.

• Change the mass to say .2 and integrate the equations. View the animation. What is different? Does this go with your intuition? Increase the mass to 10 and do the same thing.
• Change the friction to a large positive value (beyond critical damping) and observe what happens. Compress the spring and extend the spring and watch as it oozes back to rest.
• What does increasing the stiffness, k do to the spring?