Matching two variables within a certain toleration - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Matching two variables within a certain toleration (/thread-17690.html) |
Matching two variables within a certain toleration - Mason - Apr-20-2019 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). RE: Matching two variables within a certain toleration - SheeppOSU - Apr-21-2019 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 RE: Matching two variables within a certain toleration - Yoriz - Apr-21-2019 https://docs.python.org/3/library/math.html#math.isclose Wrote:math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)¶ import math if math.isclose(minf, m_fan_face): print('isclose') RE: Matching two variables within a certain toleration - rxndy - Apr-21-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? RE: Matching two variables within a certain toleration - Mason - Apr-21-2019 (Apr-21-2019, 06:48 PM)Yoriz Wrote:https://docs.python.org/3/library/math.html#math.isclose Wrote:math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)¶ 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. RE: Matching two variables within a certain toleration - Yoriz - Apr-21-2019 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') |