Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask MATLAB Expert

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.

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M91583432
  • Price:- $180

Guranteed 48 Hours Delivery, In Price:- $180

Have any Question?


Related Questions in MATLAB

Assignment -matlab codes and simulated model in

Assignment - Matlab codes and simulated model in simulink/matlab and truetime. 1. Matlab codes and simulink model for pid controller optimization using particle swarm optimization (PSO) my plant is integer order 1000/(s^ ...

Prepare a 3 - 10 pages long reportprepare a presentation

Prepare a 3 - 10 pages long report Prepare a presentation with 5 - 9 slides. The slides will include introduction (need and similar work), theoretical background (tested neural networks), Data, Results (Comparison of the ...

Assignmentq1 find the laplace transforms of the following

Assignment Q.1 Find the Laplace transforms of the following functions: (a) t 2 + at + b and (b) sin(2nΠt/T) Q.2 Find f (t) for the following F(s) = α[ f (t)]. (i) 5/(s + 3), (ii) 1/s 2 + 25, (iii) 1/s(s+1) Q.3 Find the L ...

Question 1 manipulate spectral imagehyperspectral images

Question 1. Manipulate spectral image Hyperspectral images can be seen as a generalisation of normal colour images such as RGB images. In a normal RGB colour image, there are 3 channels, i.e. channels for red colour, gre ...

Assignment -we have daily gridded rainfall data of 40 years

Assignment - We have daily gridded rainfall data of 40 years and structure of the dataset is like below; Lat = [6.5:0.25:38.5]; Lon = [66.5:0.25:100]; Rainfall (135x129x365x40) (Lon, Lat, days, years). Now, we looking fo ...

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Recitation problems -1 determine the highest real root of

Recitation Problems - 1. Determine the highest real root of f(x) = 2x 3 - 11.7x 2 + 17.7x - 5 using the Newton-Raphson method with at least four iterations. Start with an initial guess of x 0 = 3. 2. Determine the real r ...

Assignment matlab programmingusing appropriate matlab

Assignment: MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

What comparison of means test was used to answer the

What comparison of means test was used to answer the question

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As