Matlab continuous uniform distribution

AI Thread Summary
To generate 100 data points from a continuous uniform distribution with a mean of 10 and a variance of 4, the equations for the mean and variance are used to derive the limits a and b. The mean is calculated as u = (a+b)/2, and the variance as var = (b-a)^2 / 12. The code attempts to solve these equations symbolically for a and b, but the user reports that the polynomial solver is not producing usable values for 'r'. This issue prevents the successful generation of the random data points. The discussion centers around troubleshooting the code to ensure correct implementation of the uniform distribution.
freezer
Messages
75
Reaction score
0

Homework Statement


Generate 100 data points from a continuous uniform distribution with mean = 10 and variance = 4


Homework Equations



u = (a+b)/2

var = (b-a)^2 / 12

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


The Attempt at a Solution



Code:
points = 100

m1 = 10
v1 = 4

syms a b 
[a, b] = solve( (a+b) == 2*m1,(b-a)^2 == 12 *v1)

 
r = a + (b-a).*rand(points, 1);
 
Physics news on Phys.org
freezer said:

Homework Statement


Generate 100 data points from a continuous uniform distribution with mean = 10 and variance = 4


Homework Equations



u = (a+b)/2

var = (b-a)^2 / 12

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


The Attempt at a Solution



Code:
points = 100

m1 = 10
v1 = 4

syms a b 
[a, b] = solve( (a+b) == 2*m1,(b-a)^2 == 12 *v1)

 
r = a + (b-a).*rand(points, 1);

Do you have a question?
 
Oh yea... sorry.

So my code is not working. The poly solver is not generating numbers that i can us in 'r'.
 

Similar threads

Back
Top