| Thread Closed |
MATLAB for uniform random variables |
Share Thread |
| May4-10, 03:18 PM | #1 |
|
|
MATLAB for uniform random variables
1. The problem statement, all variables and given/known data
Given 2 independent uniform random variables X,Y = U [0,1], consider the random variables Z = g (X,Y) for g = (x,y) = sqrt (-2ln(x) . cos(2piy). Since finding the distribution of g(X,Y) analytically is quite tough, I need to generate MATLAB program for 1 - 10,000 uniformly distributed random samples for X and Y 2 - For each sample of X and Y, compute Z= g(X,Y) 3 - Draw a histogram over the resulting samples in Z 4 - Estimate the moments mZ for n = 1,2....6. 3. The attempt at a solution I tried for the first solution and I'm hopelessly stuck. MATLAB gives me an error saying "Attempted to access (0,1); index must be a positive integer or logical." I don't understand where I'm going wrong. Please help! |
| May4-10, 03:38 PM | #2 |
|
|
Please post exactly what Matlab command you have typed which produces that error.
|
| May4-10, 03:48 PM | #3 |
|
|
I tried to put the formula into MATLAB and this was my program
x= 0; >> y= 1; >> rand (1, 1000); >> g= sqrt((-2*log(x)) * cos((2*pi*y))); >> plot(g) Actually, for this, I get a blank plot. Please point out the mistake. |
| May4-10, 05:03 PM | #4 |
|
Mentor
|
MATLAB for uniform random variables
Your error message came from an attempt to access the (0, 1) element of a an array.
Before starting to code, you should take a look at the Matlab documentation to learn how to use such functions as rand, log, and plot. In the code you show, x is 0, and your fourth line is attempting to take the log of 0 Getting started with MATLAB User documentation I can't really give you much help, since your code is a VERY LONG way from doing what you need it to do. |
| May4-10, 06:04 PM | #5 |
|
|
Thanks for your comments but I need to point out thats the question in the first place. So there is no chance I can take a different value.
How do you suggest I define the vectors then? One of the vector (x) is multiplied with the log and the second vector (y) is multiplied with cos (2pi). And the question says X (note the upper case) = U (0,1) |
| May4-10, 06:28 PM | #6 |
|
Mentor
|
|
| May5-10, 10:08 AM | #7 |
|
|
Thanks, Mark. I read the documentation.
In my first post, the question has U= [0,1] with 10,000 random variables. Can you please tell me how I shud use this in the rand function? Also, please help with the substitution for x and y if I define the rand as "rand [1, 10000]" Thanks again. |
| May5-10, 12:50 PM | #8 |
|
Mentor
|
You can do this to create a 100 x 100 array of random numbers in the open interval (0, 1): X = rand(100) Or you can do this to create a vector of length 10000 of numbers from the same interval: X = rand(1, 10000) Whatever you do to create your X array, do the same to create the Y array. |
| Thread Closed |
| Tags |
| matlab, random variables, uniform distribution |
Similar discussions for: MATLAB for uniform random variables
|
||||
| Thread | Forum | Replies | ||
| Sum of two continuous uniform random variables. | Calculus & Beyond Homework | 18 | ||
| Proof of the statement: sum of two random variables is also a random variable | Set Theory, Logic, Probability, Statistics | 8 | ||
| Expectation and variance of a random number of random variables | Calculus & Beyond Homework | 3 | ||
| PDF of function of 3 continuous, uniform random variables? | Set Theory, Logic, Probability, Statistics | 3 | ||
| joint density of uniform random variables | Calculus & Beyond Homework | 0 | ||