Graphical histogram with a theoretical curve: random implementation

I need to write a program that generates random implementations of the Cauchy distribution

gif.latex? f (x) =% 5Cfrac% 7B1% 7D% 7B% 5Cpi% 7B (1 & plus; x% 5E% 7B2% 7D)% 7D% 7D

with zero location and units scale.

I also need to make a histogram between -5 and 5 cells, for a random implementation of 1000 points, together with a theoretical curve , to make sure that they have the same units.

I calculated the cumulative distribution function gif.latex? F (x)for the Cauchy distribution:

gif.latex? F (x) = tan [% 7B% 5Cpi% 7B (rand () -% 7B% 5Cfrac% 7B1% 7D% 7B2% 7D)% 7D% 7D% 7D]

And I wrote the following python code:

from __future__ import division
import scipy
import random
import matplotlib.pyplot as plt
import numpy as np
import math as m


valuesX = []
for q in range(1000):
    R = random.random()
    x = m.tan(m.pi*(R-0.5)) #Cumulative Function
    valuesX.append(x)

z = np.linspace(-10,10,1000)
y = 1/(m.pi*(1+z**2)) #Theoretical Cauchy

plt.plot(y,z)
plt.hist(valuesX, bins = 50, range = [-5,5], normed=True)

My results: Random implementation histogram for Cauchy distribution

, , ( ) . ? .

+4
1

, , , , . "normed = True" plt.hist() . .

, , , , , , .

, , [a, b], :

enter image description here

, .

, :

enter image description here

, (.. b ). , .

0

Source: https://habr.com/ru/post/1611144/


All Articles