CS计算机代考程序代写 In [1]:

In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as spst
In [2]:
a=5
b=2
x = np.random.rand(1000)
y = a + (b-a)*x
In [3]:
fy = y**2 + 1
gx = fy*(b-a)
In [10]:
Egx = np.mean(gx)
Sgx = np.std(gx, ddof=1)
# z score of t score
z = spst.norm.ppf(0.975)
n = 1000
Egx
Out[10]:
-42.284959564299044
In [11]:
lower = Egx-z*Sgx/n**0.5
upper = Egx+z*Sgx/n**0.5
lower, upper
Out[11]:
(-43.393755727205274, -41.17616340139281)
In [0]:
#since g(x) are all from a continuous distribution
#let’s use a histogram to visualize the samples
In [7]:
a=5
b=2
x = np.random.rand(1000)
y = a + (b-a)*x
fy = y**2 + 1
gx = fy*(b-a)
np.mean(gx)
Out[7]:
-42.3197215570678
In [9]:
plt.hist(gx, density=True, bins=30)
plt.show()


In [0]:

In [0]: