Posts: 3
Threads: 2
Joined: Apr 2019
Apr-20-2019, 03:09 PM
(This post was last modified: Apr-20-2019, 03:10 PM by Mason.)
Hi all,
I am new to Python and currently working on a thesis project. I have come across an issue regarding some simple calculations. I have the following script:
#isentripic relationships
gamma=1.4
patm=23908.7784729
tatm=218.923952814
rho=0.379597
R=287
a=296.5355
Mf=.85
MFCR=0.7
P0=(1+((gamma-1)/2)*(Mf**2))**(gamma/(gamma-1))*patm
T0=(1+((gamma-1)/2)*(Mf**2))*tatm
#print(T0)
pg=P0-patm
#print (pg)
#determining Ah
import math
rhi=0.663
Ahi= math.pi*rhi**2
print(Ahi)
Ainf=MFCR*Ahi
minf=rho*Ainf*Mf*(gamma*R*tatm)**0.5
print(minf)
p_engine_outlet=P0-patm
np.isclose ([minf, m_fan_face]), (1e-09])
m_fan_face = rho*Ahi*M_fan_face*(gamma*R*tatm)**0.5
for M_fan_face in range(0.5,0.7,0.01):
What I want to achieve with my code is to match the variable minf and m_fan_face. I want to tell Python to match these two within a tolerance of 1e-09. In obtaining m_fan_face I need to iterate for the variable M_fan_face and substitute this in the equation :m_fan_face = rho*Ahi*M_fan_face*(gamma*R*tatm)**0.5. However, I don't know how to do this process. I have tried doing it in the last three lines of my code. I would be pleased if someone could help me with this. I am using spyder (Python 2.7).
Posts: 479
Threads: 86
Joined: Feb 2018
First off, you should put all your imports at the top of the script. Second... That's all I can help you with. IDK how simple this stuff seems to most people, but to 7th grader like me... I only recognize the formula for the area of a circle. Sorry
Posts: 2,168
Threads: 35
Joined: Sep 2016
https://docs.python.org/3/library/math.h...th.isclose Wrote:math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)¶- Return True if the values a and b are close to each other and False otherwise.
Whether or not two values are considered close is determined according to given absolute and relative tolerances.
rel_tol is the relative tolerance – it is the maximum allowed difference between a and b, relative to the larger absolute value of a or b. For example, to set a tolerance of 5%, pass rel_tol=0.05. The default tolerance is 1e-09, which assures that the two values are the same within about 9 decimal digits. rel_tol must be greater than zero.
abs_tol is the minimum absolute tolerance – useful for comparisons near zero. abs_tol must be at least zero.
If no errors occur, the result will be: abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol).
The IEEE 754 special values of NaN, inf, and -inf will be handled according to IEEE rules. Specifically, NaN is not considered close to any other value, including NaN. inf and -inf are only considered close to themselves.
New in version 3.5.
import math
if math.isclose(minf, m_fan_face):
print('isclose')
Posts: 27
Threads: 6
Joined: Apr 2019
I don't understand what this means in your question:
Quote: match the variable minf and m_fan_face
What does Match mean in this context?
Posts: 3
Threads: 2
Joined: Apr 2019
Apr-21-2019, 07:13 PM
(This post was last modified: Apr-21-2019, 07:13 PM by Mason.)
(Apr-21-2019, 06:48 PM)Yoriz Wrote: https://docs.python.org/3/library/math.h...th.isclose Wrote:math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)¶- Return True if the values a and b are close to each other and False otherwise.
Whether or not two values are considered close is determined according to given absolute and relative tolerances.
rel_tol is the relative tolerance – it is the maximum allowed difference between a and b, relative to the larger absolute value of a or b. For example, to set a tolerance of 5%, pass rel_tol=0.05. The default tolerance is 1e-09, which assures that the two values are the same within about 9 decimal digits. rel_tol must be greater than zero.
abs_tol is the minimum absolute tolerance – useful for comparisons near zero. abs_tol must be at least zero.
If no errors occur, the result will be: abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol).
The IEEE 754 special values of NaN, inf, and -inf will be handled according to IEEE rules. Specifically, NaN is not considered close to any other value, including NaN. inf and -inf are only considered close to themselves.
New in version 3.5.
import math
if math.isclose(minf, m_fan_face):
print('isclose')
m_fan_face = rho*Ahi*M_fan_face*(gamma*R*tatm)**0.5
for M_fan_face in range(0.5,0.7,0.01): I wanted to iterate for M_fan_face and substitute this into the first equation and check that it matches minf. The values of rho, Ahi, gamma, R and tatm are fixed. I only need to guess for M_fan_face from 0.5 to 0.7 in increments of 0.01. I know that m_fan_face won't be exactly identical to minf but I want the difference between them to be 1e-09.
Posts: 2,168
Threads: 35
Joined: Sep 2016
something like this maybe
for M_fan_face in range(0.5,0.7,0.01):
m_fan_face = rho*Ahi*M_fan_face*(gamma*R*tatm)**0.5
if math.isclose(minf, m_fan_face):
print(f'm_fan_face isclose using M_fan_face as {M_fan_face}')
break
else:
print('M_fan_face is not close enough using range given')
|