Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Say I want to randomly sample the Maxwell Boltzmann Distribution in python: This

ID: 3283370 • Letter: S

Question

Say I want to randomly sample the Maxwell Boltzmann Distribution in python:

This function is going from 0 to infinity. In python, I would usually generate a random point from a function like:

def f(x):

return somenumber

xval = numpy.random.uniform(xmin,xmax)

randomyval = f(xval)

But how would I do this for a function with an infinite domain? I can't just choose an arbitrarily large xmax. I think I need to use importance sampling, but I'm not sure how. Can someone show me in python how to randomly sample a distribution with infinte range, where I'm still able to tweak the standard deviation if I like?

I've tried using scipy.stats.maxwell, but it doesn't give you an option to change the standard deviation, only scale and shape. And I'm not sure how they relate.

0 (717)/ 1-3 7 7 = (v‘z)/

Explanation / Answer

Since there is a maxInt in Python ( 231-1 ) or (263 -1) depending on 32 and 64 bit systems , or in any computer languages , you cannot choose numbers beyond that and hence domain cannot be infinite.

The best you can do that choose numbers between minInt and maxInt .

*** Hope it helps , if not , we can follow this up in the comments ***

In Python 3 you can use the following code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote