logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

 If you are using Python, you have to implement the Matrix class by yourself, you may not use any existing libraries.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Update1:

 If you are using Python, you have to implement the Matrix class by yourself, you may not use any existing libraries.

If you are using C++, use a double datatype (instead of float) for your matrices that will store floating point values, as it can help you to distinguish between int and double matrices. You can have two functions in your generic class to tell if a particular matrix instance is using int or double. If your template type is T, following functions in your generic class can help tell that.

bool isInt(){ return sizeof(T) == sizeof(int);}

bool isDouble{return sizeof(T) == sizeof(double);}

Note that this is not the best solution to know the actual types for the template type, but should work for our purposes.

As for Python, you can use isinstance() to tell between int and float. E.g. call isinstance(variable_name,int) or isinstance(variable_name,float).

Update2:

 Instead of ! operator, please use – (unary minus) for matrix inverse. The document has been updated to replace ! with -.

When we create a matrix using matrix_name = [ semicolon separated row values ], all the values will either be integers or floating points, but never mixed. So it would be either A = [1 2 3 4; 5 6 7 8;] or A

= [1.4 2.3 3.1 4.9; 5.2 6.0 7.4 8.1;].

If A and B are both integer matrices, the result of A + B should be an integer matrix. If they are both floating point, the result should be floating point. Same applies for other binary operations (that require another matrix parameter). Because the Matrix class is generic, a matrix should only be able to accept another matrix of the same type as a parameter. So in order to add two matrices where one is integer and the other is floating point, first you will have to create a new floating point matrix with the same values of the integer matrix but promoted to floating points and then add the matrices.

e.g. if A is integer and B is floating point and the command is A + B.

First you will create a temp matrix, let’s call it C, that has A’s values promoted to floating point. Then do the addition by doing C + B.

You have to write your own generic class (whether you are coding in Python or C++). By a generic class we mean that the datatype for the matrix values will be generic. Other members, such as dimensions will be regular data types (e.g. int for number of rows and number of columns). The instance

methods of the class (including those which overload operators) should be generic, which means if they accept another Matrix object as a parameter, that matrix should be of the (same) generic type.

Description:

 MatShell: A shell/program for high-school students to solve questions involving matrices. It will be a MATLAB like tool (although extremely limited in its capability and scope).

Details:

 The program will behave like an interactive shell where the user can give commands (related to matrices) and see the results. Alternatively, the commands may be written in a script (with .msh extension) which can be passed as a command line argument. If a script is provided, the program will run all the commands given in the script, display corresponding results, and exit. If no script is provided as a command line option, it will enter into the interactive shell mode, where it will wait for user to type a command. For each typed command, it will display a result and wait for the next command. It will remain active until a command to exit the shell is given by the user. MatShell should be able to handle matrices of any size. Following commands are supported:

Command:

  • matrix_name = [ matrix values provided as rows separated by semicolons ]

A matrix can be created by providing a name, equal sign, and values of the matrix provided in rows separated by semicolons and enclosed in square brackets. The name of a matrix can only be composed of one or more letters e.g. A and First are valid names but Mat1 is not. The program should internally create a matrix with provided values and remember its name, as it would be used later by the user in other commands. The program should also print the matrix as a signal to user that it got the matrix and is ready for the next command. (Note that this is not really a command but a way to create a matrix.)

The following is how we can create a 2x4 matrix A. A = [1 2 3 4; 5 6 7 8;]

The program will print the following as soon as the user provides the above command and presses enter.

A =

1

2

3

4

5

6

7

8

Note that the printed matrix is nicely formatted.

  • size matrix_name

size command will print the size of the matrix matrix_name as number of rows x number of columns.

Example: (Note A was declared above.)

size A

ans = 4 x 2

  • isRow matrix_name

isRow command will print yes if the given matrix matrix_name is a row matrix (has a single row), otherwise no.

Example:

isRow A ans = no

  • isColumn matrix_name

isColumn command will print yes if the given matrix matrix_name is a column matrix (has a single column), otherwise no.

Example:

isColumn A ans = no

  • isRectangular matrix_name

isRectangular command will print yes if the given matrix matrix_name is a rectangular matrix (number of rows and number of columns are different), otherwise no.

Example:

isRectangular A ans = yes

  • isSquare matrix_name

isSquare command will print yes if the given matrix matrix_name is a square matrix (number of rows and number of columns are equal), otherwise no.

Example:

isSquare A ans = no

  • isDiagonal matrix_name

isDiagonal command will print yes if the given matrix matrix_name is a square matrix whose all non-diagonal elements are 0, otherwise no.

Example:

B = [1 2 3; 4 5 6; 7 8 9;] B =

1         2         3

4         5         6

7         8         9

isDiagonal B ans = no

C = [2 0; 0 5;] C =

2         0

0         5

isDiagonal C

ans = yes

  • isScalar matrix_name

isScalar command will print yes if the given matrix matrix_name is a diagonal matrix whose all diagonal elements are equal to some non-zero constant, otherwise no.

Example: isScalar C ans = no

D = [2 0; 0 2;] D =

2         0

0         2

isScalar D ans = yes

  • isIdentity matrix_name

isIdentity command will print yes if the given matrix matrix_name is a diagonal matrix whose all diagonal elements are equal to 1, otherwise no.

Example: isIdentity D ans = no

E = [1 0 0; 0 1 0; 0 0 1;] B =

1         0         0

0         1         0

0         0         1

isIdentity E ans = yes

  • isUpperTriangular matrix_name

isUpperTriangular command will print yes if the given matrix matrix_name is a square matrix whose all elements below the diagonal are 0, otherwise no.

Example:

isUpperTriangular E ans = yes

  • isLowerTriangular matrix_name

isLowerTriangular command will print yes if the given matrix matrix_name is a square matrix whose all elements above the diagonal are 0, otherwise no.

Example:

isLowerTriangular E ans = yes

  • isNull matrix_name

isNull command will print yes if all the elements of the given matrix matrix_name are 0, otherwise no.

Example:

 

isNull E ans = no

  • isSymmetric matrix_name

isSymmetric command will print yes if the given matrix matrix_name is symmetric, otherwise no. A symmetric matrix is a square matrix whose transpose is the same as the matrix itself (A’ = A).

Example:

isSymmetric E ans = yes

  • isSkewSymmetric matrix_name

isSkewSymmetric command will print yes if the given matrix matrix_name is skew- symmetric, otherwise no. A skew-symmetric matrix is a square matrix whose transpose is the same as the negative of the matrix. (A’ = -A)

Example:

isSkewSymmetric E ans = no

  • areEqual matrix_nameA matrix_nameB

areEqual command is followed by two matrix names; it prints yes if both matrices are the same size and their corresponding elements are the same, otherwise no.

Example:

areEqual A B ans = no

  • det matrix_name

det command prints the determinant of the provided matrix matrix_name if it is a square matrix, otherwise it prints an error message “Error: It is not a square matrix”. Example:

det A

ans = Error: It is not a square matrix. det B

ans = 0

F = [1 2 3; 2 5 4; 4 3 2;] F =

1

2

3

2

5

4

4

3

2

det F

 

 

ans = -20

  • isSingular matrix_name

isSingular command prints yes if the determinant of the provided matrix matrix_name is

  1. It prints no if the determinant is non-zero and prints an error message “Error: It is not a square matrix” if it is not a square matrix.

Example:

18)   exit

isSingular A

ans = Error: It is not a square matrix. isSingular B

ans = yes isSingular F ans = no

This command will make the interactive shell stop executing.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

503 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

802 Answers

Hire Me
expert
Husnain SaeedComputer science

515 Answers

Hire Me
expert
Atharva PatilComputer science

921 Answers

Hire Me

Get Free Quote!

347 Experts Online