Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# In this simulation the library numpy is used and it is named it np # We will also use the math library
# In this simulation the library numpy is used and it is named it np
# We will also use the math library and we will name it math
import numpy as np
import math as math
# The seed below initializes the random generator to always obtain the same random inputs.
# DO NOT CHANGE THIS VALUE AND RERUN THIS CELL EVERYTIME YOU RUN THE PROGRAM.
nprandom.seed
# Variables are defined in this cell
Cap # Capacity of the reservoir
hours # hours in one day
days # number of days in years
nHours # Counter for number of hours
inflow # Inflow of treated water into the reservoir every hour in ML
offDem # Offpeak demand
meanpDem # Mean of the demand during peak hours
covpDem # Coefficient of variation of demand during peak hours
# Because the peak demand lognormally distributed the mean and standard deviation of the lnpDem must be obtained
Psi math.sqrtmathlog covpDem
Lambda math.logmeanpDem Psi
Dem npemptyhoursdays
volume Cap # initialise the volume equal to the capacity
nFail # counter of falures
pFail # probability of failure
for day in rangedays:
for hour in rangehours:
# Define peak demand period
# If peak demand randomly sample values of lnpDem from the lognormal distribution and store them in Dem
# If offpeak demand Dem
if hour and hour:
DemnHours math.expnprandom.normalLambdaPsi
else:
DemnHours offDem
# Perform water balance in reservoir
volume volume inflow DemnHours
if volume Cap:
volumeCap
elif volume :
volume
if hour and hour:
nFail nFail
nHours nHours
# calculate and print the probability of damage DURING PEAK HOURS
pFail nFailhoursdays
printThe probability of failing to supply the demand is pFail Answer the question in the image please.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started