Create the following matrices using the given constraints. 2 Points each.
exp(0.5)
to 2 significant figures. Do the computation inside the {}
in the f-string.
In [1]:
import numpy as np
m = np.ones( (6,6) )
m[:,1] = 3
print(m)
In [2]:
[np.pi**i for i in range(10)]
Out[2]:
In [18]:
f'{np.exp(0.5):.2}'
Out[18]:
Use the two matrices given to answer the following problems. Answer in Python.
$$A = \left[\begin{array}{lcr} 4 & -3 & 8\\ -3 & 4 & -4\\ 8 & -4 & 10\\ \end{array}\right]$$$$B = \left[\begin{array}{lcr} 1 & 5 & -1\\ 23 & -1 & -2\\ 1 & 2 & 3\\ \end{array}\right]$$
In [4]:
from numpy import linalg
A = np.array([[4, -3, 8], [-3, 4, -4], [8, -4, 10]])
B = np.array([[1, 5, -1], [23, -1, -2], [1, 2, 3]])
In [5]:
linalg.matrix_rank(B)
Out[5]:
In [6]:
B @ A @ B
Out[6]:
In [7]:
f'{linalg.eig(B)[0][1]:.2f}'
Out[7]:
In [8]:
b = [11, 84, 17]
In [9]:
x = linalg.inv(B) @ b
print(x)
In [10]:
B @ x
Out[10]:
In [11]:
# can use any of the eigenvectors here
eig_s, eig_v = linalg.eig(A)
v = eig_v[:,0]
print(v)
In [12]:
print(A @ v, '==', v * eig_s[0])
In [13]:
import scipy.stats as ss
2 * ss.t.cdf(-3, df=5)
Out[13]:
In [14]:
print('{:.2f} standard deviations'.format(-ss.norm.ppf(0.025)))
In [15]:
print('{:.1f} / sqrt(N) standard deviations'.format(-ss.norm.ppf(0.025)))
In [16]:
# want extreme high values, so take 1 - CDF up to 10
# However we want 20 to be in our interval, so I add it back
# only subtract 1 point for missing that
1 - ss.poisson.cdf(20, 3) + ss.poisson.pmf(20, 3)
Out[16]:
In [17]:
T = (2 - 2.4) / (0.8 / np.sqrt(11))
print(2 * ss.t.cdf(T, df=10))