In [4]:

```
# Force applied on the piston
from math import *
# Given
d = 10 # diameter of hydraulic press in meters
d1 = 1 # diameter of piston in meters
W = 1000 # weight in Newtons
Ap = math.pi*d1**2/4 # Area of piston in m**2
Ar = math.pi*d**2/4 # Area of rram in m**2
# Solution
p = W/Ar # pressure to be supplied by the oil in N/cm**2
F = p*Ap # Force applied on the piston
print "Using the pascal's law a weight of 1000N can be lifted by applying a force only of ",round(F,1),"N"
```

In [5]:

```
# Pressure in kN/m**2
# Given
h = 1 # ocean depth below the surface in km
gma = 10070 # Specific weight of sea water
# Solution
P =gma*h # Pressure in kN/m**2
print "Pressure = ",round(P),"kN/m**2"
```

In [15]:

```
# Pressure at the bottom of the tank
# Given
p1 = 150*10**3 # Pressure at point 1 in kN/m**2
Sg = 0.85 # Specific gravity of oil
h = 0.8 # height of oil 2 i tank in meters
g = 9810 # specific gravity
h1 = 2.0 # height of oil 3 in tank
# Solution
p2 = (p1 + Sg*h*g)
p3 = (p2 + g*h1)/1000
print "Pressure at the bottom of the tank is",round(p3,1),"kN/m**3"
```

In [6]:

```
# Height of the mountain
# Given
from math import *
from __future__ import division
Po = 570 # mercury barometer reading in mm
T = 273 -5 # temperature in K
p = 750 # mercury barometer reading in mm
n = 1.2345 # for polytropic atmosphere
R =287 # univerasl gas constant in J/Kg-K
g = 9.81
r = p/Po
# Solution
y = -(R*T/(g*0.19))*(1 - (r)**((n-1)/n))
print "Height of the mountain is",round(y,0),"m"
```

In [7]:

```
# Pressure in the pipe
# Given
h1 = 500 # height in mm
h2 = 950 # height in mm
S1 = 1 # specific gravity fo water
S2 = 1.5 # specific gravity of liquid 2
w = 9810 # specific weight of water
# Solution
ha = ((h2*S2)-(h1*S1))/1000
Pa = w*ha/1000 # Pressure in kPa
print "Pressure in the pipe = ",round(Pa,3),"kPa"
```

In [18]:

```
# Force required to open the gate
# Given
from __future__ import division
from math import *
d = 1 # diameter of the gate in m
w = 9810 # specific weight in N/m**3
A = pi*d**2/4 # area of the gate
Ig = pi*d**4/64 # mamm moment of inertia
theta = pi/2
y1= 5+0.5
# Solution
F = w*round(A,3)*(y1) # the answer will come out to be different as they have used the value of Area as 0.78
# depth of the COP
h1 = y1 + (Ig*math.sin(theta)*math.sin(theta)/(A*y1))
# moment about hinge A
F1 = (F*(h1 - 5))/d
print "Magnitude of the force required to open the gate = ",round(F1,0),"N"
#The area calculated in the book is 0.785 and that calculated from code is 0.78.
#This difference of 0.005 is causing the answer to change from the original
```

In [3]:

```
# total force ; position of the center of pressure
from math import *
# Given
l =2 # length of the plate in m
b =1 # width of the plate
theta = pi/3
h = 0.75 # depth of the plate
w = 9810 # specific weight of water
# Solution
A = 1*2
y1 = h + 1*sin(theta)
F = w*A*y1/1000
print "(a) Total force = ",round(F,2),"kN"
Ig = (b*l**3)/12
h1 = y1 + (Ig*sin(theta)*sin(theta)/(2*y1))
print "(b) Position of center of pressure = ",round(h1,3),"m"
```

In [9]:

```
# Hydrostatic force and point of location
from math import *
# Given
d = 6 # diameter of the gate in ft
A =pi*d**2/4 # area of the gate
p1 = 600 # pressure on top in psia
y1 = 10 +2 + 3*sin(pi/6)
F = 62.4*A*y1
F1 = p1*A
# Solution
Tf = F+F1
print "Total hydrostatic force =",round(Tf,0),"lbs"
Ig = pi*d**4/64
h1 = y1 + ((Ig*sin(pi/6)*sin(pi/6))/(A*y1))
H = ((F*h1)+(F1*y1))/Tf
print "point of location on the center plate = ",round(H,2),"ft"
# method 2
Hf = p1/62.4 # equivalent fluid height
y2 = Hf+y1
Tf1 = 62.4*A*y2
h2 = y2 + ((Ig*sin(pi/6)*sin(pi/6))/(A*y2))
H1 = y2-Hf
print " OR point of location on the center plate from method 2 = ",round(H1,2),"ft"
```

In [10]:

```
# Horizontal and Vertical components
import math
# Given
R = 4 # radius of the gate in ft
w = 1 # width of the gate in ft
gma =62.4 # specific weight of water
y1 = 4 # distance of center of the gate
xv1 = 2 # distance in ft
xv2 = 1.7 # distance in ft
# Solution
Fh = R*y1*gma
Ig = w*R**3/12
yh = y1 + (Ig/(R*y1))
Fv1 = R*2*gma
Fv2 = pi*R**2*gma/4
Fv = Fv1 + Fv2
Xv = (Fv1*xv1+Fv2*xv2)/(Fv)
print "Horizontal component acting on the plate = ",round(Fh,2),"lbs"
print "Vertical component acting on the plate = ",round(Fv,2),"lbs"
print "location of Xv =",round(Xv,2),"ft"
```

In [19]:

```
# Vertical and Horizontal components
from math import *
from __future__ import division
# Given
p = 50 # pressure in psia
gma = 62.4 # specific weight in ft
h1 = p*144/gma # equivalent height of water surface in ft
R = 4 # radius of gate in ft
w = 1 # width of the gate in ft
A = R*w
y1 = h1 + 2.5 + 2 # center of pressure
xv1 = 2 # center of pressure1 for x direction force
xv2 = 1.7 # center of pressure2 for x direction force
# Solution
Fh = gma*A*y1 # hiorizontal force
Ig = 5.33 # moment of inertia
yh = y1 + (Ig/(A*y1)) # location of horizontal component
y2 = h1+2.5
Fv1 = gma*(R*y2) # vertical force component 1
Fv2 = gma*(pi*R**2/4) # vrtical force component 2
Fv = Fv1 + Fv2 # vertical force component
Xv = (Fv1*xv1+Fv2*xv2)/(Fv)
print "(a) Horizontal component acting on the plate = ",round(Fh,0),"lbs" # The answer for horizontal force in the book is wrong
print "(b) Vertical component acting on the plate = ",round(Fv,2),"lbs"
print "location of vertical component Xv =",round(Xv,2),"ft from the left wall"
```

In [12]:

```
# Depth to which water would rise
from math import *
from __future__ import division
# Given
l = 3 # length in m
b = 4 # breadth in m
h = 15 # height in m
S = 0.9 # specific gravity of barge
Sw = 1.09 # specific gravity of water
Wd = 150*10**3 # addditional weight in kN
V = l*b*h # volume in m**3
Wb = gma*S*V # weight of barge
Tw = Wb + Wd # total weight in kN
gma = 9810 # specific density
# Solution
Fb = Tw # since barge is floating
V1 = Fb/((gma/1000)*Sw) # volume in m**3
d = (V1/(h*b))/1000
print "Depth to which water would rise = ",round(d,2),"m"
```

In [13]:

```
# Level at which cylinder will float
from math import *
from __future__ import division
import numpy as np
# Given
W = 0.4 * 9.81 # weight of the solid cylinder in N
# Solution
A = np.array([(1,-0.96),(1,1)])
b = np.array([0,6.37])
x = np.linalg.solve(A,b)
X = x[0]
Y = x[1]
print "X = ",round(X,2),"cm"
print "Y = ",round(Y,2),"cm"
b = 8 -x[0]
print "The bottom of the solid cylinder will be ",round(b,2),"cm above the bottom"
```

In [14]:

```
# Weight of the pan and the magnitude of righting moment
from math import *
# Given
l =100 # length of the pan in cm
w = 20 # width of the pan in cm
d = 4 # depth of the pan in cm
L = 1.5 # load in N/m
gma = 9810 # sepcific weight
# Solution
Fb = gma*(d*w*l/(2*l**3)) # weight on the pan
W = Fb-L # weight of the pan
X1 = w/3
X2 = w/2
theta = math.atan(d/w)*180/pi
x = ((X2-X1)*cos(theta*pi/180))
# momentum equation
M = W*x
print "Weight of the pan =",round(W,1),"N"
print "Magnitude of right momentum = ",round(M,1),"N.cm"
```

In [15]:

```
# Metacentric height and rightning moment
from math import *
from __future__ import division
# Continued from example 2.15
# Given
Io = 15*4**3/12 # moment of inertia in m**4
V = 15*4*2.71 # Volume in m**3
Gb = ((3/2)-(2.71/2))
W = 1739.2 # weight of the barge from the previous example in kN
# Solution
Mg = (Io/V)-Gb # metacentric height in m
print "(a) Metacentric height = ", round(Mg,3),"m"
M = W*Mg*sin(pi*6/180)
print "(b) Righting moment =",round(M,1),"kN.m"
```

In [16]:

```
# Maximum pressure in the tank
from math import *
from __future__ import division
# Given
l=6 # length of the tank
w =2 # width of the tank
d = 3 # depth of the tank
a = 3 # acceleration in m/s**2
theta = pi/6
W = 9810 # specific weight
X = 0
po=0 # pressure at the origin
# Solution
A = np.array([(1,-1),(1,1)])
b = np.array([-1.38,3.0])
x = np.linalg.solve(A,b)
Y1 = x[0]
Y2 = x[1]
# AMximum pressure at the bottom of the tank
P = po - W*(2.61*X/9.81) - W*(1+(1.5/9.81))*(-Y2)
print"Amximum pressure occurs at the bottom of the tank =",round(P,3),"N"
```

In [17]:

```
# Height of the paraboloid revolution; maxm=imum pressure and location ; pressure at the point 0.2 from the center
from math import *
from __future__ import division
# Given
d = 1 # diamter of the jar in ft
h =2 # height of the jar in ft
H = 1 # height of water in the jar in ft
N = 150 # RPM
g = 32.2 # acceleration due to gravity in ft/s**2
# Solution
w = 2*pi*N/60
ho = H+((w**2*(d/2)**2)/(4*g))
print "(a) Height of paraboliod revolution of base = ", round(ho,2),"ft"
Pmax = 62.4*ho
print "(b) Maximum pressure corresponding to maximum height = ",round(Pmax,1),"lbs/ft**2"
z = H - ((w**2*(d/2)**2)/(4*g))
r = 0.2 # distance from center
y = -(0.52-0.25)
P = po + (62.4*w**2*r**2/(2*g))-(62.4*y)
print "(c) Pressure =",round(P,1),"lbs/ft**2"
```

In [ ]:

```
```