Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > The Academy > Tilted Knowledge and How-To


 
 
LinkBack Thread Tools
Old 09-22-2003, 07:18 AM   #1 (permalink)
Psycho
 
Scorpion23's Avatar
 
Help with random numbers in Matlab

Does anyone know how to generate a matrix or sequence of random numbers in Matlab? The numbers have to fall inside a ellipse of equation:
t=[0:2*pi/100:2*pi];
x=5*cos(t);
y=1*sin(t);
plot(x,y,'.')
or any other ellipse/shape.
The end result would be an ellipse filled with random points.
I've tried looking for a command that would generate points within a constraint but to no avail.
Scorpion23 is offline  
Old 09-22-2003, 10:30 AM   #2 (permalink)
Riiiiight........
 
One method, called Acceptance/Rejectance or Thinning,
is to bound your ellipse by a box.

Generate random points within this box, then check if the points are within the ellipse. Throw away points that are not in the ellipse.

So the better you "bound" your shape, the less points you have to throw away.

In fact, since your ellipse is symmetrical about the x-axis, you can simply use 'half' and ellipse, the part thats above the x-axis.
dimbulb is offline  
Old 09-22-2003, 02:13 PM   #3 (permalink)
undead
 
Location: nihilistic freedom
This method kinda depends on the granularity of your values... but, you could generate a list of all points uniformly distributed within your elipse. Then randomize this list. Now for your generator, all you need to do is traverse the list. Or I guess you could just walk around the list with a large prime number... same effect.
nothingx is offline  
Old 09-22-2003, 03:11 PM   #4 (permalink)
Psycho
 
Scorpion23's Avatar
 
Yeah, I had already started to write a subroutine that would generate a random matrix then delete the points that don't fall inside the boundary of the ellipse. But I was hoping to find some obscure Matlab command that would make it much easier. These ideas are pretty good though.

btw, moelester: what do you mean by "walk around the list with a large prime number"
__________________
"Empirically observed covariation is a necessary but not sufficient condition for causality" - Edward Tufte
Scorpion23 is offline  
Old 09-23-2003, 06:05 AM   #5 (permalink)
Riiiiight........
 
Well, there are several ways of generating random numbers corresponding to a distribution from uniform[0,1] distributions ( thats what you essentially get when you use rand().)

Another way, if you have a nice function, is to use the inverse of the cumulative distribution function. Since the cumulative distribution function maps from [range of values in the distribution] to [0,1], and thus the inverse maps from [0,1] to [range of values], and the uniform is also from [0,1], you can get generate a random U(0,1) number, and plug it into the inverse of the CDF.

For more information about generating random numbers, check up a book on simulation. The textbook by Law and Kelton has a pretty comprehensive section on how to generate random numbers.
dimbulb is offline  
 

Tags
matlab, numbers, random


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 06:06 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76