Question

In: Computer Science

The command below produces a row vector of 100 random values uniformly distributed between -10 and...

The command below produces a row vector of 100 random values uniformly distributed between -10 and +10.


r = 10.*rand(1,100)-10;

r = 20.*rand(1,100)-10;

r = -10.*rand(1,100)+10;

r = 10.*rand(1,100)-20;

Solutions

Expert Solution

r = 20.*rand(1,100)-10; is the right answer

Explanation

A general formula to produce a row vector of X random values uniformly distributed between some values A and B could be given as:

r = (B-A).*rand(1,X)+A;

in this example consider A = -10 and B = 10

Let's break it down

(1,100) means that the matrix has 1 row and 100 columns, which is nothing but a row vector.

rand function returns real numbers that are between 0 and 1, in a uniform manner.

Why are we multiplying the random number thus generated with 20 and then subtracting it by 10?

By multiplying 20 with the random number thus generated (which is between 0 and 1), we get a random number which is between 0 and 20.

When we subtract this number (which is between 0 and 20) with 10, the result is a number which is between -10 and 10

Example 1:

the rand function generated 0.1

0.1 x 20 = 2

2 -10 = -2

-2 is between -10 and 10

Example 2:

the rand function generated 0.9

0.9 x 20 = 18

18 -10 = 8

8 is between -10 and 10

The first option r = 10.*rand(1,100)-10; seems to be correct for instance.

But it is wrong because it only generates numbers between -10 and 0

We are asked to generate random numbers between -10 and 10

NOTE: rand function does not generate 0 and 1, it only generates the real numbers that fall between them


Related Solutions

Use Excel to generate 100 N (10,5) distributed random values (that is 100 values of a...
Use Excel to generate 100 N (10,5) distributed random values (that is 100 values of a Normally distributed random variable with mean 10 and standard deviation 5). Plot histogram for your data. See Appendix on how to generate these values.
The price of a bond is uniformly distributed between $60 and $100. What is the probability...
The price of a bond is uniformly distributed between $60 and $100. What is the probability that the bond price will be at least $83?          [5 pts.] What is the probability that the bond price will be between $55 to $90? [5 pts.] What is the probability that the bond price will be less than $85? [5 pts.] What is the probability that the bond price will be more than $92.5? [5 pts.] Determine the expected price of the bond....
The price of a bond is uniformly distributed between $60 and $100. What is the probability...
The price of a bond is uniformly distributed between $60 and $100. What is the probability that the bond price will be at least $83?          [5 pts.] What is the probability that the bond price will be between $55 to $90? [5 pts.] What is the probability that the bond price will be less than $85? [5 pts.] What is the probability that the bond price will be more than $92.5? [5 pts.] Determine the expected price of the bond....
The weekly output of a steel mill is a uniformly distributed random variable that lies between...
The weekly output of a steel mill is a uniformly distributed random variable that lies between 110 and 175 metirc tons. 1. Compute the probability that the steel mill will produce more than 150 metric tons next week. 2. Determine the probability that the steel mill will produce between 120 and 160 metric tons next week.
Suppose we have a random variable X that is uniformly distributed between a = 0 and...
Suppose we have a random variable X that is uniformly distributed between a = 0 and b = 100. What is σ X? a. 0.913 b. 0.833 c. 50 d. 7.071
A random variable x is uniformly distributed between 20 and 52 . What is the expected...
A random variable x is uniformly distributed between 20 and 52 . What is the expected value of x?
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a minimum of 2, and a maximum of 18. Obtain the mean and the histogram of these numbers, and discuss whether they appear uniformly distributed with the desired mean.
Consider 4 bidders whose values are independently and uniformly distributed over [0, 10]. (a) What are...
Consider 4 bidders whose values are independently and uniformly distributed over [0, 10]. (a) What are the expected selling prices in a (i) second-price auction, and (ii) first-price auction. (b) Suppose the values of the bidders are 8, 7, 4, and 2. What would be the selling price in a (i) second-price auction, and (ii) first-price auction. (c) Suppose the values of the bidders are 9, 5, 4, and 2. What would be the selling price in a (i) second-price...
Generate 2500 random numbers that are uniformly distributed between 90 and 160. Prove experimentally that STD...
Generate 2500 random numbers that are uniformly distributed between 90 and 160. Prove experimentally that STD of sample means = STD of Population/sqrt(sample size) for sample sizes of 10 and 100. How close is your calculation of STD of sample means to the theoretical approximation? Keep number of samples in each case equal to sample size. Repeat for normal and weibull (also between 90 and 160). What does it say about STD of sample means as you increase your sample...
Write a C++ program that 1) generates a vector containing 10 different random integers with values...
Write a C++ program that 1) generates a vector containing 10 different random integers with values between 1 and 100, then 2) calculates the average value in that vector in floating point format with 1 decimal place. Output the vector values and the average value to cout. Your program output should look like this: Vector values: 3, 78, 55, 37, 8, 17, 43, 60, 94, 1 Average value: 39.6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT