Question: Using MATLAB language. Create matrices with zeros, eye, ones, and triu: Create the following matrices with the help of the matrix generation functions zeros, eye,
Using MATLAB language.
Create matrices with zeros, eye, ones, and triu: Create the following matrices with the help of the matrix generation functions zeros, eye, ones, and triu. See the on-line help on these functions if required (i.e. help eye)
M=[2 0 0
0 2 0
0 0 2]
N=[0 0
0 0]
,P=[3 3 3
0 3 3
0 0 3]
,Q=[4 4 4
4 4 4]
Create a big matrix with submatrices:
The following matrix G is created by putting matrices A, B, and C from Exercise 1, on its diagonal and inserting 22 zeros matrices and 22 identity matrices in the appropriate position. Create the matrix using submatrices A, B , C, zeros and eye (that is, you are not allowed to enter the numbers explicitly).
G= [1 2 1 0 0 0
3 6 0 1 0 0
0 0 2 3 1 0
0 0 1 4 0 1
1 0 0 0 2 1
0 1 0 0 3 2]
5.
Manipulate a matrix:
Do the following operations on matrix G created above in Problem 4.
(a) Extract the first 33 submatrix from G and store it in the matrix H, that is, create a matrix
H =[1 2 1
3 6 0
0 0 2]
by extracting the appropriate rows and columns from the matrix G.
(b) Create the matrix E obtained from H by replacing E33 = 2 by 5. Do not enter Eexplicitly.
Hint: enter first E=H; to create copy of the matrix H and then manipulate the matrix E
.
(c) Create the matrix F obtained by deleting the second row of the matrix H. Do not enter F explicitly.
(d) What happens if you type G(:,:) and hit return? Do not include the output in your lab report, but include a statement describing the output in words.
What happens if you type G(:) and hit return? Do not include the output in your lab report, but include a statement describing the output in words.
(e) What do you get if you type
G(8) and hit return? Can you explain how MATLAB got that answer? Try G(16) to confirm your answer.
(f) What happens if you type G(10,1) and hit return? Explain. (g) What happens if you type G(G>2) and hit return? Can you explain how MATLAB got that answer? What happens if you type G(G>2) = 50 and hit return? Can you explain how MATLAB got that answer?
6.
See the structure of a matrix: Create a 2525 matrix with the command A = ones(25); Now replace the 55 submatrix between rows 11:15 and columns 11:15 with zeros. See the structure of the matrix (in terms of nonzero entries) with the command spy(A). Set the 55 submatrices in the top left corner and bottom right corner to zeros and see the structure again.
NOTE: Use semicolon to suppress the output for all the matrices in this problem. In your lab- write up include the pictures obtained with the spy command. To include the pictures, open your diary file using a word processor such as MS Word then, on the MATLAB figure, select Edit and Copy Figure, and paste the picture into the Word file. Make sure you crop and resize the picture so that it does not take up too much space.
7. Create a symmetric matrix: Create an upper triangular matrix with the following command: A = diag(1:6) + diag(7:11, 1) + diag(12:15, 2) Make sure you understand how this command works (see the on-line help on diag). Now use the upper off-diagonal terms of A to make A a symmetric matrix with the following command: A = A + triu(A,1) This command takes the upper triangular part of A above the main diagonal, flips it (transpose), and adds to the original matrix A, thus creating a symmetric matrix A. See the on-line help on triu
.
8.
Perform row operations:
Enter the following matrix:
A=[1 2 3
4 5 6
7 8 9]
(a) Enter the following command in MATLAB:
A(2,:)=A(2,:)-4*A(1,:)
This command performs an elementary row operation on the matrix A. Describe the row operation.
(b) On the matrix obtained in part (a), use MATLAB to perform a row operation that subtracts
7 times the first row from the third row.
(c) On the matrix obtained in part (b), divide the second row by 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
