import math
#Initialization of variables
b = 4. #m
y = 1.2 #m
sf = 0.001
n = 0.012
gam = 9.81*1000
#calculations
A = b*y
R = A/(b+ 2*y)
Q = 1/n *A*R**(2./3) *sf**(1./2)
T = gam*R*sf
#results
print "Discharge = %.3f m**3/s"%(Q)
print " bed shear = %.2f N/m**2"%(T)
#The answer in textbook is wrong for discharge. Please use a calculator.
import math
#Initialization of variables
b = 6. #m
y = 2. #m
sf = 0.005
slope = 2.
gam = 9.81*1000
Q = 65. #m**3/s
#calculations
A = (b+ 2*y)*slope
P = b+ 2*y*math.sqrt(slope**2 +1)
R = A/P
V = Q/A
n = R**(2./3) *sf**(1./2) /V
#results
print "Value of mannings coefficient = %.3f"%(n)
import math
#Initialization of variables
b = 3. #m
y = 1. #m
sf = 0.005 #slope
n = 0.028
gam = 9.81*1000
Q = 0.25 #discharge - m**3/s
slope = 1.5
#calculations
A = 0.5 *b*y
P = 2*math.sqrt(1 + (slope)**2)
R = A/P
yx = Q*n/(slope * R**(2./3) *sf**(1./2))
y = yx**(3./8)
#results
print "depth = %.2f m"%(y)
import math
#Initialization of variables
sf = 0.0064 #slope
n = 0.015
Q = 6. #discharge - m**3/s
gam = 9.81*1000
#calculations
AR = n*Q/math.sqrt(sf)
print ("On trial and error, ")
y = 0.385 #m
print "normal depth = %.3f m"%(y)
import math
from numpy import *
#Initialization of variables\
sf = 0.00007
n = 0.013
gam = 9.81*1000
V = 0.45 #velocity - m/s
Q = 1.4 #m**3/s
#calculations
by = Q/V
#x = poly(0,"x")
#y = roots(x**2 -2.66*x +1.55)
y = roots([1,-2.66,1.55])
b = by/y
#results
print "y = ", y
print "corresponding b = " ,b
import math
#Initialization of variables
sf = 0.0016 #slope
n = 0.02
Q = 0.84 #m**3/s
gam = 9.81*1000
#calculations
y53 = Q*n/math.sqrt(sf)
y = y53**(3./5)
#results
print "depth of flow = %.2f m"%(y)
import math
#Initialization of variables
n = 0.015
Q = 1.3 #m**3/s
V = 0.6 #m/s
gam = 9.81*1000
#calculations
alpha = 60. #degrees
A = 0.5 *(1./2)**2 *(180-alpha)/180 *math.pi -(1./4)**2 *math.radians(math.tan(alpha))
A = 0.206
P = 0.5*(180-alpha)/180 *math.pi
R = A/P
d2 = V*n/(R**(2./3))
d8 = Q*n*4*4**(2./3) /math.pi
d = math.sqrt(d8/d2)
sf = (d2**2/d**(4./3))
#results
print "Diameter = %.2f m"%(d)
print " slope = %.5f "%(sf)
#The answer given in textbook is wrong. please check
import math
#Initialization of variables
b = 0.5 #m
y = 0.35 #m
sf = 0.001 #slope
nc = 0.016
gam = 9.81*1000
Q = 0.15 #m**3/s
#calculations
A = b*y
P = b+ 2*y
R = A/P
ng = 1/Q *A*R**(2./3) *sf**(1./2)
n = (b*nc**(3./2) + 2*y*ng**(3./2))**(2./3) /(P**(2./3))
Q2 = 1/n *A*R**(2./3) *sf**(1./2)
#results
print "flow in case 2 = %.3f m**3/s"%(Q2)
# note : rounding off error
import math
#Initialization of variables
b1 = 8. #m
b2 = 5. #m
y = 5. #m
b5 = 15. #m
b3 = 3. #m
b4 = 3. #m
y2 = 2. #m
y3 = 3. #m
n1 = 0.025
n2 = 0.035
sf = 0.0008
#calcuations
A = (b1+b2)*y
P = b1+ math.sqrt(b2**2 +y**2) + math.sqrt(b3**2 +b4**2)
R = A/P
Q1 = 1/n1 *A*R**(2./3) *sf**(1./2)
A2 = b5*y2 - 0.5*y2*y2 + 0.5*y3*y2
P2 = b5 + math.sqrt(b4**2 + y3**2)
R2 = A2/P2
Q2 = 1/n2 *A2*R2**(2./3) *sf**(1./2)
Q = Q1+Q2
#results
print "Total discharge = %.f m**3/s"%(Q)
# rounding off error
import math
#Initialization of variables
Q = 12. #m**3/s
n = 0.023
A = 2.472
b = 0.472
sf = 1./8000
#calculations
y8 = Q*n/A *2**(2./3) /sf**(1./2)
y = y8**(3./8)
b2 = b*y
#results
print "depth = %.3f m"%(y)
print " width = %.2f m"%(b2)
import math
#Initialization of variables
Q = 30.
V = 1.
#calculations
A = Q/V
y = math.sqrt(A/(math.sqrt(2) + 0.5))
b = (A- 0.5*y**2)/y
#results
print "width = %.2f m"%(b)
print " depth = %.2f m"%(y)