Homework#2 1/24/25, 9:08 PM Homework #2 Synopsis In expansion and compression problems, we currently have two strategies: 1. Solving problems using ideal gas properties 2. Solving problems using real gas properties Regardless of the cases above, the task is the same we need to identify the number of degrees of freedom of the initial and final states of the fluid and we need to identify the pathway that the fluid takes during the compression. Reversible, adiabatic expansion will take 1 of 2 paths: 1. isoenthalpic pathway - when the fluid is expanded across a valve with no work performed. 2. isoentropic pathway - when the fluid is expanded across a turbine where work is extracted. Reversible, adiabatic compression can only take 1 path: 1. isoentropic pathway - when the fluid is compressed when either boundard or shaft work. Functions used: 1. np.interp 2. pd.read_csv 3. plt.plot Objectives 1. More practice with unit conversion 2. Working with real data and using interpolation as a means to extract quantities 3. Working with analytical functions file:///Users/jonathanschiff/Downloads/Homework%232.html Page 1 of 21 Homework#2 1/24/25, 9:08 PM Tutorial Let's start by importing our standard libraries In [ ]: import matplotlib.pyplot as plt import numpy as np from matplotlib import rc import os import pandas as pd from IPython.display import Markdown as md path2files = os.getcwd() + '/Homework2 - data' Loading Property Data: As a quick refresher from HW#1 that property databank data can be loaded using the pandas.read_csv function by telling the function that the text file is tab ('\t') delimited. This tells the functions that the columns in the text file are separated by tabs. The resulting data will be stored in a dataframe which acts like an excel worksheet where the columns of data can be operated on and plotted. Below I load in the 1 bar isobar data from the nist property databank In [ ]: meth6bar = pd.read_csv(os.path.join(path2files,'Methane.txt'), delimiter='\t') nitrogen_isobar_1bar = pd.read_csv(os.path.join(path2files,'Nitrogen1isobar.txt'), nitrogen_isobar_4bar = pd.read_csv(os.path.join(path2files,'Nitrogen4isobar.txt'), #nitrogen_isobar_2000bar = pd.read_csv(os.path.join(path2files,'nitrogen_isobar_20 Pandas Keys: To access a column in a pandas dataframe, we need to use its keys. Keys are usually strings in dataframes. To know the formatting of the keys, we can use the .keys() property of the dataframe which returns a list of the strings corresponding to the keys. In [ ]: print(nitrogen_isobar_1bar.keys()) Index(['Temperature (C)', 'Pressure (bar)', 'Density (mol/l)', 'Volume (l/mol)', 'Internal Energy (kJ/mol)', 'Enthalpy (kJ/mol)', 'Entropy (J/mol*K)', 'Cv (J/mol*K)', 'Cp (J/mol*K)', 'Sound Spd. (m/ s)', 'Joule-Thomson (K/bar)', 'Viscosity (uPa*s)', 'Therm. Cond. (W/m*K)', 'Phase'], dtype='object') file:///Users/jonathanschiff/Downloads/Homework%232.html Page 2 of 21 Homework#2 1/24/25, 9:08 PM Extracting data and plotting: Now that we know the keys we can extract properties of interest and plot them or perform calculations with them. Copying and pasting the strings within the list above makes this task simple. Note that the column associated with each key is accessed by the correspond key string passed to the entry in the key dictionary using the dataframe[key] format. In the example below, we plot the enthalpy vs. the temperature. In [ ]: key1 = 'Temperature (C)' key2 = 'Enthalpy (kJ/mol)' key3 = 'Entropy (J/mol*K)' key4 = 'Density (kg/m3)' plt.figure(dpi=300,figsize=(1.5,1.5)) Temperature = nitrogen_isobar_1bar[key1] Enthalpy = nitrogen_isobar_1bar[key2] plt.plot(Temperature, Enthalpy) plt.xlabel(key1) plt.ylabel(key2) Out[ ]: Text(0, 0.5, 'Enthalpy (kJ/mol)') file:///Users/jonathanschiff/Downloads/Homework%232.html Page 3 of 21 Homework#2 1/24/25, 9:08 PM Interpolation: Often when working with real gas properties, we need to interpolate because the data is only available at finite increments and the value that we seeks is not available in our table. For this we can use the np.interpolate command. Let's say that I want to find the enthalpy at 25 C using the isobar above, I do that using the code below and print the result in a formatted f-string (this makes things nice and tidy). Note that the formatting string works {python_variable}:.1f which is a floating point number that will print off values up to only one decimal place. In [ ]: H = np.interp(25, Temperature, Enthalpy) print(f'The enthalpy at 25 C is {H:.1f} kJ/kg') The enthalpy at 25 C is 8.7 kJ/kg file:///Users/jonathanschiff/Downloads/Homework%232.html Page 4 of 21 Homework#2 1/24/25, 9:08 PM We can confirm that the interpolation was successful by plotting the interpolated value. The red star lands on the line so the interpolation is successful. In [ ]: plt.figure(dpi=300,figsize=(1.5,1.5)) plt.plot(Temperature,Enthalpy, '-r') plt.plot([25],[H],'r*') plt.xlim(0,100) plt.ylim(0,500) plt.xlabel(key1) plt.ylabel(key2) Out[ ]: Text(0, 0.5, 'Enthalpy (kJ/mol)') Interpolation works for most things, but sometimes when the data is non-monotonic the interpolation can fail (where there are multiple y-values for the same x-value). In these file:///Users/jonathanschiff/Downloads/Homework%232.html Page 5 of 21 Homework#2 1/24/25, 9:08 PM cases, it is best to use masking for the region of the data that you anticipate finding the answer. Problem #1: An adiabatic compressor operates at steady state to compress nitrogen from 1 to 4 bar. Using the NIST property database, compute the work required for this compression. Note that the nitrogen enters the compressor at −80 o C . 1. State your assumptions and write in the space provided below the simplified energy and entropy balance expression for the compression. dU dt = 0 = Σ(Ṅ H̄) + Ws because Q̇ = 0 and dV = 0 Ws = Ṅ(H̄2 − H̄1 ) dS ˙ =0 = 0 = Σ(Ṅ S̄) because Sgen dt S¯1 = S¯2 2. Calculate the enthalpy change associated with the reversible compression and compare it to the enthalpy change for the equivalent ideal gas. Compute the temperature of the outlet gas in both cases In [ ]: print(nitrogen_isobar_1bar.keys()) Index(['Temperature (C)', 'Pressure (bar)', 'Density (mol/l)', 'Volume (l/mol)', 'Internal Energy (kJ/mol)', 'Enthalpy (kJ/mol)', 'Entropy (J/mol*K)', 'Cv (J/mol*K)', 'Cp (J/mol*K)', 'Sound Spd. (m/ s)', 'Joule-Thomson (K/bar)', 'Viscosity (uPa*s)', 'Therm. Cond. (W/m*K)', 'Phase'], dtype='object') In [ ]: t1 = nitrogen_isobar_1bar[key1] entro1 = nitrogen_isobar_1bar[key3] file:///Users/jonathanschiff/Downloads/Homework%232.html Page 6 of 21 Homework#2 1/24/25, 9:08 PM entha1 = nitrogen_isobar_1bar[key2] s1 = np.interp(-80,t1,entro1) s2=s1 h1 = np.interp(-80,t1,entha1) entha4 = nitrogen_isobar_4bar[key2] entro4 = nitrogen_isobar_4bar[key3] t4 = nitrogen_isobar_4bar[key1] h2 = np.interp(s2,entro4,entha4) t2 = np.interp(s2,entro4,t4) print(f'Enthalpy change: {h2-h1} kJ/mol') print(f'Enthalpy change: {(h2-h1)/28.02*1000} kJ/kg') print(f'Real Gas temp out: {t2+273.15}K or {t2}C') Enthalpy change: 2.728166440702675 kJ/mol Enthalpy change: 97.36496933271503 kJ/kg Real Gas temp out: 287.29680370289384K or 14.146803702893845C In [ ]: R = 8.314 cp = 28.318 ti1 = -80+273.15 ti2 = 4**(R/C_p)*ti1 print(f' ideal gas out temp = {ti2} K or {ti2-273.15}C') print(f'Ideal enthalpy change = {cp*(ti2-ti1)/1000} kJ/mol') ideal gas out temp = 290.1723468190625 K or 17.022346819062534C Ideal enthalpy change = 2.747478817222213 kJ/mol 3. Calculate the corresponding amount of work for the compression if the feed is 5000 mol/s In [ ]: w = (h2-h1)*5000 print(f'Work: {w}kW') Work: 13640.832203513375kW Problem #2: A cylinder, initially charged with nitrogen at 2000 bar and 25 C , is vented through a valve. The result of this adiabatic expansion is that both the temperature and pressure of the gas within the cylinder decrease. The gas exits the cylinder file:///Users/jonathanschiff/Downloads/Homework%232.html Page 7 of 21 Homework#2 1/24/25, 9:08 PM expanding to atmospheric pressure. The volume of the cylinder is 1 m3 . 1. If there is negligable heat transfer during the expansion, what is the final temperature within the cylinder? What mass of nitrogen remains in the cylinder? Assume nitrogen is an ideal gas with a heat capacity Cp = 28.318 J/mol ∗ K ) In [ ]: tn2 = ((1.0135/2000)**(8.315/28.318))*(25+273.15) print(f'Final temp: {tn2}K') n = (1.01*10**5)/(8.314*tn2) print(f'Mass in the cylinder: {n*28.02/1000}kg') Final temp: 32.12662273156453K Mass in the cylinder: 10.595328134508662kg 2. Repeat (1) using real gas properties of nitrogen. In [ ]: Nitrogen2000isobar = pd.read_csv(os.path.join(path2files,'Nitrogen2000isobar.txt') Nitrogen101isobar = pd.read_csv(os.path.join(path2files,'Nitrogen101isobar.txt'), In [ ]: ty1 = Nitrogen2000isobar[key1] entroy1 = Nitrogen2000isobar[key3] enthay1 = Nitrogen2000isobar[key2] s1 = np.interp(25,ty1,entroy1) print(s1) s2=s1 h1 = np.interp(25,ty1,enthay1) entha101 = Nitrogen101isobar[key2] entro101 = Nitrogen101isobar[key3] t101 = Nitrogen101isobar[key1] h2 = np.interp(s2,entro101,entha101) t2 = np.interp(s2,entro101,t101) print(f'Enthalpy change: {h2-h1} kJ/mol') print(f'Gas temp out: {t2+273.15}K') dens = Nitrogen101isobar['Density (mol/l)'] dfinal = np.interp(s1,entro101,dens) print(f'Mass in the cylinder is {dfinal*28.02}kg') file:///Users/jonathanschiff/Downloads/Homework%232.html Page 8 of 21 Homework#2 1/24/25, 9:08 PM 121.53529739776953 Enthalpy change: -10.844793054021956 kJ/mol Gas temp out: 77.32999999999998K Mass in the cylinder is 337.966259144853kg Problem #3: In order to fuel booster, SpaceX must fill the fuel tanks with ∼ 800 tons of liquid methane and ∼ 3000 tons of liquid oxygen. The tanks hold the saturated liquids at 6 bar while the ship awaits launch. A launch at sea level results in the firing of all 33 raptor engines with the exhaust gas velocity of 3.2 km/s. Using the NIST Property database for liquid methane and liquid oxygen and assuming the fuel to oxidizer ratio during combustion is given by the ratio of volumes of liquid methane and oxygen in the tanks, answer the following questions. 1. What are the temperatures and densities of the liquid methane and liquid oxygen in the tanks? Plot the isobars of liquid methane as density (ρ) in kg/m3 vs. temperature (T) o C and identify the saturated liquids. In [ ]: mmmeth = 16.04 mmox = 32 In [ ]: keydense = 'Density (mol/l)' keytemp = 'Temperature (C)' methtemp6bar = meth6bar[keytemp] Dens = meth6bar[keydense]*mmmeth for i in range (methtemp6bar.size): checkTemp = methtemp6bar[i] if checkTemp == methtemp6bar[i+1]: print(f'Tcrit for methane: {checkTemp}C') print(f'Density at Tcrit: {Dens[i]}kg/m^3') Tcritmeth6 = checkTemp denscritmeth = Dens[i] break file:///Users/jonathanschiff/Downloads/Homework%232.html Page 9 of 21 Homework#2 1/24/25, 9:08 PM ox6bar = pd.read_csv(os.path.join(path2files,'Oxygen6bar.txt'), delimiter='\t') keydenseox6 = 'Density (mol/l)' keytempox6 = 'Temperature (C)' Tcox6 = ox6bar[keytemp] Densox6 = ox6bar[keydense]*mmox densityox6 = Densox6*16.01*0.001 for i in range (Tcox6.size): checkTempox6 = Tcox6[i] if checkTempox6 == Tcox6[i+1]: print(f'Tcrit for oxygen: {checkTempox6}C') print(f'Density at Tcrit: {Densox6[i]}kg/m^3') Tcritox6 = checkTempox6 denscritox = Densox6[i] break mask2 = Tcox6 <-80 mask1 = methtemp6bar <-80 plt.figure(dpi=300,figsize=(1.5,1.5)) plt.xlabel(keytempox6) plt.ylabel('Density (kg/m3)') plt.plot([Tcritox6],[denscritox],'r*') plt.plot([Tcritmeth6],[denscritmeth],'r*') plt.plot(Tcox6[mask2],Densox6[mask2],label = 'Oxygen') plt.plot(methtemp6bar[mask1],Dens[mask1],label = 'Methane') plt.legend(fontsize=4,frameon=False) Tcrit for methane: -134.42C Density at Tcrit: 379.07331999999997kg/m^3 Tcrit for oxygen: -161.69C Density at Tcrit: 1026.976kg/m^3 Out[ ]: <matplotlib.legend.Legend at 0x15ad7f970> file:///Users/jonathanschiff/Downloads/Homework%232.html Page 10 of 21 Homework#2 1/24/25, 9:08 PM 2. During launch, the methane and oxygen are pressurized by separate turbopumps to 860 bar and 430 bar respectively before being pumped into the combustion chamber. Construct a Temperature (T) vs. Entropy (S) diagram for this compression and indicate the temperature and entropy of the gas exiting the turbopump. In [ ]: meth860bar = pd.read_csv(os.path.join(path2files,'Methane860bar.txt'), delimiter=' ox430bar = pd.read_csv(os.path.join(path2files,'Oxygen430bar.txt'), delimiter='\t' In [ ]: #do the equation balances, end result is constant entropy entropymeth860 = meth860bar['Entropy (J/mol*K)'] tempmeth860 = meth860bar['Temperature (C)'] entropymeth6 = meth6bar['Entropy (J/mol*K)'] entropyox430 = ox430bar['Entropy (J/mol*K)'] file:///Users/jonathanschiff/Downloads/Homework%232.html Page 11 of 21 Homework#2 1/24/25, 9:08 PM tempox430 = ox430bar['Temperature (C)'] entropyox6 = ox6bar['Entropy (J/mol*K)'] In [ ]: satmeth6 = meth6bar [Dens == denscritmeth] satox6 = ox6bar [Densox6 == denscritox] In [ ]: #smeth = np.interp(Tcritmeth6,methtemp6bar,entropymeth6) smeth = float(satmeth6['Entropy (J/mol*K)'].iloc[0]) sox = float(satox6['Entropy (J/mol*K)'].iloc[0]) print(f'Entropy meth: {smeth}J/molK') print(f'entropy ox: {sox}J/molK') Tmeth860 = np.interp(smeth,entropymeth860,tempmeth860) Tox430 = np.interp(sox,entropyox430,tempox430) print(f'Temp meth: {Tmeth860}C') print(f'Temp ox: {Tox430}C') Entropy meth: 12.472J/molK entropy ox: 105.89J/molK Temp meth: -107.10666666666667C Temp ox: -149.3116030534351C In [ ]: print('Different units for easier grading:') print(f'Entropy meth: {smeth/mmmeth} J/gK') print(f'entropy ox: {sox/mmox} J/gK') print(f'Temp meth: {Tmeth860+273.15} K') print(f'Temp ox: {Tox430+273.15} K') Different units for easier grading: Entropy meth: 0.7775561097256858 J/gK entropy ox: 3.3090625 J/gK Temp meth: 166.0433333333333 K Temp ox: 123.83839694656487 K In [ ]: plt.figure(dpi=300,figsize=(1.5,1.5)) plt.plot(entropymeth860, tempmeth860, label = 'Methane 860 bar') plt.ylabel(keytempox6) plt.xlabel('Entropy (J/mol*K)') plt.plot([smeth],[Tmeth860],'r*') plt.plot(entropymeth6, methtemp6bar, label = 'Methane 6bar' ) plt.plot([smeth],[Tcritmeth6],'r*') plt.plot(entropyox430, tempox430, label = 'Oxygen 430bar') file:///Users/jonathanschiff/Downloads/Homework%232.html Page 12 of 21 Homework#2 1/24/25, 9:08 PM plt.plot([sox],[Tox430],'r*') plt.plot(entropyox6, Tcox6, label = 'Oxygen 6bar' ) plt.plot([sox],[Tcritox6],'r*') plt.legend(fontsize=4,frameon=False) Out[ ]: <matplotlib.legend.Legend at 0x15ae13310> 3. Assuming a liquid flow rate of 930 kg/s, what is the work required for the compression in both turbopumps? Assume negligible heat transfer in the turbopumps. Calculate the total work of compression required for all engines. ˙ ^ ^ file:///Users/jonathanschiff/Downloads/Homework%232.html Page 13 of 21 Homework#2 1/24/25, 9:08 PM Ẇ = ṁ(H^2 − H^1 ) Find mass flows and enthalpies for each species. In [ ]: massmeth = 800*907.185 massox = 3000*907.185 mtot = massox+massmeth rmassox = massox/mtot rmassmeth = 1-rmassox print(rmassmeth) 0.21052631578947367 In [ ]: mflowmeth = 930*rmassmeth mflowox = 930*rmassox print(mflowmeth) 195.78947368421052 In [ ]: print(sox) print(smeth) 105.89 12.472 In [ ]: enthalpyoxin = ox6bar['Enthalpy (kJ/mol)'] enthalpyoxout = ox430bar['Enthalpy (kJ/mol)'] enthalpymethin = meth6bar['Enthalpy (kJ/mol)'] enthalpymethout = meth860bar['Enthalpy (kJ/mol)'] h2ox = np.interp(Tox430,tempox430,enthalpyoxout) h1ox = float(satox6['Enthalpy (kJ/mol)'].iloc[0]) h2ox = h2ox/mmox*1000 h1ox = h1ox/mmox*1000 print(h2ox) print(h1ox) print(h2ox-h1ox) Wox = mflowox*(h2ox-h1ox) print(f'Power from oxygen: {Wox} kJ/s') h2meth = np.interp(Tmeth860,tempmeth860,enthalpymethout)/mmmeth*1000 h1meth = float(satmeth6['Enthalpy (kJ/mol)'].iloc[0])/mmmeth*1000 Wmeth = mflowmeth*(h2meth-h1meth) print(h2meth-h1meth) print(f'Power from meth: {Wmeth} kJ/s') Wtot = Wox+Wmeth print(Wtot) file:///Users/jonathanschiff/Downloads/Homework%232.html Page 14 of 21 Homework#2 1/24/25, 9:08 PM print('This section is just for me, the answers are in the next set of print state -55.986283396946554 -95.97812499999999 39.99184160305344 Power from oxygen: 29362.43107171555 kJ/s 210.51390674452594 Power from meth: 41216.40700471771 kJ/s 70578.83807643325 This section is just for me, the answers are in the next set of print statem ents! In [ ]: #above is just working it out, here it is simplified: print(f'Power from the methane: {Wmeth/1000} MW ') print(f'Power from the oxygen: {Wox/1000} MW ') print(f'Total power: {Wmeth/1000+Wox/1000} MW ') Power from the methane: 41.21640700471771 MW Power from the oxygen: 29.362431071715548 MW Total power: 70.57883807643326 MW In [ ]: # multiply by time to get total energy print(f'Energy from the methane: {Wmeth/1000*112.32658846529814} MJ ') print(f'Energy from the oxygen: {Wox/1000*112.32658846529814} MJ ') print(f'Total Energy: {(Wmeth/1000+Wox/1000)*112.32658846529814} MJ ') Energy from the methane: 4629.698387637158 MJ Energy from the oxygen: 3298.1817113332754 MJ Total Energy: 7927.880098970433 MJ In [ ]: #h1ox = np.interp(sox,entropyox6,enthalpyoxin) #h1meth = np.interp(smeth,entropymeth6,enthalpymethin)/mmmeth*1000 In [ ]: #byhand dhmethhand = 712.984 dhoxhand = 234.031 In [ ]: ### #Wmethhand = mflowmeth*dhmethhand #print(Wmethhand) #Woxhand = mflowox*dhoxhand #print(Woxhand) #Wtothand = Wmethhand+Woxhand #print(f'total wattage: {Wtothand}kJ/s') #print(Wtothand*1000) #print((Wtothand*1000)*10**(-6)) #print(Wtot*1000*10**(-6)) 4. How long does it take for the tanks to empty? file:///Users/jonathanschiff/Downloads/Homework%232.html Page 15 of 21 Homework#2 1/24/25, 9:08 PM In [ ]: t = (mtot)/(mflowmeth+mflowox)/33 print(f'it takes {t}s or {t/60}mins to empty the tank') it takes 112.32658846529814s or 1.8721098077549692mins to empty the tank 5. The combustion chamber is optimized so that the combustion gases expand to atmospheric pressure prior to exiting the nozzle. This ensures that all of the enthalpy of the pressurized liquids entering the combustion chamber is converted to kinetic energy. Based on the exit velocity of the combustion gases, estimate the amount of heat generated as a product of combustion in J/mol of methane. ^ = KE Due to assumptions, we can assume the following: ΔH^vap + ΔH comb ^ We can find ΔH^vap and KE, so we can find ΔHcomb In [ ]: print('The following has a lot of space where I work out enthalpy change in differ The following has a lot of space where I work out enthalpy change in differe nt ways, look at the end for my final answer In [ ]: methaneatm = pd.read_csv(os.path.join(path2files,'Methane101bar.txt'), delimiter= methaneatmenth = methaneatm['Enthalpy (kJ/mol)'] methaneatmtemp = methaneatm['Temperature (C)'] In [ ]: oxyatm = pd.read_csv(os.path.join(path2files,'Oxygen101bar.txt'), delimiter='\t') oxyatmenth = oxyatm['Enthalpy (kJ/mol)'] oxyatmtemp = oxyatm['Temperature (C)'] In [ ]: plt.plot(methaneatmtemp,methaneatmenth) Out[ ]: [<matplotlib.lines.Line2D at 0x15aea0d60>] file:///Users/jonathanschiff/Downloads/Homework%232.html Page 16 of 21 Homework#2 1/24/25, 9:08 PM In [ ]: plt.plot(oxyatmtemp,oxyatmenth) Out[ ]: [<matplotlib.lines.Line2D at 0x15af187f0>] file:///Users/jonathanschiff/Downloads/Homework%232.html Page 17 of 21 Homework#2 1/24/25, 9:08 PM In [ ]: # Initialize variables topenthox = None bottomenthox = None # Loop through the temperature array for i in range(oxyatmenth.size - 1): # Avoid out-of-bounds index check = oxyatmtemp[i] print() # Check for constant temperature at the "bottom point" if check == oxyatmtemp[i + 1]: # Temperature constant bottomenthox = oxyatmenth[i] # Interpolate enthalpy at the bottom point # Search for when temperature stops being constant for j in range(i, oxyatmenth.size - 1): # Inner loop avoids out-of-bounds check2 = oxyatmtemp[j] print(check2) if check2 != oxyatmtemp[j + 1]: # Temperature changes topenthox = oxyatmenth[j] # Interpolate at the top point break break # Exit the outer loop once top and bottom points are found print(topenthox) print(bottomenthox) # Calculate enthalpy difference if topenthox is not None and bottomenthox is not None: file:///Users/jonathanschiff/Downloads/Homework%232.html Page 18 of 21 Homework#2 1/24/25, 9:08 PM denthox = topenthox - bottomenthox print(f"Enthalpy Difference (Hvap): {denthox}") else: print("Could not find both top and bottom points.") h430ox = np.interp(Tox430,tempox430,enthalpyoxout) h860meth = np.interp(Tmeth860,tempmeth860,enthalpymethout) print(h430ox) -182.96 -182.96 2.55 -4.2675 Enthalpy Difference (Hvap): 6.8175 -1.7915610687022898 In [ ]: # Initialize variables topenthmeth = None bottomenthmeth = None # Loop through the temperature array for i in range(methaneatmenth.size - 1): # Avoid out-of-bounds index check = methaneatmtemp[i] print() # Check for constant temperature at the "bottom point" if check == methaneatmtemp[i + 1]: # Temperature constant bottomenthmeth = methaneatmenth[i] # Interpolate enthalpy at the bottom p # Search for when temperature stops being constant for j in range(i, methaneatmenth.size - 1): # Inner loop avoids out-of-bo check2 = methaneatmtemp[j] print(check2) if check2 != methaneatmtemp[j + 1]: # Temperature changes topenthmeth = methaneatmenth[j] # Interpolate at the top point break break # Exit the outer loop once top and bottom points are found print(topenthmeth) print(bottomenthmeth) # Calculate enthalpy difference if topenthmeth is not None and bottomenthmeth is not None: denthmeth = topenthmeth - bottomenthmeth print(f"Enthalpy Difference (Hvap): {denthmeth}") else: print("Could not find both top and bottom points.") file:///Users/jonathanschiff/Downloads/Homework%232.html Page 19 of 21 Homework#2 1/24/25, 9:08 PM #not done, need to midterm study -161.48 -161.48 8.1952 0.00016787 Enthalpy Difference (Hvap): 8.19503213 In [ ]: moldenthmeth = denthmeth moldenthox = denthox moldenthtot = moldenthox+moldenthmeth In [ ]: denthmeth = denthmeth/mmmeth*1000 denthox = denthox/mmox*1000 denthtot = denthox+denthmeth print(denthtot) 723.9591025561098 In [ ]: #total moles moltot = 1000*massox/(mmox)+1000*massmeth/(mmmeth) print(moltot) 130294728.41334164 In [ ]: v = 3.2*1000 KE = 0.5*v**2 molKE = KE/moltot print(molKE) 0.039295526859363966 In [ ]: enthcomb = KE-denthtot print(f'Enthalpy of combustion is {enthcomb}kJ/kg') Enthalpy of combustion is 5119276.040897444kJ/kg In [ ]: h430ox = h430ox/mmox*1000 h860meth = h860meth/mmmeth*1000 Hliquid = h430ox*rmassox + h860meth*rmassmeth vapsatmeth6_dens = np.max(meth6bar['Density (mol/l)'][meth6bar['Phase'] == 'vapor' vapsatox6_dens = np.max(ox6bar['Density (mol/l)'][ox6bar['Phase'] == 'vapor']) #from NIST SatTempmeth6 = -134.42 file:///Users/jonathanschiff/Downloads/Homework%232.html Page 20 of 21 Homework#2 1/24/25, 9:08 PM SatTempox6 = -161.69 satvapormeth6 = meth6bar[meth6bar['Density (mol/l)']==vapsatmeth6_dens] satvaporox6 = ox6bar[ox6bar['Density (mol/l)']==vapsatox6_dens] Svapmeth6 = float(satvapormeth6['Entropy (J/mol*K)'].iloc[0]) Svapox6 = float(satvaporox6['Entropy (J/mol*K)'].iloc[0]) h860meth_vap = np.interp(Svapmeth6,entropymeth860,enthalpymethout) h430ox_vap = np.interp(Svapox6,entropyox430,enthalpyoxout) h860meth_vap = h860meth_vap/mmmeth*1000 h430ox_vap = h430ox_vap/mmox*1000 Hvap = h430ox_vap*rmassox + h860meth_vap*rmassmeth dHvap = Hvap-Hliquid dHcomb = KE-dHvap In [ ]: print(f'Enthalpy of combustion is {dHcomb} kJ/kg') print('FINAL ANSWER') Enthalpy of combustion is 5119497.60997892 kJ/kg FINAL ANSWER file:///Users/jonathanschiff/Downloads/Homework%232.html Page 21 of 21