My question is:
The volume v of a liquid in a hollow cylinder of radius r and length L is related to the depth of the liquid h by v = [rᶺ2 cos ᶺ -1 {( r-h )/r} – (r-h)√(2rh-hᶺ2)]L. Determine h by python program, given r = 2m,L =5m and v = 4meter cube.
Note that arc cosine can also be computed with Cos ᶺ-1 x = π/2 - tan ᶺ -1 ( x/√(1-x2 ))
That's not a question, that's a definition. What have you tried so far to solve the formula.
from random import randrange
from math import acos, degrees, sqrt
r = 2
L = 5
v = 4
done = True
while done:
h = randrange(-100,2)
x = randrange(5,200)
a = r ** 2
b = (r-h)/r
c = acos(b)
d = degrees©
e = sqrt(2*r*h - h**2)
f = (a * c - (r-h) * e) * L
if f > (v+2) and f < (v-2):
done = False
break
print('the value of h is', h)
and all i get is:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:\Users\Emmanuel\AppData\Local\Programs\Python\Python36\testing 1.py
Traceback (most recent call last):
File "C:\Users\Emmanuel\AppData\Local\Programs\Python\Python36\testing 1.py", line 13, in <module>
c = acos(b)
ValueError: math domain error
>>>
(Aug-18-2017, 02:02 PM)Emmanuel Wrote: [ -> ]c = acos(b)
ValueError: math domain error
That's not a python problem, that's a math problem. arccosine only makes sense in the range of -1 to +1. You're using random numbers, so let's pretend h is -50...
>>> import math
>>> h = -50
>>> r = 2
>>> c = (r - h) / r
>>> c
26.0
>>> math.acos(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
Maybe don't use random numbers until you have a working algorithm?
Cosine only returns values from -1 to 1. Therefore arc cosine (acos) can only take values from -1 to 1. You should probably constrain h to be -2 to 2 to keep b within -1 to 1.
In any case the calculation should be volume = ∏r^2h