Problem 1.1

This commit is contained in:
orosmatthew 2024-02-05 12:03:36 -05:00
parent 8e6f63405c
commit 0cd119041e
2 changed files with 46 additions and 0 deletions

26
1.1.py Normal file
View File

@ -0,0 +1,26 @@
import numpy as np
ages = np.array([14, 15, 16, 16, 16, 22, 22, 24, 24, 25, 25, 25, 25, 25])
# a
expect_j_sqrd = np.sum(ages ** 2) / ages.size
print("<j^2>:", expect_j_sqrd)
expect_j = np.sum(ages) / ages.size
print("<j>^2:", expect_j ** 2)
# b
unique_ages = np.unique(ages)
unique_delta_js = unique_ages - expect_j
print("delta js:", [(unique_ages[i], unique_delta_js[i]) for i in range(len(unique_ages))])
delta_js = ages - expect_j
std_eq11 = np.sqrt(np.sum(delta_js ** 2) / delta_js.size)
print("std eq. 1.11:", std_eq11)
# c
std_eq12 = np.sqrt(expect_j_sqrd - expect_j ** 2)
print("std eq. 1.12:", std_eq12)

View File

@ -0,0 +1,20 @@
import numpy as np
import math as m
def pascal(n: int) -> np.ndarray:
p = np.zeros(n + 1)
for i in range(n + 1):
p[i] = m.factorial(n) / (m.factorial(i) * m.factorial(n - i))
return p
def normalized_pascal(n: int) -> np.ndarray:
return pascal(n) / 2 ** n
N = 10
heads = np.arange(N + 1)
print("heads:", heads)
print("pascal:", normalized_pascal(N))