Question: 1 4 . Run the commands: zeros 5 3 = zeros ( 5 , 3 ) ; ones 4 2 = ones ( 4 ,
Run the commands:
zeroszeros;
onesones;
Variables: zeros ones
Q: What do the functions zeros and ones do
Generate the diagonal times matrix S with the diagonal elements using the
Matlab diag function. To learn about diag type help diag in the command line.
Variables: S
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
Rrand
diagRdiagR
This creates a matrix R with random entries from the interval 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: RdiagR
Alternatively we can use spdiags. This creates a sparse matrix with a large number
of zeros so that Matlab only stores the nonzero entries. To convert sparse form to
dense form, use the command full. Run the following code:
diagspdiagsonesonesones;
fulldiag
Variables: diag
Q: What does this code do
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
