Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

1. What are the pros and cons of diversity for an organisation?

Answered: 1 week ago

Question

1. Explain the concept of diversity and equality in the workplace.

Answered: 1 week ago