• No se han encontrado resultados

Capítulo 2. El mundo de los Drag Queen

2.1. Orígenes e historia

y r r x r y F Fx Fy

FIGURE 2.24: The moment of a force in the xy−plane

In Figure 2.24 we see a force, F, acting on a body in a point defined by the radius r. Both vectors, F and r, are defined by their components parallel to the given axes of coordinates. Considering that a moment is positive when it tends to rotate the body counterclockwise, the moment of the force about the origin of coordinates is given by

M =−ryFx+ rxFy= rx ry Fx Fy

To give an example consider the point shown in Figure 2.24 and a force whose components parallel to the coordinate axes are both equal to 1.5 N. If the radius r is measured in m, the moment in Nm is

 r = [ 3*cosd(40) 2*sind(40) ] r = 2.2981 1.2856  F = [ 1.5 1.5 ]; det([ r; F ]) ans = 1.5188

The body tends to turn counterclockwise. The fact that we could calculate the moment as a determinant suggests that it is equal to the vector product of r by F. The moment about the origin, of a force, F, acting in a point identified by the vector r, is defined, indeed, as

y M o z F r x

FIGURE 2.25: The moment about a point x y r F P1 r1 r2

FIGURE 2.26: Calculating the moment about a shifted point

Mo= r× F

Thus, the moment is a vector perpendicular to the plane defined by r and F and pointing in the direction in which a screw would advance when r will turn towards F. To continue the example in MATLAB we must first convert the vectors to three-dimensional ones and afterward call the command cross:

 r = [ r 0 ]  F = [ F 0 ];  cross(r, F) ans =

0 0 1.5188

Figure 2.25 shows at correct scale the three vectors involved in these calcu- lations and the positive sense of rotation of r towards F.

As an exercise let us calculate the moment of the force F about another point, P1 in Figure 2.26. The new point is defined by the radius r1. The lever of the force about this point is r2 = r− r1. Then, the moment about P1 is equal to

M1= r2× F = (r − r1)× F As r× F = M, we conclude that

M1= M− r1× F

and this is the rule for calculating the moment of a force about a shifted point. With the values used previously, and defining the position vector of the shifted point, r1, we calculate in MATLAB:

 r1 = [ -2.9544 0.3473 0 ];  r2 = r - r1 r2 = 5.2526 0.9383 0  M1 = cross(r2, F) M1 = 0 0 6.4714  M - cross(r1, F) ans = 0 0 6.4714

2.7

Summary

In this chapter we generalize the notion of array and its uses. First, we show that we can store numbers not only as a line, but also as a column. Next, we combine one-dimensional arrays into two-dimensional arrays. The array is the basic data structure of MATLAB. We show that the one-dimensional array allows a natural representation of vectors, quantities that have a magnitude, a direction and a sense. The operations defined on vectors are the addition, the multiplication by a scalar, the scalar, or dot product, and the vector, or cross product. This chapter includes a few applications of vectors in geometry and in mechanics.

We turn two-dimensional arrays into matrices by defining the matrix prod- uct. Another notion introduced in this chapter is that of determinant. We illustrate applications of these notions in geometry and mechanics.

In this chapter we learn to program in MATLAB:

For loops - constructions that perform iterations of operations or groups of operations;

If Elseif Else constructions - these are schemes that perform conditional branching.

When programming, mind the following recommendations.

Comment lines - The first line of a script file, or the first line following a function declaration should be a comment line beginning with the name of the file, preferably written in upper case letters. More comment lines can follow and they may include a short description of the purpose of the program, the input and output arguments, and the date of writing or last revision. These comments can be retrieved with the command

help followed by the name of the file, which is also the first word of the comments. This helps the writer of the program who wants to use it after some time and has forgotten the details. It also helps another user to call correctly a function. Ending the comments with a date helps the user in choosing the last version.

Indentation - The body of a repetitive construction, such as a For loop, or of a conditional construction, such as if elseif else, should be indented. Do this to enhance readability.

Check correctness of repetitive constructions - Tools for doing this are

simulation, a loop invariant, or proof by induction.

The MATLAB commands and functions introduced in this chapter are: axis([ a b c d )] - defines the size of the figure.

axis equal - forces the same scale on the horizontal and the vertical axes; axis off - suppresses the plotting of axes.

cross - calculates the vector, or cross product. det - calculates the determinant of a square matrix.

diff - a function that calculates differences between adjacent elements of an array.

dot - a function that yields the scalar product of two vectors of the same length.

fill - a command that fills a figure with a required color.

hold on - a command that allows us to add plots over an existing graph. It is recommended to add the closing command hold off after com- pleting the sequence of plotting commands. These two commands are introduced below, in Example 2.5.

norm - a function defined for more advanced purposes, but that we use in this chapter to calculate the length, or magnitude of a vector.

patch - another command command that fills a figure with a required color; plot3 - the command for plotting lines in three-dimensional graphs.

size - a command that yields the dimensions of an array, that is the number or rows and the number of columns.

sum - the command that yields the sum of the elements in a given array. zeros(m, n) - creates the m-by-n zero matrix.

To enhance graphs we introduce five elements belonging to handle graphics: ’color’ - a command to define the color of a line, for example ’color’, ’r’. ’FontSize’ - a command that allows us to define the size of fonts. The

common unit is the point equal to 1/72 in.

’LineStyle’ - a command that defines the line style, which can be, for exam- ple, ’-’, or ’:’.

’LineWidth’ - a command that allows us to define the thickness of lines. set - a command of general use in Handle graphics and employed with a

handle as first argument, for example set(h, ’LineWidth’, 1.5). In this chapter we also build three utility functions that we are going to reuse throughout this book in creating figures:

arrow - in 2-D plots draws an arrow between two points defined by their coordinates;

pline - in 2- and 3-D drawings connects with straight-line segments of a set of points defined by their coordinates;

point - in 2-D plots draws a black circle of given radius, with center defined by its coordinates.

EXAMPLE 2.5 The graphics of the hanging weight

In this example we return to the function Statics1, developed in Exam- ple 2.4, and turn it into another function that plots the scheme of the problem adapted to the input variable a. In Chapter 10 we develop a graphical user interface, shortly GUI, that calls the function described in this example. The function developed here, Stat1FigFun, is called with one input argument, the horizontal distance a between the first and the second articulation, and an array of four output arguments

• the magnitude, r1, of the force R1; • the magnitude, r2, of the force R2; • the two-dimensional vector R1; • the two-dimensional vector R2.

function [ r1 r2 R1 R2 ] = Stat1FigFun(a)

%STAT1FIGFUN plots the figure of the GUI TwoBarStatics % The input argument a is given in mm, as usual % in Mechanical-Engineering drawings.

% The output arguments are measured in N.

% This function calls the utility functions arrow,

% pline and point.

% Written by Adrian Biran for Taylor &

% Francis, June 2009.

% Define parameters for drawing ad = a/10; b = 150 - ad; c = 50; ha = 110; % higher articulations z w = 50; % length of W vector, N % define articulations; A = [ 30; ha ]; B = [ (30+ ad); (ha -c) ]; C = [ (30 + 150); ha ]; % plot something pline([ A B C ], 1, ’k’, ’-’) axis([ 0 190 0 135 ])

axis equal, axis off hold on % plot ceiling hp = plot([ 20 190 ], [ 115 115 ], ’k-’); set(hp, ’LineWidth’, 1.5) plot([ 20 22.5 ], [ 117.5 120 ], ’k-’) % plot articulations

point(A, 1) % first articulation from left

plot([ 25 30 35 25 30 ], [ 115 110.5 115 115 110.5 ], ’k-’) point(B, 1) % second articulation from left

x0 = 20; % initialize hatching for k = 1:67

plot([ x0 (x0 + 5) ], [ 115 120 ], ’k-’) x0 = x0 + 2.5;

end

plot([ 187.5 190 ], [ 115 117.5 ], ’k-’) % end hatching point(C, 1) % third articulation from left

plot([ 175 180 185 175 180 ], [ 115 110.5 115 115 110.5 ], ’k-’) % plot hanging weight

ht = text((B(1) + 2), 30, ’W = 50 N’); set(ht, ’FontSize’, 14)

% Plot inverse of W vector

arrow(B, [ B(1); (B(2) + w) ], 1.3) text((B(1) + 3), (B(2) + w/2), ’-W’) % calculate angles

alpha = atand(ad/c); beta = atand(b/c);

gamma = 180 - alpha - beta;

% calculate magnitudes of tension vectors r1 = sind(beta)*w/sind(gamma); r2 = sind(alpha)*w/sind(gamma); % define tension vectors % two-dimensional R1 = r1*[ -sind(alpha); cosd(alpha) ]; R2 = r2*[ sind(beta); cosd(beta) ]; % coordinates of vector extremities

L1 = B + R1;

arrow(B, L1, 1.6)

ht = text((L1(1) - 8), (L1(2) - 8), ’R_1’); set(ht, ’FontSize’, 12, ’FontWeight’, ’bold’)

L2 = B + R2;

ht = text((L2(1) + 5), (L2(2) - 4), ’R_2’); set(ht, ’FontSize’, 12, ’FontWeight’, ’bold’) arrow(B, L2, 1.6) % dimensions plot([ 30 30 ], [ 115 126 ], ’k-’) plot([ B(1) B(1) ], [ 115 126 ], ’k-’) plot([ 180 180 ], [ 115 126 ], ’k-’) arrow([ (A(1) + B(1))/2; 125 ], [ 30; 125 ], 0.8) arrow([ (A(1) + B(1))/2; 125 ], [ B(1); 125 ], 0.8) ht = text((30 + ad/2), 129, ’a’);

set(ht, ’FontSize’, 10) arrow([ (B(1) + C(1))/2 ; 125 ], [ B(1); 125 ], 0.8) arrow([ (B(1) + C(1))/2; 125 ], [ C(1); 125 ], 0.8) ht = text((B(1) + C(1))/2, 129, ’b’); set(ht, ’FontSize’, 10) plot([ 4 30 ], [ 110 110 ], ’k-’) plot([ 4 B(1) ], [ 60 60 ], ’k-’) arrow([ 5; 85 ], [ 5; 110 ], 0.8) arrow([ 5; 85 ], [ 5; 60 ], 0.8) ht = text(0, 65, ’c = 500’, ’rotation’, 90); set(ht, ’FontSize’, 10)

% plot parallelogram of forces

pline([ L2 [ B(1); (B(2) + w) ] ], 1, ’r’, ’--’) hold off W = 50 N −W R 1 R 2 a b c = 500

FIGURE 2.27: Figure generated with the command Stat1FigFun(500)

The first plotted elements are the straight-line segments that connect the three articulations. MATLAB sizes the figure according to the first plotted elements. We need a slightly larger figure for adding more elements. To avoid the resizing of the figure, we define its size from the beginning by using the command axis with an array argument. The four elements of the array are the x−coordinate of the left corners of the plotting area, the x−coordinate of the right corners, the y−coordinate of the lower corners, and the y−coordinate of the upper corners. Further, we use the command axis equal to force the same scales along the x− and y−axes, and the command axis off to suppress the plotting of axes.

2.8

More exercises

Exercise 2.3 Plotting a square a) Given the three points

P1=  1 1  , P2=  1 3  , P3=  3 3 

define a fourth point, P4, such that P1, P2, P3, P4 are the vertices of a square.

c) Calculate the perimeter of this square and verify that it corresponds to what you expect.

Exercise 2.4 A function for calculating the perimeter

Convert the function perim, developed in Subsection 2.1.3, into a function, perim1, valid for n−dimensional vectors. To do this, use the function size to determine the dimension, n, of the vectors and call the function diff in a loop that is executed n times, each time for another coordinate.

Exercise 2.5 The angle between two vectors

Write a function that finds the angle between two vectors according to the specification

Input arguments: two vectors V1, V2, defined by their components parallel to cartesian axes of coordinates;

Output argument: the angle between the two vectors, in degrees. Exercise 2.6 Elementary operations on matrices

Define in MATLAB the matrices A =  6−4 10 2 0 −6  , B =  −2 10 0 4 −6 14  , C =  1 3 2 3 1 2  ,

1) Check that the addition of matrices is commutative, that is A + B = B + A

2) Check that

A− B = −(B − A)

3) Check that the addition of matrices is associative, for example A + (B + C) = (A + B) + C 4) Define in MATLAB D =  5 10 1 2  Try the operations

A + D, A− D and explain what happens.

O = zeros(size(A)) and check that

A + O = O + A, B + O = O + B

7) Define in MATLAB the scalar k = 2. See what happens if you multiply it by a matrix, for example k∗ A, with A defined as above.

8) Check that the multiplication of matrices by scalars is associative, for example

k∗ A + k ∗ B = k ∗ (A + B) Also, define h = 3 and check that

h∗ A + k ∗ A = (k + h) ∗ A

Note. The elements of the matrices involved in this exercise are all integers. Therefore, the proprieties described here are always verified. When working with numbers that are not integers, many of the above properties are verified only approximatively. This subject is treated in Chapter 5.

Exercise 2.7 The cross products of base vectors

For the vector basis defined in Subsection 2.1.7 use the cross product to show that

e1× e2= e3, e2× e3= e1, e3× e1= e2

Mind the circular permutation of indices in the above equations. Exercise 2.8 Properties of rotation

For the rotation shown in Figure 2.21 you are asked to:

1. use the function norm to check that the distances between points are not changed by rotation. In other words check that P1P 2 = Q1Q2, a.s.o; 2. use the dot product to check that the points are rotated, indeed, by 30

degrees. In other words check that P1OQ1= 30o, a.s.o.

Exercise 2.9 Combining translation and rotation

Suppose that we have to perform several transformations. In general, the order in which we carry them defines the final result. Consider in Subsec- tion 2.1.5 the triangle defined by the three points, P1, P2, P3. Your assign- ment incudes the following tasks:

1. convert the matrix of coordinates, P, into a matrix of homogeneous coordinates;

2. plot the initial triangle defined by P. The axes of the plot should allow the addition of the two plots required below;

3. define a translation matrix, in homogeneous coordinates, that shifts ob- jects 3 units horizontally, and 4 units vertically;

4. define a rotation matrix, in homogeneous coordinates, that rotates ob- jects 30 degrees counterclockwise;

5. using the matrices defined above, first translate, next rotate the triangle. Call the resulting points Q1, Q2, Q3. Plot the transformed triangle in the same figure that shows the initial triangle;

6. using the matrices defined above, first rotate, next translate the triangle. Call the resulting points R1, R2, R3. Plot the transformed triangle in the same figure that shows the initial triangle.

Exercise 2.10 Weight data of a containership

x z

FIGURE 2.28: Coordinates used for the containership

Table 2.1 shows the weight data of a containership. These data are taken from an example found in Taggart (1980) and are slightly simplified for the purpose of the exercise. The coordinates of the centers of gravity of the various weight groups are:

VCG (Vertical Center of Gravity), is the height coordinate measured parallel to the z−axis, from the baseline, as shown in Figure 2.28;

LCG (Longitudinal Center of Gravity), is the length coordinate measured parallel to the x−axis, from the line marked AP (Aft Perpendicular), as shown in Figure 2.28. The Aft Perpendicular coincides here with the z−axis.

The y− coordinate of the center of gravity of the lightship and that of the fully-loaded ship are expected to be zero; therefore, the table contains only two coordinates.

The ship without any load consists of items 1 to 3. The sum of the masses of the three first items is known as lightship. Items 4 to 10 constitute the deadweight. The sum of the Lightship and Deadweight masses is the full load mass. In this exercise you are required to calculate

Table 2.1: Weight data of containership

Weight group Mass, t VCG, m LCG, m

1 Hull 8624 9.8 99.5

2 Outfit 2383 14.2 94.6

3 Machinery 1158 8.4 32.1

4 Miscellaneous deadweight 152 11.6 16.5 5 Passengers, crew and stores 85 15.3 26.5

6 Fuel oil 6727 8.0 113.3

7 Fresh water 588 4.5 32.9

8 Salt water ballast 2470 1.0 108.4

9 Stabilizer tank 163 9.3 80.2

10 Container cargo 15485 14.1 102.6

1. the total mass and the VCG and LCG of the lightship; 2. the total mass and the VCG and LCG of the deadweight; 3. the total mass and the VCG and LCG of the full load.

Equations

3.1

Introduction

The first part of this chapter deals with systems of linear equations. To solve them in MATLAB they must be written in the matrix form AX = B. Then, the preferred MATLAB solution uses the backslash operator, ‘\’, called as X = A\B. The backslash operator always yields a solution; it can be a unique solution, a particular solution, a solution in the least-squares sense, or no solution at all. To explain these cases we distinguish between fully determined, underdetermined, overdetermined and homogeneous systems. The Kronecker- Capelli theorem gives a criterion for knowing whether a given system of linear equations has a solution or not. The criterion is based on the notion of rank, a number that can be calculated in MATLAB.

The second part of the chapter treats to some extent algebraic equations. To explain how to solve them in MATLAB we show first how to represent polynomials and how to deal with them in MATLAB. Equating a polynomial to zero yields an equation that can be solved in MATLAB with the command roots. This command, however, has its limitations, a subject discussed later in another chapter.

Equations that are not polynomials can be solved by iterative methods. We show how to implement in MATLAB a popular iterative method, that is the Newton-Raphson method.