Question
Use MATLAB help lo find a command which can generate a matrix with random real entries between 0 and I (just mention the function) b) Use MATLAB help to find a command which rounds a number to its nearest integer, (just mention the function) Use the linspace and logspace functions to create vectors identical to the following: (a) x_l =0: 1: 20 (c) x_3= 10.^(l: l: 6) (d) Explain the main difference in the required input between colon notation and the linspace function when creating a vector that spans the interval (a, b) and has n elements with a step size h. such that (n-1) = (b-a)/h. Use the ones and zeros functions to create the following vectors: (a) x_1 =[1 1 1 1 l] (b) x_2 = [0 0 0 0] C)x^4= [-2 -2 -2]
Explanation / Answer
Ans(1.a):
rand( ) function generates random numbers between 0 and 1.
we need matrix so we use rand(N) which generates NxN matrix of random numbers.
-----------------------
Ans(1.b):
floor( ) command can be used to round the random numbers to nearest integer. For example, floor(8.734) is 8.