All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM : To write a MATLAB Program that helps Parsing NASA's thermodynamic data. OBJECTIVES : To write a function that extracts the 14 coefficients and calculates Specific Heat, Enthalpy & Entropy. Plot the Cp, Enthalpy and Entropy for each species. To calculate the molecular weight of each species. THEORY : Parsing…
Abhinav Mahto
updated on 03 Apr 2022
AIM : To write a MATLAB Program that helps Parsing NASA's thermodynamic data.
OBJECTIVES :
THEORY :
Parsing is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of formal grammar. The term Parsing comes from the Latin word 'Pars' meaning 'Part'.
In this project, we are going to parse NASA's thermodynamic data and evaluate its thermodynamic properties such as Cp, H and S for all the species given in the data file.
The formulae we are using are given below:
where,
Cp - Specific Heat (kJ/kg K)
R - Universal Gas Constant (kJ/kg K)
H - Enthalpy (kJ/kg)
T - Temperature (K)
S - Entropy (kJ/K)
Specific Heat of a Gas at Constant Pressure (Cp) -
It is defined as the amount of heat energy required to raise the temperature of the unit mass of gas by one degree at constant pressure. As per the above formula
Cp=R⋅[a1+a2⋅T+a3⋅T2+a4⋅T3+a5⋅T4]
Enthalpy (H) -
Enthalphy is the property of a gas which is equal to algebraic sum of internal energy and the product of pressure and volume. As per above formula
H=(R⋅T)⋅[a1+a2⋅(T2)+a3⋅(T23)+a4⋅(T34)+a5⋅(T45)+a6T]
Entropy (S) -
Entropy is a property of a thermodynamic system that expresses the direction or outcome of spontaneous changes in the system. It predicts that certain processes are irreversible or impossible, despite not violating the conservation of energy. As per the above formula
S =R⋅[a1⋅log(T)+a2⋅T+a3⋅(T22)+a4⋅(T33)+a5⋅(T44)+a7]
PROGRAM :
Main Program
% MATLAB Program for Parsing the NASA's thermodynamic data
clear all
close all
clc
% Step I : Given
% Universal Gas Constant (kJ/kg K)
R = 8.31446;
% Reading NASA's Thermodynamic Data File
f1 = fopen('THERMO.dat', 'r');
fgetl(f1);
% Step II : Defining Global Temperatures
% Converting strings into numeric value
templ = str2num(fgetl(f1));
low_temp = templ(1);
mid_temp = templ(2);
high_temp = templ(3);
% Step III : Skipping Unwanted Lines
for i = 1:3
fgetl(f1);
end
% Step IV : Global Temperature Range
T = linspace(low_temp, high_temp, 1000);
% Step V : Extracting First 7 Higher & Second 7 Lower Temperature Coefficients
for j = 1:53
l_str = fgetl(f1);
l = strsplit(l_str, ' ');
m = length(l);
species = l{1};
% Storing the values of 1st Line
l1_str = fgetl(f1);
% Finding Position of E
a = strfind(l1_str, 'E');
% Reading all the variable and convert
a1 = str2num(l1_str(1:a(1)+3));
a2 = str2num(l1_str((a(1)+4):(a(2)+3)));
a3 = str2num(l1_str((a(2)+4):(a(3)+3)));
a4 = str2num(l1_str((a(3)+4):(a(4)+3)));
a5 = str2num(l1_str((a(4)+4):(a(5)+3)));
% Storing the values of 2nd Line
l2_str = fgetl(f1);
% Finding Position of E
b = strfind(l2_str, 'E');
% Reading all the variable and convert
a6 = str2num(l2_str(1:b(1)+3));
a7 = str2num(l2_str((b(1)+4):(b(2)+3)));
a8 = str2num(l2_str((b(2)+4):(b(3)+3)));
a9 = str2num(l2_str((b(3)+4):(b(4)+3)));
a10 = str2num(l2_str((b(4)+4):(b(5)+3)));
% Storing the values of 2nd Line
l3_str = fgetl(f1);
% Finding Position of E
c = strfind(l3_str, 'E');
% Reading all the variable and convert
a11 = str2num(l3_str(1:c(1)+3));
a12 = str2num(l3_str((c(1)+4):(c(2)+3)));
a13 = str2num(l3_str((c(2)+4):(c(3)+3)));
a14 = str2num(l3_str((c(3)+4):(c(4)+3)));
% Step VI : Calculate Specific Heat, Enthalpy & Entropy
% if-else statement to find values of Cp, h and S at different Temperature
if T < mid_temp
Cp = R.*(a1 + a2.*T + a3.*(T.^2) + a4.*(T.^3) + a5.*(T.^4));
h = (R.*T).*(a1 + a2.*(T./2) + a3.*((T.^2)./3) + a4.*((T.^3)./4) + a5.*((T.^4)./5) + (a6./T));
S = R.*(a1.*log(T) + a2.*T + a3.*((T.^2)./2) + a4.*((T.^3)./3) + a5.*((T.^4)./4) + a7);
else
Cp = R.*(a8 + a9.*T + a10.*(T.^2) + a11.*(T.^3) + a12.*(T.^4));
h = (R.*T).*(a8 + a9.*(T./2) + a10.*((T.^2)./3) + a11.*((T.^3)./4) + a12.*((T.^4)./5) + (a13./T));
S = R.*(a8.*log(T) + a9.*T + a10.*((T.^2)./2) + a11.*((T.^3)./3) + a12.*((T.^4)./4) + a14);
end
% Step VII : Calculating Molecular Weight of each Species
W = molecular_weight(species);
mw_file = fopen('molecular_weight.txt', 'w');
fprintf(mw_file,'molecular_weight of %s is %d', species);
fclose(mw_file);
% Step VIII : Creating NASA's Thermodynamic Data for each Species
cur_dir = pwd;
mkdir(species);
cd(species);
% Step IX : Plotting Specific Heat, Enthalphy and Entrophy with Temperature
% Plot Specific Heat (Cp) vs Temperature (T)
figure(1)
plot(T, Cp, 'LineWidth',3,'Color','r');
xlabel('Temperature (K)')
ylabel('Specific Heat (kJ/kg K)');
title(sprintf('Specific Heat vs Temperature range of %s', species));
saveas(figure(1), 'Specific Heat.jpg');
grid on
% Plot Enthalphy (h) vs Temperature (T)
figure(2)
plot(T, h, 'LineWidth',3,'Color','g');
xlabel('Temperature (K)')
ylabel('Enthalphy (kJ/kg)');
title(sprintf('Enthalphy vs Temperature range of %s', species));
saveas(figure(2), 'Enthalphy.jpg');
grid on
% Plot Entrophy (S) vs Temperature (T)
figure(3)
plot(T, Cp, 'LineWidth',3,'Color','b');
xlabel('Temperature (K)')
ylabel('Entrophy (kJ/K)');
title(sprintf('Entrophy vs Temperature range of %s', species));
saveas(figure(3), 'Entrophy.jpg');
grid on
cd(cur_dir);
end
Explanation
Functional Program
function W = molecular_weight(species)
% Step I : Atomic Names
% Hydrogen (H), Carbon (C), Nitrogen (N), Oxygen (O) and Argon (Ar)
atoms = ['H', 'C', 'N', 'O', 'Ar'];
% Step II : Atomic Weight
atomic_weight = [1.00797 12.011 14.0067 15.9994 39.948];
% Step III : Starting Molecular Range
W = 0;
for i = 1:length(species)
for j = 1:length(atoms)
if strcmp(species(i), atoms(j))
W = W + atomic_weight(j);
position = j;
end
end
% Step IV : Finding Molecular Weight for more Species
n = str2num(species);
if n > 1
W = W + (atomic_weight(position).* (n-1));
end
end
% Step V : Results
fprintf('Molecular Weight of %s : ', species);
fprintf('%f', W);
disp(' ');
end
RESULTS :
Molecular Weight of Species
Screenshot of the window where all folders are saved
Plots for O2
Plots for N2
Plots for CO2
CONCLUSION :
By using MATLAB, we have obtained the temperature coefficients for high and low temperatures relative to their local temperature ranges. The specific heat, enthalpy and entropy of all species are calculated concerning their given formula, and graphs are drawn. Also, the molecular weights are calculated and displayed in the command window.
REFERENCES & COMMANDS USED :
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
MATLAB Project based on NASA's Thermodynamic Data
AIM : To write a MATLAB Program that helps Parsing NASA's thermodynamic data. OBJECTIVES : To write a function that extracts the 14 coefficients and calculates Specific Heat, Enthalpy & Entropy. Plot the Cp, Enthalpy and Entropy for each species. To calculate the molecular weight of each species. THEORY : Parsing…
03 Apr 2022 01:57 PM IST
MATLAB Project based on Rankine Cycle Simulator
AIM : To create a MATLAB Program that calculate the state points of the Rankine Cycle. OBJECTIVES : To create a Rankine Cycle Simulator using MATLAB. To determine its state points including (i) Net work output & (ii) Back work ratio. Plot its T-S and h-S diagram from the given data. Explain its working. THEORY…
03 Apr 2022 01:56 PM IST
MATLAB Program based on Curve fitting
AIM : To write a MATLAB code to fit a linear and cubic polynomial for the cp data. OBJECTIVES : Write code to fit a linear and cubic polynomial for the Cp data. Plot the linear and cubic fit curves along with the raw data points. Write a code to show splitwise method. Explain the parameters used to measure…
03 Apr 2022 01:47 PM IST
MATLAB Program to calculate Drag Force against a Cyclist
AIM: To create a Matlab program to calculate drag force against a cyclist. OBJECTIVES: To understand the flow of air while cycling and calculate the drag force which is acting opposite to it with respect to velocity and drag coefficient. Plot graph of Velocity vs Drag force & Drag Co-efficient vs Drag…
03 Apr 2022 01:43 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.