Table of contents

Vector approach

Mechanics is all about modelling, meaning that we need to create mathematical models which describe the mechanics in order to solve for interesting entities. The physical problem is first simplified into a mechanical system, using assumptions. We need to keep track of all errors we introduce in such assumptions, this is where experience comes into play. And what we lack in experience we need make up with experimentation.

Preliminaries - vector properties

OA\overrightarrow{\textrm{OA} } is defining the "origin vector" (ortsvektor), which is the vector going from the origin to the point A. We denote such vectors with an arrow.

A vector can also be denoted using bold lowercase letters, i.e., a\mathit{\mathbf{a} } or underlined a\underline a (easier to write on the board during a lecture).

The magnitude is computed using the Pythagorean theorem which is a special case of the Euclidean norm or 2-norm

a=a:=ax2+ay2+az2a=|\mathit{\mathbf{a} }|:=\sqrt{a_x^2 +a_y^2 +a_z^2 }

where ax,aya_x ,a_y and aza_z are the Euclidean components of the vector a\mathit{\mathbf{a} }. A vector can also be disassembled into an unit vector and a magnitude:

a=a  ea\mathit{\mathbf{a} }=a\;{\mathit{\mathbf{e} } }_a, where ea=aa{\mathit{\mathbf{e} } }_a =\frac{\mathit{\mathbf{a} } }{|\mathit{\mathbf{a} }|}

Let's start by defining some helper functions which we will use frequently.

First we clear the workspace, this is good practice in scripts, to avoid nasty bugs when using the same variables in the same document. For every problem, we begin by running the clear command in our script.

clear

Matlab is made for linear algebra and treats natively EVERYTHING as matrices, as such it sees no difference between a vector or a matrix. Matlab in fact is short for Matrix Laboratory.

In Matlab we can quickly compute the norm (magnitude) of a vector simply by using the function norm() which basically does aa\sqrt{\mathbf{a} \cdot \mathbf{a} } .

Many times we need to compute the unit vector for some vector a\mathbf{a}. Unfortunately there is no built in function in Matlab to do so. But we can create our own functions easily, the simplest way is to create an anonymous function.

normalize = @(a)a./norm(a);

Here, we use the built in function norm to compute the magnitude. The @(a) part defines the variable of the function. Let us try with a=[3,4,0]\mathbf{a} =\left\lbrack 3,4,0\right\rbrack since we expect the answer to be [3/5,4/5,0]\left\lbrack 3/5,4/5,0\right\rbrack.

a = [3,4,0];
normalize(a)
ans = 1x3    
    0.6000    0.8000         0

As a test we take to norm of the result

norm(normalize(a))
ans = 1

OK!

Sometimes we need to compute the projection of vector a\mathbf{a} onto vector b\mathbf{b}:

proj = @(a,b)dot(a,b)/dot(b,b)*b;

Let us test this by projecting a\mathbf{a} onto the xx-axis, which is the same as taking the x-component of a\mathbf{a}.

b = [1,0,0]
b = 1x3    
     1     0     0
proj(a,b)
ans = 1x3    
     3     0     0

OK!

Example 1.

Let us study the following problem

The arm OA can rotate freely around O and is actuated by the string attached in AA and around BB. Let a=400mma=400\mathrm{mm}, b=35mmb=35\mathrm{mm} and OA=350mm|\overrightarrow{\mathrm{OA} } |=350\mathrm{mm}.

Solution

Using the right-hand rule we define a coordinate system with xx positively to the right, yy positively up and thus zz is given positively outward from the screen.

Even if the problem is simplified into two dimensions (2D problem or plane problem), we will still use three dimensions in our computations, to ensure that the cross product function, cross(), works in Matlab.

The point BB is a fix point, it does not vary with θ\theta, so it is easiest to describe.

OC=[400,35,0]T\overrightarrow{\mathrm{OC} } ={\left\lbrack 400,35,0\right\rbrack }^T

The point AA varies with θ\theta, using trigonometry we can identify a triangle and define the components. We begin with the unit vector.

eOA=[sinθ,  cosθ,  0]T{\mathit{\mathbf{e} } }_{\mathrm{OA} } ={\left\lbrack \sin \theta ,\;-\cos \theta ,\;0\right\rbrack }^T

Testing this is always a good idea, just set θ\theta to some angles for which the outcome is trivial. For θ=0\theta =0 we expect to get eOA(θ=0°)=[0,  1,  0]T{\mathit{\mathbf{e} } }_{\mathrm{OA} } \left(\theta =0\degree \right)={\left\lbrack 0,\;-1,\;0\right\rbrack }^T, which is the case, and for θ=90°\theta =90\degree we expect to get eOA(θ=90°)=[1,  0,  0]T{\mathit{\mathbf{e} } }_{\mathrm{OA} } \left(\theta =90\degree \right)={\left\lbrack 1,\;0,\;0\right\rbrack }^T, which also is the case.

Now we can define

OA=350eOA(θ)\overrightarrow{\mathrm{OA} } =350{\mathit{\mathbf{e} } }_{\mathrm{OA} } \left(\theta \right)

The vector AB\overrightarrow{\mathrm{AB} } is given by taking the "head minus the tail"

AB=OCOA(θ)\overrightarrow{\mathrm{AB} } =\overrightarrow{\mathrm{OC} } -\overrightarrow{\mathrm{OA} } \left(\theta \right)

And finally the magnitude of the length is given by

L(θ):=AB(θ)L\left(\theta \right):=|\overrightarrow{\mathrm{AB} } \left(\theta \right)|

Now we will compute this in Matlab using symbolic expressions and plot the length as a function of theta to get a graphical solution, which is a perfectly valid solution to our problem.

clear
OB = [400, 35, 0].';
syms theta
eOA = [sind(theta), -cosd(theta), 0].';
OA = 350 * eOA;

AB = OB-OA
(400350sin(πθ180)350cos(πθ180)+350) \left(\begin{array}{c} 400-350\,\sin \left(\frac{\pi \,\theta }{180}\right)\\ 350\,\cos \left(\frac{\pi \,\theta }{180}\right)+35\\ 0 \end{array}\right)
L = norm(AB)
350cos(πθ180)+352+350sin(πθ180)4002 \sqrt{ {\left|350\,\cos \left(\frac{\pi \,\theta }{180}\right)+35\right|}^2 +{\left|350\,\sin \left(\frac{\pi \,\theta }{180}\right)-400\right|}^2 }
figure
fplot(L,[0,180])
xlabel("\theta")
ylabel("L")
title("L(\theta)")

You can now zoom in on the minimum point to get the answer (to an arbitrary precision), LL has its lowest value of 51mm51\mathrm{mm} at θ=95°\theta =95\degree.

We could of course compute the derivative, set it to zero and solve for theta to get the minimum value.

dL = diff(L,theta)
35πsin(πθ180)σ1sign(350cos(πθ180)+35)935πcos(πθ180)σ2sign(σ2)92σ12+σ22where    σ1=350cos(πθ180)+35    σ2=350sin(πθ180)400 \begin{array}{l} -\frac{\frac{35\,\pi \,\sin \left(\frac{\pi \,\theta }{180}\right)\,\sigma_1 \,\textrm{sign}\left(350\,\cos \left(\frac{\pi \,\theta }{180}\right)+35\right)}{9}-\frac{35\,\pi \,\cos \left(\frac{\pi \,\theta }{180}\right)\,\left|\sigma_2 \right|\,\textrm{sign}\left(\sigma_2 \right)}{9} }{2\,\sqrt{ {\sigma_1 }^2 +{\left|\sigma_2 \right|}^2 } }\\ \mathrm{}\\ \textrm{where}\\ \mathrm{}\\ \;\;\sigma_1 =\left|350\,\cos \left(\frac{\pi \,\theta }{180}\right)+35\right|\\ \mathrm{}\\ \;\;\sigma_2 =350\,\sin \left(\frac{\pi \,\theta }{180}\right)-400 \end{array}
theta1 = solve(dL==0,theta)
(180log(25404644944806449i2)iπ180log(25404644944806449i2)iπ) \left(\begin{array}{c} -\frac{180\,\log \left(-\frac{\sqrt{-\frac{25404}{6449}-\frac{4480}{6449}\,\mathrm{i} } }{2}\right)\,\mathrm{i} }{\pi }\\ -\frac{180\,\log \left(\frac{\sqrt{-\frac{25404}{6449}-\frac{4480}{6449}\,\mathrm{i} } }{2}\right)\,\mathrm{i} }{\pi } \end{array}\right)

We have a problem, we are getting weird results, in fact we expect to get infinitely many results since the solution is cyclic.

We can switch to a numerical solver to find the answer

theta1 = vpasolve(dL==0, theta, 95)
95.000644597558432872096355509481 95.000644597558432872096355509481

Here vpasolve(), uses a variant of the Newton-Raphson root finding method to find the root using an initial value.

Let us vary b[10,50]b\in [-10,50] .

figure; hold on
for b = [-10,0,10,20,30,40,50]
    OB = [400, b, 0].';
    AB = OB-OA;
    L = norm(AB);
    fplot(L,[0,180], 'Displayname', ['b: ',num2str(b)])
end
legend show
xlabel("\theta")
ylabel("L")
title("L(\theta)")

Visualization gives an additional dimension to the understanding.

If in doubt, write some visualization code!

theta = 0;
eOA = [sind(theta), -cosd(theta), 0].';
OA = 350 * eOA;
AB = OB-OA;
L = norm(AB);

figure; hold on;
axis([-50,450,-400,400])
plot(0,0,'o','MarkerFaceColor','k','MarkerSize',10)
text(10,5,'O')

plot(OA(1),OA(2),'ok','MarkerFaceColor','w','MarkerSize',10)
text(OA(1)+10,OA(2)+10,'OA')

plot(OB(1),OB(2),'ok','MarkerFaceColor','w','MarkerSize',10)
text(OB(1)+10,OB(2)+10,'OB')

quiver(0,0,OA(1),OA(2),0,'k')

quiver(OA(1),OA(2),AB(1),AB(2),0,'b')

Interactive example