Assignment 6: Vector Math

In this example we will deal with mathematical objects called vectors. The definition of a vector, in Pascal, is:

   TYPE
      Vector = ARRAY[1..MaxDim] OF REAL;

For this assignment you have to write an 'include' file for my main program. In other words, your Pascal code should only contain procedures and functions, and I will include your file into my program to get the complete vector math program. You can - and must - use the new type Vector in your procedures, but you should not refer to the named constant MaxDim. All vectors should have an actual length that is less than or equal to MaxDim and that length must be passed to each procedure or function as parameter.

IMPORTANT

Your file must be called VECT-INC.PAS
All procedure and function names must be exactly as indicated
The formal parameter lists must be precisely as described

Otherwise your file will not work together with my main program.

Procedure ReadVector
Reads real numbers into a vector. The first parameter will contain the vector on output, the second parameter must contain the number of entries in the vector (length of the vector).
Parameters: 1st 2nd
Type: Vector Integer
passing: variable value
Procedure WriteVector
Write a vector on the screen. First parameter must contain the vector to write, second parameter indicates the length of the vector.
Parameters: 1st 2nd
Type: Vector Integer
passing: value value
Procedure MultiplyVectorByNumber
Multiplies each number in a vector by a real number. First parameter contains the input vector, second parameter contains the number to multiply the vector with, third parameter will contain the resulting vector, and the forth parameter indicates the length of the vector.
Parameters: 1st 2nd 3rd 4th
Type: Vector Real Vector Integer
passing: value value variable value
Procedure AddVectors
Adds two vectors and returns the result in a third vector. First and second parameters contain the two vectors to be added, third parameter will contain the result, and the fourth parameter indicates the length of the vectors.
Parameters: 1st 2nd 3rd 4th
Type: Vector Vector Vector Integer
Passing: value value variable value
Procedure SubtractVectors
Subtracts two vectors and returns the result in a third. First and second parameters contain the two vectors to be subtracted, third parameter will contain the result, and the forth parameter indicate the length of the vectors.
Parameters: 1st 2nd 3rd 4th
Type: Vector Vector Vector Integer
Passing: value value variable value

Note:This procedure should not use a loop; it should instead use the AddVectors and MultiplyVectorByNumber procedures.

Procedure MultiplyVectors
Multiplies two vectors and returns the result in a third. First and second parameters contain the two vectors to be multiplied, third parameter will contain the result, and the forth parameter indicate the length of the vectors.
Parameters: 1st 2nd 3rd 4th
Type: Vector Vector Vector Integer
Passing: value value variable value
Function FindSum
Adds up all entries in a vector. First parameter contains the vector, second one indicates the length of the vector. The function must return a real type.
Parameters: 1st 2nd
Type: Vector Integer
Passing: value value
Function FindDotProduct
Finds the sum of the product of the individual entries of two vectors. In other words, first two vectors are multiplied, and then the sum of the resulting vector is returned. First two parameters contain the two vectors, third one indicates the length of the vectors. The function must return a real type.
Parameters: 1st 2nd 3rd
Type: Vector Vector Integer
Passing: value value value

Note:This procedure should not use a loop; it should instead use the MultiplyVectors procedures and FindSum function.

Procedure FindCrossProduct
If the length of the vectors is 3, it finds the crossproduct of two vectors and retuns the result in a third one. Otherwise, it prints an error message. First two parameters contain the input vectors, third one will contain the crossproduct if possible, and the last one indicates the length of the vector.
Parameters: 1st 2nd 3rd 4th
Type: Vector Vector Vector Integer
Passing: value value variable value

Note: The crossproduct of two vectors with three entries is defined as follows:

       / A1 \    / B1 \   / A2*B3 - A3*B2 \
       | A2 | x  | B2 | = | A3*B1 - A1*B3 |
       \ A3 /    \ B3 /   \ A1*B2 - A2*B1 /

The crossproduct is not defined for vectors of lengths different from three.