Matlab program to demonstrate common matrix operations

Assignment Help MATLAB Programming
Reference no: EM13910503

Write a Matlab program to demonstrate common matrix operations:

Option 1: Matrix addition and element by element multiplication (verify that dimensions are the same)

Option 2: Matrix multiplication (verify that the number of columns of matrix 1 is equal to the number of rows of matrix2)

Option 3: Transpose of a matrix

Option 4: Determinant and inverse of a matrix (display message "Singular matrix" if determinant is less than 1.0 times 10 to the minus tenth power)

Option 5: Identity, ones, zeros, random matrices (for identity matrix, create square matrix, only use number of rows (n) to create n by n matrix)

See the example output below Match that output. Note:

  • Stay in a while loop until the user enters option 0

  • If the user enters an option that is an invalid option, display:

      option: 6 is invalid

  • See checks listed below, and illustrated in the example output

This is sample output to the command window when you execute a correct program using the matrices in the matrix.mat file:

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 1

Perform matrix addition, element by element multiplication

Enter matrix 1: o1a

Enter matrix 2: o1b

matrix_add =

matrix_add =

2          0          3

3          2          4

3          5          2

matrix_mult =

1          0          2

2          1          4

0          6          1

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 1

Perform matrix addition, element by element multiplication

Enter matrix 1: o1a

Enter matrix 2: o1c

Dimensions do not match

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 2

Perform matrix multiplication

Enter matrix 1: o2a

Enter matrix 2: o2b

matrix_mult =

4          1

10        3

7          2

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 2

Perform matrix multiplication

Enter matrix 1: o2a

Enter matrix 2: o2c

Inner matrix dimensions must agree

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 3

Transpose a matrix

Enter matrix: o3a

transpose =

1          1

2          0

2          1

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 4

Calculate determinant and inverse of a matrix

Enter matrix: o4a

determinant =

-2

inverse =

-1.0000 0.5000 1.0000

0          0.5000          0

2.0000 -1.5000 -1.0000

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 4

Calculate determinant and inverse of a matrix

Enter matrix: o4b

Singular matrix no inverse

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 5

Create identity, ones, zeros, random matrices

Enter number of rows: 3

Enter number of columns: 2

identity_matrix =

1          0          0

0          1          0

0          0          1

ones_matrix =

1          1

1          1

1          1

 

zeros_matrix =

0          0

0          0

0          0

random_matrix =

0.6948          0.0344

0.3171          0.4387

0.9502          0.3816

Matrix options:

1 add, element multiplication, 2 multiply

3 transpose,4 determinant

5 identity, ones, zeros, random matrices, 0 end program

Enter matrix option: 6

option: 6 is invalid

Enter matrix option: 0

Matrix program ended

Program Requirements

Error checking

Note the error checking in the example output:

  • For Option 1, check that the dimensions match

  • For Option 2, check that the inner matrix dimensions agree (columns of matrix 1 = rows of matrix 2)

  • For Option 3, check that the matrix is not singular: if the absolute value of the determinant is less than 1.0e-10 it is singular. If singular, the inverse is not calculated.

  • Check that the user entered a valid option (integer from 0 through 5). You can assume that the user will enter an integer.

  • Stay in a loop asking for a user option until the user enters 0 for the option. See the example output.

Function to get option

Use a function to get the option. Stay in a loop in the function until the user enters, 0 through 5 (you can assume that the user will enter an integer). The function does not get any parameters from the script, and returns the option (1 through 5) to the script.

Reference no: EM13910503

Questions Cloud

Wireless technologies and mobile technologies : Define wireless technologies and mobile technologies. Next, determine at least three (3) ways which companies or organizations utilize such technologies to improve business efficiency.Determine the wireless technologies and mobile technologies that D..
Calculate their average speed : Szymon and Chris fly their balloon around the earth in 80 days. Taking the radius of the earth to be 6400 km, calculate their average speed in m/s
Industrial growth of the late 1800''s have on urban living : What effect did the industrial growth of the late 1800's have on urban living?
Initial temperature of the copper : If 32.7 cal of heat is removed from 17.8 g of copper, the temperature decreased to 15.2 oC. What was the initial temperature of the copper? (The specific heat of copper is 0.0908 cal/(g oC))
Matlab program to demonstrate common matrix operations : Write a Matlab program to demonstrate common matrix operations - Matrix addition and element by element multiplication and Matrix multiplication.
Analyze the development of t2d in the u.s : Analyze the development of T2D in the U.S
Consider the balanced reaction : Consider the balanced reaction between Cu and nitric acid shown below. If 1.55 g of Cu (NO3)2 (MW = 187.6 g/mol) was obtained from the reaction of 0.95 g of Cu (MW = 63.55 g/mol) with excess HNO3, what is the percent yield of the reaction?
What s the soldier' rebellion : What' s the soldier's rebellion, and the shortcomings of US military intervention in Vietnam War? Be specific
World systems theory : World Systems Theory, what is it? Hegemony, what is it? why is it important? Why does depression happen? How did FDR's New Deal respond to the economic crisis.Know WWII and the ways in which it transformed the American economy and the nation's standi..

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Finite difference method

Use the finite difference method to calculate the temperature at the point specified since it is easier.

  Determine the necessary shell temperature

In a shell-and-tube heat exchanger, one fluid passes through a central tube while another fluid flows through an outer shell in the opposite direction. The purpose is to heat the fluid passing through the central tube.

  Find the integral of a function at an arbitrary location

Write a Matlab function to perform numerical integration of a set of evenly spaced data points using the trapezoidal rule

  Compute the speed of single-stage planetary gear train

Write a MATLAB function [speed] = planetary (N, emesh, first, last, arm) that computes the speed of a given link in a single-stage planetary gear train.

  Calculate and plot the error in the numerical derivative

Write a program to calculate and plot the error in the numerical estimate of the derivative.

  Create the graph using matlab functions

Create the graph, which contains a piecewise function where a line exists in the first interval, a parabola in the second interval, and the sine function in the third interval.

  Develop a simulation program

Develop a simulation program

  Create a vector in matlab

Create a three dimensional diagram of function.

  Open a named pipe and to read data from the pipe

Open a named pipe and to read data from the pipe in matlab

  Write the commands that will create the matrix

Write the commands that will create the matrix.

  Lagrange interpolating polynomial of degree

Lagrange interpolating polynomial of degree

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd