Velocity and Acceleration Vectors in Matlab

In this activity we will introduce Matlab's quiver command, which will assist in creating visualizations that help develop a deeper understanding of velocity and acceleration in the plane and three-space.

Motion on a Line

Recall from your first calculus course (differential calculus) the following idea. Let x represent the position of a particle constrained to move along a line (see Figure 1). Because the position of the particle changes with time, x is a function of time t; i.e., x=x(t).

SVG

The position x=x(t) of a particle on a line is a function of time.

Now, recall two facts from differential calculus:

  1. The first derivative of the position with respect to time gives the velocity of the particle on the line as a function of time; i.e.,

    v(t)=x'(t).

  2. The second derivative of the position with respect to time gives the acceleration of the particle on the line as a function of time; i.e.,

    a(t)=x''(t).

We will now extend these ideas of velocity and acceleration into the plane.

Motion in the Plane

Suppose that a particle moves in the plane along the path shown in Figure 2.

SVG

The tip of the position vector traces the path of the particle as a function of time.

Position: The position of the particle is determined by the position vector r(t)=x(t),y(t). That is, the vector r gives us the position of the particle as a function of time. The vector r(t) changes with time, both in magnitude and direction, and as it changes, the tip of the position vector traces out the path of the particle shown in Figure 2.

Velocity: As in the case of motion along a line, the first derivative of the position with respect to time yields the velocity. However, in the case of motion in the plane, the position is a vector valued function of time. To take the derivative, we simply take the derivative of each component of the position vector (reasons for this are discussed in your text).

v(t)=r'(t)=x'(t),y'(t)

The result should be a vector that determines the instantaneous velocity at a particular moment in time. Consequently, the velocity vector should point in the direction of motion at that instant. Therefore, the velocity vector should be tangent to the path of the particle at that instant in time, as shown in Figure 3.

SVG

The velocity vector points in the direction of motion and is tangnet to the path at each instant of time.

Acceleration: As in the case of motion along the line, the second derivative of the position with respect to time yields the acceleration. However, in the case of motion in the plane, the position is a vector valued function of time. To take the second derivative, we simply take the second derivative of each component of the position vector (reasons for this are discussed in your text).

a=r''(t)=x''(t),y''(t)

Newton's second law states that

F=ma.

This means that the force vector F is a scalar multiple of the acceleration vector a, which means that the vectors F and a must be parallel. Furthermore, because the mass m is a positive scalar quantity, the vectors F and a must point in the same direction.

Newton's first law states that "an object in motion tends to stay in motion with the same speed and direction unless acted upon by an external force." Note how the path of the particle bends downward. This cannot happen unless an external force is pushing the particle in that direction. Therefore, the acceleration of the particle must point in that same direction. Thus, the depiction of the acceleration vector in Figure 4 seems reasonable.

SVG

The acceleration vector must point in the same direction as the applied force.

An example should reinforce these concepts.

A particle moves on a path determined by the vector-valued function

r(t)=2cos(t),3sin(t).

Sketch the path taken by the particle and append velocity and acceleration vectors at several instances of time.

Solution: We begin by sketching the path determined by the position vector

r(t)=x(t),y(t)=2cos(t),3sin(t).

We first initialize some time-values, then compute the position x(t)=2cos(t), y=3sin(t) at each of these times.

t=linspace(0,2*pi,200);
x=2*cos(t);
y=3*sin(t);

Create the plot, add a grid, and equalize the axes.


plot(x,y)
grid on
axis equal

Add appropriate annotations.

xlabel('x-axis')
ylabel('y-axis')
title('The graph of x = 2 cos(t), y = 3 sin(t)')

The above sequence of commands produces the path of the particle shown in Figure 5.

The path of the particle is an ellipse.

The path of the particle is an ellipse.

Now that we have constructed the path, let's see how we can add velocity vectors to our path.

Adding Velocity Vectors: The velocity is the first derivative of the position, so:

v(t)=ddtr(t)=ddt2cos(t),3sin(t)=-2sin(t),3cos(t)

Matlab's quiver command is used to draw vectors. We first ask for information with the command help quiver, part of whose output follows.

    QUIVER(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
    at the points (x,y).  
    
    QUIVER(U,V,S) or QUIVER(X,Y,U,V,S) automatically scales the 
    arrows to fit within the grid and then stretches them by S.  Use
    S=0 to plot the arrows without the automatic scaling.

We will use the second form of syntax, namely QUIVER(X,Y,U,V,S). A quick explanation of the arguments is in order.

We will now draw a second plot and add velocity vectors at selected times. We begin as above and resketch the ellipse with the following commands.

t=linspace(0,2*pi,200);
x=2*cos(t);
y=3*sin(t);
plot(x,y)

Next, we'll select times at which to plot our velocity vectors and calculate the positions at which the tails of the vectors will be applied.


tt=0:pi/4:2*pi;
xx=2*cos(tt);
yy=3*sin(tt);

As we saw above, v(t)=-2sin(t),3cos(t). We will use this formula to calculate the components of the velocity vectors.

vx=-2*sin(tt);
vy=3*cos(tt);

Hold the plot, then add the velocity vectors with the quiver command. Note that we set the scaling S = 0, which turns off all scaling of the vectors drawn by the quiver command.

hold on
quiver(xx,yy,vx,vy,0)

Add the usual annotations.

xlabel('x-axis')
ylabel('y-axis')
title('The graph of x = 2 cos(t), y = 3 sin(t)')

The above sequence of commands will produce the plot shown in Figure 6.

Adding velocity vectors to the path of the particle.

Adding velocity vectors to the path of the particle.

In Figure 6, note that some vectors are longer than others; i.e., the magnitude of the vectors (the speed of the particle) changes with position. The speed seems to be at a maximum when the particle crosses the x-axis and at a minimum when the particle crosses the y-axis.

Let's investigate how we can add acceleration vectors to our path.

Adding Acceleration Vectors: The acceleration is the second derivative of position, or the first derivative of the velocity, so:

a(t)=d2dt2r(t)=ddtv(t)=ddt-2sin(t),3cos(t)=-2cos(t),-3sin(t)

We will now draw a third plot which includes both velocity and acceleration vectors at selected times. We repeat our work above in sketching the path and velocity vectors.


t=linspace(0,2*pi,200);
x=2*cos(t);
y=3*sin(t);
plot(x,y)
tt=0:pi/4:2*pi;
xx=2*cos(tt);
yy=3*sin(tt);
vx=-2*sin(tt);
vy=3*cos(tt);
hold on
quiver(xx,yy,vx,vy,0)

Next, we calculate the components of the acceleration vectors

ax=-2*cos(tt);
ay=-3*sin(tt);

We already "held" the plot, so we need only add the acceleration vectors.

quiver(xx,yy,ax,ay,0)

In this plot, we'll get a little fancy, adding points at the positions where the tails of our velocity and acceleration vectors are applied.

line(xx,yy,...
    'linestyle','none',...
    'marker','.',...
    'markersize',6)

Some explanatory comments are in order:

Add the usual annotations.


xlabel('x-axis')
ylabel('y-axis')
title('The graph of x = 2 cos(t), y = 3 sin(t)')

The above sequence of commands will produce the plot shown in Figure 7.

Adding acceleration vectors to the path of the particle.

Adding acceleration vectors to the path of the particle.

Note how all of the acceleration vectors point inward towards the origin. This example should bring to mind the physical situation of a planet orbiting the sun. The force of gravitation always points toward the sun, so the planet is always accelerating toward the sun.

Motion in Space

The technique shown in our planar examples works equally well in three-space. Let's just jump into an example.

The position of a particle is given by the vector:

r(t)=cos(t),sin(t),t/(8π)

Solution: It is a simple matter to sketch the path in three-space.

t=linspace(0,8*pi,200);
x=cos(t);
y=sin(t);
z=t/(8*pi);
plot3(x,y,z)

Add a grid and box for depth, equalize the axes, then orient the view to the standard orientation used in class.

grid on
box on
axis equal
view([130,30])

The above sequence of commands will produce the helix shown in Figure 8.

The path of the particle is a helix.

The path of the particle is a helix.

Select some times at which to plot the velocity and acceleration vectors, then compute the position of the tails of the vectors at each time element.

tt=0:pi/2:8*pi;
xx=cos(tt);
yy=sin(tt);
zz=tt/(8*pi);

Adding Velocity Vectors: The velocity is the first derivative of position, so:

v(t)=ddtr(t)=ddtcos(t),sin(t),t/(8π)=-sin(t),cos(t),1/(8π)

Use this result to compute the components of the velocity vectors at each time element.

vx=-sin(tt);
vy=cos(tt);
vz=ones(size(tt))/(8*pi);

The computation of vz requires a bit of explanation. We need each entry of vz to equal 1/(8π). So we first construct a vector of all ones that is the same size as the vector tt, then divide each entry by 8π.

Hold the plot, then plot the vectors with the quiver3 command.

hold on
quiver3(xx,yy,zz,vx,vy,vz,0)

The resulting velocity vectors are shown in Figure 9.

Adding velocity vectors to the path.

Adding velocity vectors to the path.

Adding Acceleration Vectors: The acceleration is the second derivative of the position, or equivalently, the first derivative of the velocity.

a(t)=d2dt2r(t)=ddtv(t)=ddt-sin(t),cos(t),1/(8π)=-cos(t),-sin(t),0

Compute the components of the acceleration vectors.

ax=-cos(tt);
ay=-sin(tt);
az=zeros(size(tt));

The command az=zeros(size(tt)) creates a vector having he same size as the vector tt and fills it with zeros. Add the acceleration vectors to the plot.

quiver3(xx,yy,zz,ax,ay,az,0);

Add some appropriate annotations.

xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('The graph of x = cos(t), y = sin(t), z=t/8\pi')

The result of the above sequence of commands is captured in Figure 10.

Adding acceleration vectors to the path.

Adding acceleration vectors to the path.

Constant Speed Curves

In Figure 10, note that all of the acceleration vectors are orthogonal (perpendicular) to the velocity vectors. This was not the case in the elliptical example of Figure 7. There is a reason why the acceleration vectors are orthogonal to the velocity vectors in the current example, the reason being that the position vector r(t)=cos(t),sin(t),t/(8π) traces what is know as constant speed curve.

Because r(t)=cos(t),sin(t),t/(8π), we saw that the velocity is given by

v(t)=-sin(t),cos(t),1/(8π).

Speed is the magnitude of velocity, so the speed of the particle traveling on the helix in Figure 10 is

|v(t)|=sin2(t)+cos2(t)+(1/(8π))2=1+164π2.

Thus, the speed is constant. Note that the velocity is not constant, because the direction of the velocity vectors in Figure 10 is always changing. But the magnitude of the vectors does not change; i.e., the speed is constant.

Now, what happens when the speed is constant; i.e., what happens when |v|=c, where c is a constant? Well, in this case, the square of the speed will be |v|2=c2, so the square of the speed is also constant. Recall that |v|2=vv, so we can write

vv=c2.

Differentiate both sides of this last result with respect to t. Remember that v=v(t); i.e., v is a function of time. Also, remember that c is constant. Note how we use the product rule for dot products in the following calculation.

ddt(vv)=ddt(c2)vdvdt+dvdtv=02vdvdt=0

Dividing both sides of the last result by 2 yields the result we need.

vdvdt=0.

Because the derivative of the velocity is acceleration,

va=0.

That is, in the case of constant speed curves, the velocity and the acceleration vectors must be orthogonal to each other at each point of the curve. This is evident in the case of the constant speed curve shown in Figure 10.

Matlab Files

Although the following file features advanced use of Matlab, we include it here for those interested in discovering how we generated the images for this activity. You can download the Matlab file at the following link. Download the file to a directory or folder on your system.

velacc.m

The file velacc.m is designed to be run in "cell mode." Open the file velacc.m in the Matlab editor, then enable cell mode from the Cell Menu. After that, use the entries on the Cell Menu or the icons on the toolbar to execute the code in the cells provided in the file. There are options for executing both single and multiple cells. After executing a cell, examine the contents of your folder and note that a PNG file was generated by executing the cell.

Exercises

In each of the following exercises, perform each of the following tasks:

  1. r(t)=t2,t3 in the plane over the time interval -1t1.
  2. r(t)=2cos(t),2sin(t) in the plane over the time interval 0t2π.
  3. r(t)=2cos(2t),2sin(2t),t/(2π) in three-space over the time interval 0t2π.
  4. r(t)=e-tcos(t),e-tsin(t),e-t in three-space over the time interval 0t2π.