HW4
a) For this problem, we will re-work homework 2a using the scipy stats module rather than the Simpson method to find:
P(x<1|N(0,1)): probability x<1 given a normal distribution of x with μ=0, σ=1
P(x>μ+2σ|N(175, 3))
Specifically, you should import as: from scipy import stats
Within stats you should explore the functions stats.norm().pdf and stats.norm().cdf , which refer to the probability density function and cumulative distribution functions, respectively.
Rather than printing your findings to the console, we will use matplotlib.pyplot to produce nicely formatted plots such as shown below. Additional requirements are:
• You should use numpy arrays for all of your work on this problem where arrays are needed.
Note: a code stem for HW4a.py is available for download.
b) Re-work problem b) from homework 2, but use fsolve rather than the secant method to find the roots.
c) Re-work problem c) from homework 2, but use numpy and scipy rather than the Cramer function to solve the matrix equations.HW4a.py (This is a stem with #JES MISSING CODE when I broke the working program)
# region imports
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
# endregion
# region functions
def main():
'''
Calculates P(x<1|N(0,1)) and P(x>μ+2σ|N(175, 3)) and displays both the GNPDF
and CDF
for each case
:return: nothing
'''
#part 1 P(x<1|N(0,1))
mu_a = #JES MISSING CODE #mean
sig_a = #JES MISSING CODE #standard deviation
c_a = #JES MISSING CODE
p_a = #JES MISSING CODE #calculate the probability P(x<1|N(0,1))
#create the illustrative plots for part a
x_a=np.linspace(mu_a-5*sig_a,mu_a+5*sig_a,500) #create a numpy array using
linspace between mu-5*sigma to mu+5*sigma with 500 points
cdf_a = np.array([#JES MISSING CODE FOR LIST COMPREHENSION]) #create a numpy
array filled with values of CDF
gnpdf_a = np.array([#JES MISSING CODE FOR LIST COMPREHENSION]) #create a numpy
array for f(x) from the GNPDF
plt.subplots(2,1,sharex=True) #create two, stacked plots using subplots with
sharex=True
plt.subplot(2, 1, 1) #set subplot 1 for our focus by using plt.subplot
plt.plot(x_a, gnpdf_a) #plot the gndpf_a vs x_a
plt.xlim(x_a.min(),x_a.max())
plt.ylim(0, gnpdf_a.max()*1.1)
# fill in area below GNPDF in range mu_a-5*sig_a to 1
x_fill = np.linspace(mu_a - 5 * sig_a, c_a, 100) #create a numpy array of x
values from mu-5*sigma to 1 with 100 points
gnpdf_fill = np.array([#JES MISSING CODE FOR LIST COMPREHENSION]) #calculate
the GNPDF function for each x in x_fill and store in numpy array
ax=plt.gca() #get the axes for the current plot
ax.fill_between(x_fill, gnpdf_fill, color='grey', alpha=0.3) #create the filled
region between gnpdf and x axis
#construct the equation to display on GNPDF using TeX
text_x=mu_a-4*sig_a
text_y=0.65*gnpdf_a.max()
plt.text(text_x,text_y,r'$f(x)=\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{1}{2}\
left(\frac{x-\mu}{\sigma}\right)^2}$')
arrow_x=(c_a-mu_a+5*sig_a)*2/3+(mu_a-5*sig_a) #calculate the x coordinate for
where the arrow should point
arrow_y=(#JES MISSING CODE ) #calculate the y coordinate for where the arrow
should point
plt.annotate('P(x<{:0.2f}|N({:0.2f},{:0.2f})={:0.2f}'.format(c_a, mu_a, sig_a,
p_a),
size=8,xy=(arrow_x,arrow_y),xytext=(text_x,0.5*text_y),arrowprops=dict(arrowstyle='
->', connectionstyle="arc3")) #draw the arrow with text
plt.ylabel('f(x)', size=12)
ax.tick_params(axis='both', which='both', direction='in', top=True, right=True,
labelsize=10) # format tick marks
# ax.xaxis.set_ticklabels([]) #erase x tick labels for the top graph
ax.yaxis.set_label('f(x)')
#create the CDF plot
plt.subplot(2,1,2) #select the second plot
plt.plot(x_a,cdf_a) #plot cdf_a vs x_a
plt.ylim(0,1)
plt.ylabel('$\Phi(x)=\int_{-\infty}^{x}f(x)\mathrm{d}x$', size=12)
plt.xlabel('x')
plt.plot(c_a,p_a,'o', markerfacecolor='white', markeredgecolor='red')
ax=plt.gca()
ax.tick_params(axis='both', which='both', direction='in', top=True, right=True,
labelsize=10) # format tick marks
ax.set_xlim(ax.get_xlim())
ax.hlines(p_a,ax.get_xlim()[0],c_a, color='black', linewidth=1)
ax.vlines(c_a, 0, p_a,color='black', linewidth=1)
plt.show()
#part 2 P(x>mu+2*sigma|N(175,3))
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme