Overview
This lab will give you more practice using variables and outputting their values as well. In addition, you will gain some exposure to some simple linear algebra concepts.
Background
A vector is composed of three decimal numbers that correspond to the x, y, and z positions of a point in Cartesian space. Two vectors can be added or subtracted with one another. Or, a vector may be multiplied or divided by a single decimal digit. The operations are defined as follows:
Addition
Vector 1 = [ x1, y1, z1 ]
Vector 2 = [ x2, y2, z2 ]
Vector result = [ (x1 + x2), (y1 + y2), (z1 + z2) ]
Subtraction
Vector 1 = [ x1, y1, z1 ]
Vector 2 = [ x2, y2, z2 ]
Vector result = [ (x1 - x2), (y1 - y2), (z1 - z2) ]
Multiplication
Vector 1 = [ x1, y1, z1 ]
Scalar s = (any number)
Vector result = [ (x1 * s), (y1 * s), (z1 * s) ]
Example: [ 1, 2, 3 ] * 3 = [ 3, 6, 9 ]
Division
Vector 1 = [ x1, y1, z1 ]
Scalar s = (any number that is not zero)
Vector result = [ (x1 / s), (y1 / s), (z1 / s) ]
Example: [ 9, 12, 15 ] / 3 = [ 3, 4, 5 ]
Assignment
Perform the following vector arithmetic operations using the given input values and output the results.
Vector 1 = [ 1.0, 2.0, 3.0 ]
Vector 2 = [ 4.0, 5.0, 6.0 ]
Scalar s = 5.0
Addition: Vector 1 + Vector 2
Subtraction: Vector 1 - Vector 2
Multiplication: Vector 1 * scalar
Division: Vector 2 / scalar
Example output:
David Whittinghill
Lab 05
[1.0, 2.0, 3.0] + [4.0, 5.0, 6.0] = [5.0, 7.0, 9.0]
[1.0, 2.0, 3.0] - [4.0, 5.0, 6.0] = [-3.0, -3.0, -3.0]
[1.0, 2.0, 3.0] * 5.0 = [5.0, 10.0, 15.0]
[4.0, 5.0, 6.0] / 5.0 = [0.8, 1.0, 1.2]
Grading
You will be graded on the correctness of your calculations, the readability of your code and of your output. You may not use any API objects or calls other than println.
|