Question: Note : Make a Flow Chart of this python code part a and b in a Human Language. import numpy as np import matplotlib.pyplot as

Note : Make a Flow Chart of this python code part a and b in a Human Language.

import numpy as np

import matplotlib.pyplot as plt

# define IdealGas class for OOP programming flow

class IdealGas:

def __init__(self,R,Tc,Pc):

self.R = R

self.Tc = Tc

self.Pc = Pc

def a(self):

return 27/64 * (self.R**2 * self.Tc**2 / self.Pc)

def b(self):

return self.R * self.Tc / (8 * self.Pc)

def T(self, P, V):

return (P + self.a() / V**2) * (V - self.b()) / self.R

def Z(self,P,V):

return (P * V ) / (self.R * self.T(P,V))

# define ammonia as an instance of IdealGas passing its values of R,Tc,Pc

ammonia = IdealGas(0.08206, 405.5, 111.3)

# PART a.

n = 5 # number of samples of P or V

P = np.linspace(30,50,n)

V = np.linspace(0.1,1,n)

print('\t P \t V \t\t T \t\t Z') # table header

for i in range(n):

T = ammonia.T(P[i],V[i]) # compute T

Z = ammonia.Z(P[i],V[i]) # compute Z

# display a table row

print('\t{:.0f}\t'.format(P[i]),'{:.1f}\t'.format(V[i]),'{:.2f}\t'.format(T),'{:.2f}\t'.format(Z))

# PART b.

Pr = [1, 2, 4, 10, 20];

P = [pr * ammonia.Pc for pr in Pr] # compute P = Pr * Pc

V = 0.5 # assume a value of V in range [0.1, 1]

Z = []

for i in range(len(P)):

Z.append(ammonia.Z(P[i],V)) # compute Z

# plot Z vs Pr

plt.plot(Pr,Z,'-o')

plt.grid(linestyle='--')

plt.xlabel('Reduced Pressure, Pr [atm]')

plt.ylabel('Compressibility Factor, Z')

plt.title('V = ' + str(V) + 'liters/g-mol')

Note : Make a Flow Chart of this python code in a Human Language.

Use python software to run the code if needed .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!