All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To parse the thermodynamic data ansd calculate the thermodynamic properties of various gas species using MATLAB DESCRIPTION: PARSING: Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural…
sriram srikanth
updated on 19 Nov 2020
AIM:
To parse the thermodynamic data ansd calculate the thermodynamic properties of various gas species using MATLAB
DESCRIPTION:
PARSING: Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar.
ENTHALPY (H): Enthalpy is a property of a thermodynamic system, that is a convenient state function preferred in many measurements in chemical, biological, and physical systems at a constant pressure. It is defined as the sum of the system's internal energy and the product of its pressure and volume.
ENTROPY (S): In statistical mechanics, entropy is an extensive property of a thermodynamic system. It quantifies the number of microscopic configurations that are consistent with the macroscopic quantities that characterize the system.
SPECIFIC HEAT (CP): The specific heat capacity, of a substance is the heat capacity of a sample of the substance divided by the mass of the sample. Informally, it is the amount of energy that must be added, in the form of heat, to one unit of mass of the substance in order to cause an increase of one unit in its temperature.
MOLECULAR WEIGHT (M): The molecular mass is the mass of a given molecule, It is measured in daltons. Different molecules of the same compound may have different molecular masses because they may contain different isotopes of an element.
GAS CONSTANT (R): The gas constant is a physical constant denoted by R and is expressed in terms of units of energy per temperature increment per mole. The gas constant value is equivalent to Boltzmann constant but expressed as the pressure-volume product instead of energy per increment of temperature per particle.
TEMPERATURE (T): Temperature is a physical property of matter that quantitatively expresses hot and cold. It is the manifestation of thermal energy, present in all matter, which is the source of the occurrence of heat, a flow of energy, when a body is in contact with another that is colder.
PROCEDURE:
Main code:
clear all
close all
clc
% reading the file data
f1 = fopen('THERMO.dat','r');
line_1 = fgetl(f1);
line_2 = fgetl(f1);
% extract global temprature range
A=strsplit(line_2,' ');
global_low_temp = str2num(A{2});
global_mid_temp = str2num(A{3});
global_high_temp = str2num(A{4});
% skipping unwanted line
for i = 1:3
omit = fgetl(f1);
end
frewind(f1);
tline=0;
while ~feof(f1)
line=fgetl(f1);
a=sscanf(line,'%c');
%checking for end
c=a(1:3);
d='END';
if c==d
break
end
tline=tline+1;
end
% calculating the no of species
no_species=(tline-5)/4;
frewind(f1);
for i=1:5
fgetl(f1);
end
for i = 1:no_species
line_3 = fgetl(f1);
line_3_split = strsplit(line_3,' ');
species_name = line_3_split(1);
species_name = species_name{1};
splits = strsplit(line_3,'G ');
lt = str2num(splits{2});
lt_low = lt(1);
lt_mid = lt(3);
lt_high = lt(2);
% co efficients
line_4 = fgetl(f1);
c = findstr(line_4,'E');
a1 = str2num(line_4(1:c(1)+3));
a2 = str2num(line_4(c(1)+4:c(2)+3));
a3 = str2num(line_4(c(2)+4:c(3)+3));
a4 = str2num(line_4(c(3)+4:c(4)+3));
a5 = str2num(line_4(c(4)+4:c(5)+3));
line_5=fgetl(f1);
a6=str2num(line_5(1:c(1)+3));
a7=str2num(line_5(c(1)+4:c(2)+3));
a8=str2num(line_5(c(2)+4:c(3)+3));
a9=str2num(line_5(c(3)+4:c(4)+3));
a10=str2num(line_5(c(4)+4:c(5)+3));
line_6=fgetl(f1);
a11=str2num(line_6(1:c(1)+3));
a12=str2num(line_6(c(1)+4:c(2)+3));
a13=str2num(line_6(c(2)+4:c(3)+3));
a14=str2num(line_6(c(3)+4:c(4)+3));
% calculating the values of Cp,enthalpy and entrophy
% universal gas constant
T=linspace(lt_low,lt_high,100);
R=8.314;
Cp= specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
H= enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
S= entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
% calculating the molecular weight of species
Molecular_weight(i)=molecular_weight(species_name);
% plotting
mkdir(species_name);
figure(1)
plot(T,Cp,'linewidth',3,'color','black')
xlabel('Temperature')
ylabel('Specific heat')
title (species_name)
figure(2)
plot(T,H,'linewidth',3,'color','black')
xlabel('Temperature')
ylabel('Enthalpy')
title(species_name)
figure(3)
plot(T,S,'linewidth',3,'color','black')
xlabel('Temperature')
ylabel('Entropy')
title(species_name)
cd(species_name)
saveas(figure(1),'T vs Cp.jpg')
saveas(figure(2),'T vs H.jpg')
saveas(figure(3),'T vs S.jpg')
cd ('..')
% printing molecular weight data in command window
fprintf('species name : %s n',species_name)
fprintf('Molecular weight : %s n',Molecular_weight(i))
end
Function to find Enthalpy:
function H = enthalpy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
if(T>lt_mid)
H = (a1+a2*T./2+a3*T.^2./3+a4*T.^3./4+a5*T.^4./5+a6./T)*R.*T;
else
H = (a8+a9*T./2+a10*T.^2./3+a11*T.^3./4+a12*T.^4./5+a13./T)*R.*T;
end
Function to find Entropy:
function S = entropy(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
if(T>lt_mid)
S = (a1*log(T)+a2.*T+a3*T.^2./2+a4*T.^3./3+a5*T.^4./4+a7)*R;
else
S = (a8*log(T)+a9.*T+a10*T.^2./2+a11*T.^3./3+a12*T.^4./4+a14)*R;
end
Function to find Specific Heat:
function Cp = specific_heat(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,lt_mid,T,R);
if(T>lt_mid)
Cp = (a1+a2*T+a3*T.^2+a4*T.^3+a5*T.^4)*R;
else
Cp = (a8+a9*T+a10*T.^2+a11*T.^3+a12*T.^4)*R;
end
Function to find Molecular Weight:
function [Molecular_weight] = molecular_weight(species_name)
Atomic_mass = [15.999,1.00784,32.065,12.0107,14.0067,39.948];
Elements = ['O','H','S','C','N','A'];
Molecular_weight = 0;
u = 0;
for i = 1:length(species_name)
for j = 1:length(Elements)
if(strcmp(species_name(i),Elements(j)))
Molecular_weight = Molecular_weight+Atomic_mass(j);
u = j;
end
end
end
num=str2double(species_name(i));
if(num>1)
Molecular_weight = Molecular_weight+Atomic_mass(u)*(num-1);
end
end
RESULTS:
GRAPHS:
Plot for species CO2:
Plot for species N2:
Plot for species O2:
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...
Week - 12 - Creating the locator, writing and reading the node data
CHALLENGE-12
30 Jul 2022 07:44 AM IST
Project 1- Building a Master TCL/TK Macro
PROJECT-1
30 Jul 2022 07:42 AM IST
Project - 2 - Generating the report for hypermesh file
PROJECT-2
30 Jul 2022 07:41 AM IST
Week - 11 - Element quality check
AIM: To check the element quality. OBJECTIVE: Create element quality check macro for 2D and 3D elements. Create a button for each criterion. On pressing the button the elements should be highlighted using temp nodes. Entry boxes next to the buttons will accept the quality criteria value. PROCEDURE:…
16 Feb 2022 11:29 AM 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.