# Programs

## Physics Programs

### Two-Dimensional Vector Sum

#### Summary Description

Programs:

VECSUM

Version:

2.0, 19 January 2006

Description:

The VECSUM program forms the sum of a number of two-dimensional vectors. Each vector may be described in either rectangular coordinates (X and Y) or polar coordinates (R and Theta). The sum is given in both rectangular coordinates and polar coordinates.

Compatibility:

 CFX-9850G Compatible with CFX-9850G FX-7400G Compatible with FX-7400G

#### Detailed Description

The VECSUM program forms the sum of a number of two-dimensional vectors. Each vector may be described in either rectangular coordinates (X and Y) or polar coordinates (R and Theta). The sum is given in both rectangular coordinates and polar coordinates.

This program uses the mathematical angle convention: angles are measured counterclockwise from the positive X axis or due East.

Other applications of the program include:

• Determining the difference of two vectors;
• Determining the distance and bearing from one point to another point;
• Determining whether a set of distances and bearings forms a closed path; and
• Converting a vector from polar to rectangular coordinates, or vice-versa.

#### Usage

Enter the VECSUM program into the calculator, either using the calculator data cable or entering the program directly.

Choose a unit of linear measure, and convert all distances (X, Y, and R) into this unit. The distances in the sum (X, Y, and R) will be expressed in this unit.

Choose a unit of angular measure (degrees, grads, or radians), and convert all angles (Theta) into this unit. Use the calculator’s SET UP menu to set the calculator to use this unit. The angle in the sum will be expressed in this unit.

Run the program.

The program will report the unit of angular measurement in use, by displaying a message such as “Angles in degrees” or “Angles in radians.” Such a message is shown in the screen shot to the right. If the unit is incorrect, halt the program execution and return to choosing a unit of angular measure.

The program will display the prompt “0:Done 1:x,y 2:r,theta” and pause for you to input a code. The prompt is as shown above. If the first vector to be entered is in rectangular coordinates, enter 1 (the code for “x,y”). If the first vector to be entered is in polar coordinates, enter 2 (the code for “r,theta”). The entry you make here is modal: the choice of rectangular or polar coordinates affects all vectors you enter until you exit the mode. Instructions on exiting the mode are given in the next paragraphs.

If you are entering vectors in rectangular coordinates, the program will prompt for the X- and Y-coordinates of the vector with “x?” and “y?”. Enter the X-coordinate of the vector in response to the “x?” prompt and the Y-coordinate of the vector in response to the “y?” prompt. The entry of the vector (15.7, -12.3) is shown in the screen shot to the right. The program will continue to prompt you with “x?” and “y?” until you enter 0 for both the X-coordinate and the Y-coordinate. When you enter the vector (0, 0), the program will return to the prompt “0:Done 1:x,y 2:r,theta.”

If you are entering vectors in polar coordinates, the program will prompt for the length (r) value with “r?” and for the angle (theta) value with “theta?”. Enter the vector length in response to the “r?” prompt, and the vector angle in response to the “theta?” prompt. The entry of the vector r=19.94, theta=141.92 is shown in the screen shot to the left. The program will continue to prompt you with “r?” and “theta?” until you enter 0 for the length (r) value. When you enter 0 for the length value, the program will return to the prompt “0: Done 1:x,y 2:r,theta.”

When the program has prompted you with “0:Done 1:x,y 2:r,theta?” you can choose 0 to indicate that you have entered all vectors. The program will then display the sum of the vectors you entered. The program will first display the sum in rectangular coordinates with the label “x,y=”, followed by the X-coordinate of the sum, followed by the Y-coordinate of the sum. This is shown in the screen shot to the right. You must press the EXE key after the X-coordinate is displayed and after the Y-coordinate is displayed.

After the sum of the vectors has been displayed in rectangular coordinates, it is displayed in polar coordinates with the label “r,theta=”, followed by the distance (r) value of the vector, followed by the angle (theta) value of the vector in the chosen angular units. This is shown in the screen shot to the left. You must press the EXE key after the distance value is displayed.

#### Usage Variations

##### Entering Angles In Degrees, Minutes, and Seconds

As with any time an angle in degrees is entered, you can enter the angle in degrees, minutes, and seconds. On the FX-7400G, press OPTN, the right arrowhead key, and F2 (ANGL) to choose the angle menu, and the right arrowhead key. This displays the degree, minutes, and seconds menu. Enter the degrees part of the angle, followed by F1 (°’”), followed by the minutes part of the angle, followed by F1 (°’”), followed by the seconds part of the angle, followed by F1 (°’”). On the CFX-9850G, press OPTN, F6 (the right arrowhead), and F5 (ANGL) to choose the angle menu. Enter the degrees part of the angle, followed by F4 (°’”), followed by the minutes part of the angle, followed by F4 (°’”), followed by the seconds part of the angle, followed by F4 (°’”). The use of this technique is indicated in the display by a superscript square, similar to the superscript degree sign. Note that you can combine this technique with the previous technique to enter an angle in degrees, minutes, and seconds, even when the unit of angular measurement is not degrees: follow the last press of the °’” key with the ° key (you may need to press the arrowhead key to get to the appropriate part of the menu). The screen shot to the right shows the entry of the angle 57°17’44.81” when the calculator is using radians.

##### Displaying Degrees, Minutes, and Seconds

As with any time a value in degrees is displayed, you can convert the value into degrees, minutes, and seconds. On the FX-7400G, press OPTN, the right arrowhead key, F2 (ANGL) to choose the angle menu, the right arrowhead key, and F2 (°’” with a bar over it) to choose the inverse degrees, minutes, and seconds operation. On the CFX-9850G, press OPTN, F6 (the right arrowhead), and F5 (ANGL) to choose the angle menu, and F5 (°’” with a bar over it) to choose the inverse degrees, minutes, and seconds operation. This converts the fractional degrees into minutes and seconds. This is shown in the screen shot to the right.

##### Subtracting Vectors

You can use the program to subtract vectors as well as add them. To form A-B, where A and B are both vectors, add A and the negative of B. You form the negative of a vector expressed in rectangular coordinates by negating both the X-coordinate value and the Y-coordinate value. You can form the negative of a vector expressed in polar coordinates either by negating its length (r) value, or by adding 180° to (or subtracting 180° from) its angle (theta) value.

##### Distance and Bearing

You can figure the distance and bearing from a point A to a point B by computing B-A. This gives you the vector needed to add to A (the origin) to move to B (the destination). The distance between the two points is the length (r) of the difference vector; the direction from A to B is the angle (theta) of the difference vector.

##### Determining If A Path Is Closed

You can use the program to determine if a path is closed. Simply add together the vectors that measure the edges of the path. If the length of the sum of the vectors is zero, the path is closed. Note that the finite precision of measurements may result in a vector sum with a length that is close to zero, rather than zero exactly. If the length of the vector sum is “close enough” to zero, you can consider the path to be closed.

##### Coordinate Conversion

You can use the program to convert a vector from polar coordinates to rectangular coordinates, or from rectangular coordinates to polar coordinates. Run the program, and enter the single vector to be converted. The “sum” of the single vector will be the vector itself, which will be presented in both rectangular and polar coordinates. The form which was not the form in which you entered the vector is the vector converted to the other form.

#### Program

##### Source Code

The program is available in a ZIP file, or may be entered as shown below. Remember that this program is copyrighted; see the copyright issues page for limitations on redistribution.

Program VECSUM (362 bytes):

'VECSUM 2.0
"Angles in"
If 1°=1
Then "degrees"
Else If 1r=1
IfEnd
IfEnd
0→A~E
Do
"0:Done"
"1:x,y"
"2:r,theta"?→A
If A=1
Then Do
"x"?→B
"y"?→C
B+D→D
C+E→E
LpWhile (B≠0)+(C≠0)
IfEnd
If A=2
Then Do
"r"?→B
If B≠0
Then "theta"?→C
Rec(B,C)
D+List Ans[1]→D
E+List Ans[2]→E
IfEnd
LpWhile B≠0
IfEnd
LpWhile A≠0
"x,y="
D
E
"r,theta="
If (D2+E2)≠0
Then Pol(D,E)
List Ans[1]
List Ans[2]→A
If A<0
Then A+2πr→A
IfEnd
A
Else 0
0
IfEnd

##### Programming Notes

The program detects the angular units in use by the calculator by checking the results of an angular measurement conversion. The ° operator converts a value in degrees into the angular measure in use by the calculator. Thus, if 1° has the value 1, the calculator is set to use degrees; and similarly for the r operator, 1r, and radians.

The program tests for multi-variable conditions by using arithmetic on the results of comparison operations. The comparison operators return 0 for false conditions, and 1 for true conditions; the various control constructs regard zero as false and non-zero as true. This permits multiplication to be used as an equivalent to logical and, and addition to be used as an equivalent to logical or.

The program uses the Rec() function to convert user-supplied polar coordinates into rectangular coordinates. The Rec() function returns a two-element List; the X coordinate is stored in [1], the Y coordinate in [2]. The program evaluates Rec() but does not store the result, so the result is available in List Ans.

The program uses the Pol() function to convert the rectangular coordinate of the sum into polar coordinates. The Pol() function returns a two-element List; the R coordinate is stored in [1], the Theta coordinate in [2]. The Pol() function returns a Theta value between negative two right angles and positive two right angles; the program adds 2πr (a whole circle in whatever angular measurement is in use) to negative angles to obtain the equivalent positive angle.

Page last updated 22 January 2006.

# Brian’s Casio Calculator Corner

Home

Programs

Index

Mathematics

Finance

Physics

Index

Vector Sum

Right Triangle

Newton’s Law

Uniform Acceleration

Ohm’s Laws

Utility

Tutorial

Puzzles

Site Information