Question: 1 4 . Run the commands: zeros 5 3 = zeros ( 5 , 3 ) ; ones 4 2 = ones ( 4 ,

14. Run the commands:
zeros53=zeros(5,3);
ones42=ones(4,2);
Variables: zeros53, ones42
Q6: What do the functions zeros and ones do?
15. Generate the diagonal 3\times 3 matrix S with the diagonal elements {1,3,7} using the
Matlab diag function. To learn about diag type help diag in the command line.
Variables: S
16. Now we want to extract the diagonal elements of a matrix and save them in a separate
vector. The same function diag accomplishes that as well. Type
R=rand(5,5)
diagR=diag(R)
This creates a matrix R with random entries from the interval (0,1), extracts the
diagonal entries from it, and saves them in the vector diagR. Observe that the function
diag has other interesting possibilities (use help diag).
Variables: R,diagR
17. Alternatively we can use spdiags. This creates a sparse matrix (with a large number
of zeros), so that Matlab only stores the non-zero entries. To convert sparse form to
dense form, use the command full. Run the following code:
diag121=spdiags([-ones(10,1)2*ones(10,1)-ones(10,1)],[-101],10,10);
full(diag121)
Variables: diag121
Q7: What does this code do?
6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!