Question: Just the pseudo code MODEL: the general form of a 2x2 matrix is: ____ | | |_ a11 a12 | | a21 a22 _| example:

Just the pseudo code

MODEL: the general form of a 2x2 matrix is: ____

| | |_

a11 a12 | | a21 a22 _|

example:

| 2.5 -3.7 | | | |_ 4 0 _|

Where:a11, a12, a21, and a22 are real numbers (scalars) that are the COMPONENTS (or ELEMENTS) of the matrix.

OPERATIONS: the following are some of the common operations that are performed on such matrices:

Matrix addition: ______

| a11 a12 | | b11 b12 | | a11+b12 a12+b12 | ||+||=|| |_ a21 a22 _| |_ b21 b22 _| |_ a21 + b21 a22 + b22 _|

Matrix subtraction: ______ | a11 a12 | | b11 b12 | | a11-b12 a12-b12 | ||-||=|| |_ a21 a22 _| |_ b21 b22 _| |_ a21 - b21 a22 - b22 _|

Scalar multiplication:

____ | a11 a12 | | kxa12 kxa12 | kx| |=| | |_ a21 a22 _| |_ k x a21 k x a22 _|

Matrix multiplication: ____ | a11 a12 | | b11 b12 | ||x|| |_ a21 a22 _| |_ b21 b22 _|

__

| a11 x b11 + a12 x b21 a11 x b12 + a12 x b22 | =|| |_ a21 x b11 + a22 +b21 a21 x b12 + a22 + b22 _|

Inverse of a matrix: ____

| A=|

|_ Where:det(A) is a scalar (the determinant of A) computed as:

det(A) = a11 x a22 a21 x a12

a11 a12

| |

a22 / det(A)

-a12 / det(A) | | a11 / det (A) _|

a21 a22

| A-1=| _| |_

-a21 / det(A)

(mathematical note: a matrix has an inverse only if det(A) is not zero. Do not test for this in your program).

In order to implement the MARRIX ADT in a programming language, it is necessary to first select an appropriate DATA STRUCTURE to represent the class. The data structure type name should be: MATRIX (that is, it should be possible to declare variables to be of type MATRIX).

After the data structure has been selected to represent the ADT, it then becomes necessary to design the functions that will implement the corresponding OPERATIONS. Write the complete definition code for the following functions:

get_matrix(name, m);

get_scalar(b); calc_sum(m1, m2, sum); calc_diff(m1, m2, diff); scalar_mult(k, m, k_m); calc_prod(m1, m2, prod); calc_inv(m, m_inv); variable) print_matrix(outfile, name, m);

enables the user to enter ONE matrix name and ONE matrix. enables the user to enter ONE scalar.

computes: computes: computes: computes: computes:

m1 + m2 m1m2 kx m m1 x m2 the inverse of m (the determinant is a local

prints ONE matrix in an appropriate form and a name that identifies it.

Be certain that you make proper use of the data structure: MATRIX. Note that these functions would form the basis of a toolkit for the MATRIX ADT. This toolkit could then be used to quickly write APPLICATION PROGRAMS that involve the use of 2x2 matrices.

Prior to using the MATRIX toolkit in applications programs, each of the functions in it should be tested to be certain that they work properly. Therefore, you are to write a throw away driver program that uses each of the functions in this toolkit. The program should:

  1. Request the user to input two matrices: mq and m2, and their names (for the test run, the names can be just: m1 and m2). This will require TWO SEPARATE calls to the get_matrix function.

  2. Request the user to enter a scalar value.

  3. Compute: m1 + m2, m1 m2, k x m1, m1 x m2, and m1 inverse.

  4. Print out the original two matrices, each of the resulting matrices, and their corresponding

    names (sum, difference, etc.). This will require several separate calls to the print_matrix function.

DIRECTIONS: USE THE FOLLOWING MATRICES AND SCALAR FOR THE SAMPLE RUN:

____

| 7 2.5 | m1 = | | |_ -3.0 2.0 _|

15.0 9.0

sum =

2.0 3.3 __ | 15.0 9.0 | sum= | | |_ 2.0 3.3 _|

Programming Notes 1. Use a STEPWISE MODULAR APPROACH in the development of this program (and all

future programs):

Design and implement ONE FEATURE of the program; then add another feature; continue adding ONE FEATURE at a time until the program is complete.

Example: begin by implementing the following:

get_matrix(name1, m1) get_matrix(name2, m2)

| 8 6.5 | m2 = | | k = 4.5

|_ 5.0 1.3 _| Sample Output: the output form should be similar to either one of the following:

calc_sum(m1, m2, sum)

open_file(outfile) print_matrix(outfile, name1, m1) print_matrix(outfile, name2, m2) print_matrix(outfile, Sum =, sum)close_file(outfile)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!