Typing G outputs the content of G in one column format d What do you get if you

Typing g outputs the content of g in one column

  • Arizona State University
  • MAT 343
  • Lab Report
  • xdonsquared
  • 10
  • 100% (41) 41 out of 41 people found this document helpful

This preview shows page 5 - 8 out of 10 pages.

Typing G(:) outputs the content of G in one column format. d) What do you get if you type G(7) and hit return? Can you explain how MATLAB got that answer? Try G(16) to confirm your answer. ans = 6 Typing G (7) outputs the 7 th element of G in the column or in row/column format it s G(1,2) G(16) ans = 3 Typing G (16) outputs the 16 th element of G in the column or in row/column format it ’s G(4,3) e) What happens if you type G(12,1) and hit return? ANSWERS: G(12,1) Index exceeds matrix dimensions. Typing G (12,1) Matlab outputs Index exceeds matrix dimensions. G on has 6 rows, the 12 gave the error. f) What happens if you type G(G>5) and hit return? Can you explain how MATLAB got that answer? What happens if you type G(G>5) = 100 and hit return? Can you explain how MATLAB got that answer? ANSWERS: G(G>5) ans = 6 9 Typing G (G>5) Matlab outputs the elements of G that are greater than 5. G(G>5) = 100 G = 2 100 0 0 1 0 3 100 0 0 0 1 0 0 1 2 0 0 0 0 3 4 0 0 1 0 0 0 4 5
Image of page 5
0 1 0 0 5 3 Typing G (G>5) = 100, Matlab find elements that are greater than 5 and replace that 5 then outputs G with the replaced G>5 with 100. 6. See the structure of a matrix: Create a 20 × 20 matrix with the command A = ones(20); Now replace the 10 × 10 submatrix between rows 6:15 and columns 6:15 with zeros. See the structure of the matrix (in terms of nonzero entries) with the command spy(A). Set the 5 × 5 submatrices in the top right corner and bottom left 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. ANSWERS: A = ones(20), creates 20x20 matrix with elements of ones B = zeros(20), creates 20x20 matrix with elements of zeros A(6:15,6:15) = B(6:15,6:15), creates 10x10 submatrix and inserted to A: See Figure 1. FIGURE 1: A(16:20,16:20) = B(16:20,16:20) and A(1:5,1:5) = B(1:5,1:5), creates 5x5 submatrix top- right and bottom-left with zeros elements. See figure 2.
Image of page 6
FIGURE 2: 7. Create a symmetric matrix: Create an upper triangular matrix with the following command:
Image of page 7
Image of page 8

You've reached the end of your free preview.

Want to read all 10 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture