Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
1 contributor

Users who have contributed to this file

executable file 41 lines (35 sloc) 1.04 KB
#!/opt/miniconda3/bin/python
import numpy as np
from scipy.optimize import fsolve
import sys
def parapiped(w,h,L):
A=2*(w*h+w*L+h*L)
V=w*h*L
return np.array([A,V])
def cylinder(r,t):
A=2*np.pi*r*(r+t)
V=np.pi*r**2*t
return np.array([A,V])
def matchAV(dim_cyl,dims):
r,t=dim_cyl
w,h,L=dims
AVp=parapiped(w,h,L)
AVc=cylinder(r,t)
return AVp-AVc
def solve_cylinder(w,h,L):
r,t=fsolve(matchAV,[1,2],args=[w,h,L])
print('A %1.2f x %1.2f x %1.2f parallelipiped'%(w,h,L) )
print('has the same surface area and volume as a cylinder')
print('that is r=%1.4f and t=%1.4f'%(r,t))
if __name__=='__main__':
if len(sys.argv)<=3:
print('error, please enter w-by-t-by-L dimensions of parallelipiped as w t L')
else:
print(sys.argv)
w=float(sys.argv[1])
h=float(sys.argv[2])
L=float(sys.argv[3])
r,t=fsolve(matchAV,[1,2],args=[w,h,L])
print('A %1.2f x %1.2f x %1.2f parallelipiped'%(w,h,L) )
print('has the same surface area and volume as a cylinder')
print('that is r=%1.4f and t=%1.4f'%(r,t))