Exercise 3

1 Checking Orthogonal Vectors

Write a function, scalarProduct, that calculates the scalar product of two arbitrary vectors (u1, u2, u3, ..., un) and (v1, v2, v3, ... , vn). The result should be: u1*v1 + u2*v2 + ... + un*vn.

Two vectors (u1, u2, u3, ..., un) and (v1, v2, v3, ... , vn) are ortogonal if the scalar product: is equal to 0.
Write a class,
Orthogonal, that decides if two integer vectors are orthogonal. The vectors must have the same number of elements, but the number of elements should be arbitrary.

1.1 Hint

Applying the multiplication operator between two vectors gives the scalar product.


1.2.1 scalarProduct

First we check if the vectors are of the same size and if they are we calculate the scalar product.

Call it:

1.2.2 Orthogonal

1.2.3 Simulation of Orthogonal

Since the value in the variable orthogonal is 1 the two vectors are orthogonal.

Check the value.