0% found this document useful (0 votes)
32 views3 pages

HW7 Code

The document generates random variables from different normal distributions and multiplies them to create a new variable V. It calculates the mean and standard deviation of V and plots a histogram of its values. It also generates random variables from a uniform distribution, transforms them and plots their histogram compared to a theoretical distribution.

Uploaded by

SRINIDHI PAWAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

HW7 Code

The document generates random variables from different normal distributions and multiplies them to create a new variable V. It calculates the mean and standard deviation of V and plots a histogram of its values. It also generates random variables from a uniform distribution, transforms them and plots their histogram compared to a theoretical distribution.

Uploaded by

SRINIDHI PAWAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

16/10/2023, 13:22 Untitled7.

ipynb - Colaboratory

import numpy as np
import matplotlib.pyplot as plt
import random
import scipy.stats as stats
import math

Q2

a = []
for _ in range(200):
a.append(np.random.normal(2.0,0.1))

b = []
for _ in range(200):
b.append(np.random.normal(3.0,0.1))

c = []
for _ in range(200):
c.append(np.random.normal(4.0,0.2))

a = np.array(a)
b = np.array(b)
c = np.array(c)
V = []
for i in range(200):
V.append(a[i]*b[i]*c[i])

V = np.array(V)
#mean and standard deviation of V
mean = np.mean(V)
std = np.std(V)
print(mean, std)

23.916418179176233 1.952302882124931

uncertainty_mean = std/np.sqrt(200)
print(uncertainty_mean)

0.13804866068805796

plt.hist(V, bins=15, edgecolor='black', density = 'True')

(array([0.00675923, 0.01351845, 0.01351845, 0.0811107 , 0.18925831,


0.16222141, 0.16898063, 0.17573986, 0.15546218, 0.16222141,
0.09462915, 0.07435148, 0.03379613, 0.00675923, 0.01351845]),
array([18.46413946, 19.20386921, 19.94359896, 20.68332871, 21.42305846,
22.16278821, 22.90251796, 23.64224771, 24.38197747, 25.12170722,
25.86143697, 26.60116672, 27.34089647, 28.08062622, 28.82035597,
29.56008572]),
<BarContainer object of 15 artists>)

Q1

https://colab.research.google.com/drive/1ezDQX4zLpyr1ubxZxjBX0LIdk4MhsiOh#scrollTo=S9EYPqnk5xUJ&printMode=true 1/3
16/10/2023, 13:22 Untitled7.ipynb - Colaboratory
r = []
for _ in range(200):
r.append(random.uniform(0,1))

x = []
for i in r:
x.append(2*np.arcsin(np.sqrt(i)))

print(len(x))

200

freq, bin_edge, _ = plt.hist(x, bins=15, edgecolor='black')


#Area of histogram:
harea = 200*np.diff(bin_edge)[0]
print(np.sum(freq))

200.0

theta = np.arange(0,(np.pi)+0.01,0.01)
y = 0.5*np.sin(theta)

plt.hist(x, bins=15, edgecolor='black')


plt.plot(theta, y*harea, label='', color='red', linestyle='--')
plt.show()

https://colab.research.google.com/drive/1ezDQX4zLpyr1ubxZxjBX0LIdk4MhsiOh#scrollTo=S9EYPqnk5xUJ&printMode=true 2/3
16/10/2023, 13:22 Untitled7.ipynb - Colaboratory

https://colab.research.google.com/drive/1ezDQX4zLpyr1ubxZxjBX0LIdk4MhsiOh#scrollTo=S9EYPqnk5xUJ&printMode=true 3/3

You might also like