6b

Advanced Placement

Computer Science Lab

 

 

Matrix Arithmetic Using Arrays

 

 

 

 

Introduction

 

A matrix is a rectangular array of real numbers which are usually called elements of the matrix.  The order of the matrix is the order pair having as the first component the number of rows and as the second component the number of columns.  Thus a 3 x 4 matrix would have 3 rows (horizontal) and 4 columns (vertical) and contain 12 elements.

 

Matrices can be easily represented in Java using two dimensional arrays ( if the matrix has only a single row or column than a one dimensional array can be used).

Page 335 in your text gives you an example of a two-dimensional array.

 

Matrices are useful in a number of applications in applied mathematic including cryptography, solving systems of equations especially systems in which complex models are developed.  Matrix arithmetic is often tedious  and time consuming  and hence it is an ideal task for a computer.

 

 

 

 

Programming Assignment

 

Design a class that has as a default constructor creates two3 x 3 matrix.  These matrices will be used to test the methods in your class.  Include as methods in your class another constructor which allows the user to input two 2 x 2, 3 x 3, or 4 x 4 matrices.  Write methods that then add, transpose and multiply these matrices. Also include an output method.  Use the message dialog boxes.

 

Write a client or driver program that uses the above class. Run the program with each different sized matrix. Turn is a listing of your source code.  Source code should use proper formatting and be fully commented.  Also turn in a copy of your output.  This can be obtained by running the program and then using AltPrintScreen to copy the window of the output onto the clipboard.  Prior to using the Alt-Print Screen, change the background of the window to white and the text to black.  This can be done by clicking on the icon in the upper left hand corner of the output window and going to the properties item in the menu that appears. In the dialog box that appears just change background to white and text or foreground to black.  Then paste the contents of the clipboard into WordPad and print out the document.  In addition to the source code, the output, also turn in the answer to the questions listed below.