Question: import numpy as np import matplotlib.pyplot as plt # Parameters alpha = 2 beta = 4 # Inverse CDF ( quantile function ) def weibull

import numpy as np
import matplotlib.pyplot as plt
# Parameters
alpha =2
beta =4
# Inverse CDF (quantile function)
def weibull_inv(u, alpha, beta):
return alpha *(-np.log(1- u))**(1/ beta)
# Generate 100 random variates
u = np.random.uniform(0,1,100)
x = weibull_inv(u, alpha, beta)
# Plot histogram and density curve
plt.hist(x, bins=20, density=True, alpha=0.6, color='g')
# Plot the PDF
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p =(beta / alpha)*(x / alpha)**(beta -1)* np.exp(-(x / alpha)**beta)
plt.plot(x, p,'k', linewidth=2)
plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!