Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Matlab script to choose from the rand), round), fix(), ceil), floor), an

ID: 2248191 • Letter: W

Question

Write a Matlab script to choose from the rand), round), fix(), ceil), floor), and hist) functions (no other functions are allowed) to generate (a) a vector of 100000 random real numbers uniform in the range from 50 to 100. Show histogram in 20 bins. (b) a vector of 100000 random integers in the range from 20 to 50. Show histogram in 31 bins. (c) a vector of 100000 random integers, either 1's or 0's. But l's will occur roughly 70% of the time. Show histogram in 2 bins. (d) a vector of 100000 random integers containing 2 for 30% of the time, 6 for 20% of the time, and 9 for 50% of the time. Show histogram in 8 bins.

Explanation / Answer

(a)

Create a vector of 10000 random values. Use the rand function to draw the values from a uniform distribution in the open interval, (50,100).

Verify the values in r are within the specified range.

(b)

To get an integer from a floating point value we can use functions such as round or ceil or floor. The round function returns the nearest integer, ceil the next higher integer, and floor, the next lower integer. Thus ceil of 20.001 is 20 and ceil of 19.999 is also 20. round of 20.001 is 20 and round of 19.999 is 20.

A = Constant 1;
          M = Constant 2;

Q = M / A;
          R = M % A;

          number = ( A * (number mod Q)    ) -
                   ( R * floor(number / Q) );

if (number is negative)
            number = number + M;
          end

(c)

x = ceil(rand() * 1);

(d)randomIntergers = floor(a + (b-a+1) .* rand(30,2));

randomIntergers = floor(a + (b-a+1) .* rand(20,6));

randomIntergers = floor(a + (b-a+1) .* rand(50,8));

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote