Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started