Hello,
just FYI, there are already random number objects in sympy,
you can access them this way:

>>> from sympy.statistics import *
>>> x = Normal(0,1)
>>> x.random()
-0.181742214115
>>> a = x.random(10)
>>> print a
Sample([-1.47958009923, -1.23521203179, -0.783418473091,
-0.0760736376295, -0.0466694687666, 0.183479317614, 0.582606719385,
0.665871480479, 0.933270566339, 1.07713745229])

Sorry, I don't know answer to your question.

Addition and multiplication of random variables is a good
idea. It can be implemented using the PDF class by
convolution of probability distributions a then sampling the
resulting PDF. However, if your aim is just generating random
numbers and not analytical computation of their properties, it
might be simpler to write your own class that does the addition
and multiplication on the fly as it generates each sample.

Stepan

2009/5/14 Yau Kwan Kiu <yaukwan...@gmail.com>:
>
> Hello.
>
> I am trying to write some random number objects with the built in
> random number generators.   I am trying first with
> random.normalvariate.
>
> I define them as a subclass (Rsymbol) of sympy.core.symbol.Symbol and
> they are called directly with __call__, e.g.
>
>>>>x=Normal('x',0,1)  #name='x', mean=0, variance=1
>>>>x()
> 1.5674156503660097
>>>>
>
> And also, e.g.
>
>  y=Normal('y',1.4)
>
> can be defined, and so far so good.  I can even put it on a list
>
>>>>for i in range(100): b.append(y())
>
> and put it in a histogram with pylab/numpy
>
> But then when I try to get more than one lists at the same time:
>>>>for i in range(100):
> ...         a.append(x())
>            b.append(y())
>
> The result is that a and b are exactly equal.
> I guess I got hit by one of those problems with python names.
>
> Question:  Is it a genuine problem?  How can I work around it?
>
> Thank you.
> P.S.  I would also like to be able to add and multiply random
> variables.  I am still looking at core.add  - is subclassing mul and
> add the quickest way to do it?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to