Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use amateur level code - java. In this problem, we will code up four functions that can be applied to 2-dimensional arrays (or matrices

image text in transcribedimage text in transcribed

Please use amateur level code - java.

In this problem, we will code up four functions that can be applied to 2-dimensional arrays (or matrices in mathematical term). Given the following 2-D array of double type, {{4.3, 2.7, 8.5, 3.2, 9.8}, {7.4, 5.6, 3.7, 5.8, 1.3}, {9.5, 6.4, 8.1, 4.9, 0.6}, {0.8, 5.7, 2.3, 3.6, 7.8}, {3.9, 6.2, 5.5, 7.8, 2.3} }; All functions and relevant demonstrations should be saved in the file MatrixOp.java. a) Write a function named displayMatrix, which accepts one parameter (a 2D array, i.e., double[][] inputArr). That is, the function header would appear as public static void display Matrix (double[][] inputArr) and display the matrix on your command prompt (in main method) as follows 4.3, 2.7, 8.5, 3.2, 9.8 7.4, 5.6, 3.7, 5.8, 1.3 9.5, 6.4, 8.1, 4.9, 0.6 0.8, 5.7, 2.3, 3.6, 7.8 3.9, 6.2, 5.5, 7.8, 2.3 b) Write a function named rowSum that accepts one 2D array and returns an array of row sum. That is, each element of the returned array should correspond to the sum in each row. The function header would appear as public static double[] rowSum (double[][] inputArr) The correct output would be 28.5, 23.8, 29.5, 20.2, 25.7. Make sure that you print these results in the main method. c) Write a function named colSum that accepts one 2D array and returns an array of column sum. That is, each element of the returned array should correspond to the sum in each column. The function header would appear as public static double[] colSum (double[][] inputArr) The correct output would be 25.9, 26.6, 28.1, 25.3, 21.8. Make sure that you print these results in the main method. d) Write a function named getTrace that accepts one 2D array and returns the trace of the input matrix. Recall that trace of a matrix is defined by summing up all diagonal elements. For instance, the diagonal elements of our sample matrix are 4.3, 5.6, 8.1, 3.6, and 2.3. In terms of 2D array, diagonal elements are those with same row/column indices, i.e., inputArr[i][i]. The function header would appear as public static double getTrace (double[][] inputArr) and the correct result is 23.9. Make sure that you print the trace in the main method. In this problem, we will code up four functions that can be applied to 2-dimensional arrays (or matrices in mathematical term). Given the following 2-D array of double type, {{4.3, 2.7, 8.5, 3.2, 9.8}, {7.4, 5.6, 3.7, 5.8, 1.3}, {9.5, 6.4, 8.1, 4.9, 0.6}, {0.8, 5.7, 2.3, 3.6, 7.8}, {3.9, 6.2, 5.5, 7.8, 2.3} }; All functions and relevant demonstrations should be saved in the file MatrixOp.java. a) Write a function named displayMatrix, which accepts one parameter (a 2D array, i.e., double[][] inputArr). That is, the function header would appear as public static void display Matrix (double[][] inputArr) and display the matrix on your command prompt (in main method) as follows 4.3, 2.7, 8.5, 3.2, 9.8 7.4, 5.6, 3.7, 5.8, 1.3 9.5, 6.4, 8.1, 4.9, 0.6 0.8, 5.7, 2.3, 3.6, 7.8 3.9, 6.2, 5.5, 7.8, 2.3 b) Write a function named rowSum that accepts one 2D array and returns an array of row sum. That is, each element of the returned array should correspond to the sum in each row. The function header would appear as public static double[] rowSum (double[][] inputArr) The correct output would be 28.5, 23.8, 29.5, 20.2, 25.7. Make sure that you print these results in the main method. c) Write a function named colSum that accepts one 2D array and returns an array of column sum. That is, each element of the returned array should correspond to the sum in each column. The function header would appear as public static double[] colSum (double[][] inputArr) The correct output would be 25.9, 26.6, 28.1, 25.3, 21.8. Make sure that you print these results in the main method. d) Write a function named getTrace that accepts one 2D array and returns the trace of the input matrix. Recall that trace of a matrix is defined by summing up all diagonal elements. For instance, the diagonal elements of our sample matrix are 4.3, 5.6, 8.1, 3.6, and 2.3. In terms of 2D array, diagonal elements are those with same row/column indices, i.e., inputArr[i][i]. The function header would appear as public static double getTrace (double[][] inputArr) and the correct result is 23.9. Make sure that you print the trace in the main method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions