/**
* TODO: finish this comment
*/
void addVectors(double a[], double b[], double c[], int length);
/**
* TODO: finish this comment
*/
double dotProduct(double a[], double b[], int length);
Assigned | 10 Jul 2018 @ 16:54h |
Due | 17 Jul 2018 @ 23:59h |
Implement a function to calculate the dot product of two vectors.
It is common in many Engineering problems to represent quantities using vectors rather than scalars. For example, rather than using a scalar speed to represent an object’s motion (e.g., 7.02 m/s), we will often use a vector displacement instead (e.g., $3 \hat{\imath} + 4 \hat{\jmath} + 5 \hat{k} \textrm{ m/s}$). We can apply a few important operations to vectors, including addition and multiplication.
To add two vectors together, we simply add their respective components together. For example, with the three-dimensional co-ordinate system above ($\hat{\imath}$ along the x axis, $\hat{\jmath}$ along the y axis, etc.), vector addition would look like this:
This assumes that the vectors have the same number of components.
There is more than one way to multiply two vectors. The first (and simplest!) way is called the dot product (the other way is called the cross product; we may come back to in in the future). The dot product has an important geometric meaning, but for our purposes in this assignment it is sufficient to know that it is defined as the sum of the products of two vectors' corresponding components. The result is a scalar. For example, using our three-dimensional example above:
For this assignment, you need to:
complete the contract for the two functions declared below by completing each function’s descriptive comment, including any necessary pre-conditions, and
define both functions in a C++ file called assign4.cpp
.
The two functions are declared in assign4.h (which you can download as a starting point for your work):
/**
* TODO: finish this comment
*/
void addVectors(double a[], double b[], double c[], int length);
/**
* TODO: finish this comment
*/
double dotProduct(double a[], double b[], int length);
As always, assignments in this course must be done individually. You can (and are encouraged to!) work together on exercises, but you must do the assignments yourself. If in doubt, come and talk with me.