OverviewThe intent of this program is to give you experience using arrays, which is a data type that stores multiple pieces of data.Learning ObjectivesBe able to create and use an array type.Be able...

1 answer below »



Overview




The intent of this program is to give you experience using arrays, which is a data type that stores multiple pieces of data.








Learning Objectives







  • Be able to create and use an array type.



  • Be able to use an array type.



  • Be able to pass an array type as a parameter.



  • Be able to return an array type as a return value.



  • Start thinking algorithmically to calculate a result.










Assignment




You will input from the user a 3x3 matrix and a vector, hence requiring two arrays: matrix and vector. After inputting 12 values (9 for the matrix and 3 for the vector), you will multiply the vector by the matrix, which produces vector result.




A matrix multiplied with a vector will produce a vector like the example below.













[m00 m01 m02m10 m11 m12m20 m21 m22]×[v0v1v2]=[m00 × v0+m01 × v1+m02 × v2m10 × v0+m11 × v1+m12 × v2m20 × v0+m21 × v1+m22 × v2]" role="presentation" style="display: inline-block; line-height: normal; font-size: 16px; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">[m00m01m02m10m11m12m20m21m22]×[v0v1v2]=[m00×v0+m01×v1+m02×v2m10×v0+m11×v1+m12×v2m20×v0+m21×v1+m22×v2]











You can see that we will get a vector (array) with three elements.




The matrix isrow major, meaning that matrix[0] is m00, matrix[1] is m01, matrix[2] is m02, matrix[3] is m10, matrix[4] is m11, and so forth. Conceptually, the matrix has 3 rows and 3 columns, however using a single dimension, we flatten it out as: [ m00 m01 m02 m10 m11 m12 m20 m21 m22 ].




For example,













[1.0 2.0 3.04.0 5.0 6.07.0 8.0 9.0]×[10.020.030.0]=[1.0× 10.0+2.0× 20.0+3.0× 30.04.0× 10.0+5.0× 20.0+6.0× 30.07.0× 10.0+8.0× 20.0+9.0× 30.0]=[10.0+40.0+90.040.0+100.0+180.070.0+160.0+270.0]=[140.0320.0500.0]" role="presentation" style="display: inline-block; line-height: normal; font-size: 16px; text-align: left; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; position: relative;">[1.02.03.04.05.06.07.08.09.0]×[10.020.030.0]=[1.0×10.0+2.0×20.0+3.0×30.04.0×10.0+5.0×20.0+6.0×30.07.0×10.0+8.0×20.0+9.0×30.0]=[10.0+40.0+90.040.0+100.0+180.070.0+160.0+270.0]=[140.0320.0500.0]











As you can see, the result of a 3x3 matrix multiplied by a 3x1 vector is a 3x1 vector.








Template




Use the following code in a file called arrays.java. Do not change the template. Only modify the template where there is a TODO comment. You must ensure that all output matches the sample outputs.




Hints and Restrictions







  • You do not need to error check any of the values coming into your code or the number of values. Assume the user will input the data correctly.



  • You MUST use two for loops for the matrix math. The outer for loop loops through each row of the matrix and the inner for loop loops through each column.



  • The private final static int VECTOR_SIZE and MATRIX_SIZE are essentially global constants. Remember, the keyword 'final' means that we cannot change its value.



  • Do NOT hardcode any values, such as 9 or 3.The graders must be able to change VECTOR_SIZE and MATRIX_SIZE and still have your code function properly!This will not function properly if you hardcode 9 or 3 instead of using the constants. This means, if you are tempted to write a literal "9" or a "3" in your code somewhere, think about a variable name you can use instead (i.e. VECTOR_SIZE and MATRIX_SIZE).





  • Your printVector for loop must NOT have any if statements within it. Instead, you must think about how many of the values need to be printed with spaces (all except the last) and how many don't (the last one). Print with three digits of precision.



  • You are permitted to add iterators for your loop. Otherwise, you should not need to declare additional variables aside from what is specified in the TODO statements.













Answered Same DayNov 30, 2022

Answer To: OverviewThe intent of this program is to give you experience using arrays, which is a data type that...

Vikas answered on Dec 01 2022
38 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here