Challenge

Week 2 Air standard Cycle

Q1.

import numpy as np

import matplotlib.pyplot as plt

def otto_cycle():

# Define the parameters of the Otto Cycle

r = 8 # Compression ratio

k = 1.4 # Specific heat ratio

Tmin = 300 # Minimum temperature (K)

Pmin = 1e5 # Minimum pressure (Pa)

# Calculate the temperatures and pressures at each stage

Tc = Tmin * r ** (k - 1) # Temperature at the end of compression

Tmax = Tc * r ** (k - 1) # Maximum temperature

Pmax = Pmin * r ** k # Maximum pressure

# Create the PV diagram

V = np.linspace(Pmin / Pmax, 1, 100)

P = Pmax * V ** (-k) # Isentropic compression

T = Tmax * V ** (k - 1) # Isentropic compression

# Plot the PV diagram

plt.figure(figsize=(10, 6))

plt.plot(V, P)

plt.xlabel('Volume (V/Vmax)')

plt.ylabel('Pressure (P/Pmax)')

plt.title('PV Diagram for Otto Cycle')

plt.grid(True)

# Calculate the thermal efficiency

thermal_efficiency = 1 - 1 / r ** (k - 1)

print(f"Thermal efficiency of the Otto Cycle: {thermal_efficiency:.2%}")

if __name__ == "__main__":

otto_cycle()

Thermal efficiency of the Otto Cycle: 56.47%

Q2.

import numpy as np

def otto_cycle():

# Define the parameters of the Otto Cycle

r = 8 # Compression ratio

k = 1.4 # Specific heat ratio

Tmin = 300 # Minimum temperature (K)

Pmin = 1e5 # Minimum pressure (Pa)

# Calculate the temperatures and pressures at each stage

Tc = Tmin * r ** (k - 1) # Temperature at the end of compression

Tmax = Tc * r ** (k - 1) # Maximum temperature

Pmax = Pmin * r ** k # Maximum pressure

# Create the PV diagram

V = np.linspace(Pmin / Pmax, 1, 100)

P = Pmax * V ** (-k) # Isentropic compression

T = Tmax * V ** (k - 1) # Isentropic compression

# Print the PV diagram

print("Volume (V/Vmax) Pressure (P/Pmax)")

for i in range(len(V)):

print(f"{V[i]:.3f} {P[i]:.3f}")

# Calculate the thermal efficiency

thermal_efficiency = 1 - 1 / r ** (k - 1)

print(f"Thermal efficiency of the Otto Cycle: {thermal_efficiency:.2%}")

if __name__ == "__main__":

otto_cycle()

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.