Challenge

Project 1 - Parsing NASA thermodynamic data

Aim:

    To write a function that extracts the co-efficients and to calculates the enthalpy, entropy and specific heats for all the species in the data file

Here R is the universal gas constant, T is the temeprature

Introduction:

Enthalpy

Enthalpy is defined as a change in internal energy and volume at constant pressure. It deals with the heat contained in any system. Thereby, it changes when heat enters or leaves a system. For example, it increases when heat is added and decreases when heat is withdrawn from that system. There are some molecules that take part in this change are called “internal enthalpy” and the molecules that do not are referred to as “external enthalpy”. The enthalpy is represented through the following equation.

 

                                                   E= U+ PV

Where E is enthalpy, U is the internal energy of any system, P is pressure, and V is volume

Entropy

Entropy is the measure of the disorder of the energy of a collection of particles. This idea is derived from Thermodynamics, which explains the heat transfer mechanism in a system. This term comes from Greek and means “a turning” point. It was first coined by Rudolf Clausius, a German physicist. He documented a precise form of the Second law of thermodynamics through entropy. 

 

It states that any spontaneous change in an isolated system for irreversible reaction always leads towards increasing entropy. For example, when we put a block of ice on a stove, these two make an integral part of a single isolated system. Thereby, the ice melts and entropy increases. Since all the spontaneous processes are irreversible, we can say that the entropy of the universe is increasing. Moreover, it can be concluded that more energy will be unavailable for work. Due to this, it is said that the universe is “running down”. 

 

The S.I unit of entropy is Joules per Kelvin. Also, it is expressed as ΔS, and the following is its equation. 

              ΔSsystem = Qrev / T

Where S denotes the change in entropy, Q denotes the reverse of heat and temperature is represented by T in the Kelvin scale. 

Specific heat 

In other words of specific heat a solid or liquid is the amount of heat that  raises the temperature of a unit mass of the solid through 1° C. We symbolise it as C. In S.I unit, it is the amount of heat that raises the temperature of 1 kg of solid or liquid through 1K.

Its unit in S.I system is always given as J kg-1 K-1 and CGS as cal g-1 C-1. If the amount of heat, ∆Q, required to raise the temperature of mass M through ∆T, then the formula for specific heat i

Specific Heat at Constant Pressure or Volume

  • The volume of solid remains constant when heated through a small range of temperature. This is known as specific heat at a constant volume. It is denoted as CV.
  • The pressure of solid remains constant when heated through a small range of temperature. This is known as specific heat at constant pressure which can be denoted as CP.

The behavior of gas when heat is supplied, the pressure and volume change in temperature and the amount of heat required to raise the temperature for 1gm of gas through 1°C depends on the way gas is heated. You can use several sets of values of P and V heat the gas.

Therefore,  specific heat possesses infinite values. The specific heat of the gas is not constant if you do not supply a constant amount of heat. So, you must have specific heat at a constant volume or pressure. For an ideal gas,

CP – CV = nR

where CP is heat capacity at constant pressure, CV  is heat capacity at constant volume, n is amount of substance, and R=8.3144598(48) J mol−1 K and is the molar gas constant.

Programe 

clear all
close all
clc
% Opening the Data File
f1 = fopen ('THERMO.dat','r');
fgetl(f1);
fgetl(f1);
fgetl(f1);
fgetl(f1);
fgetl(f1);
% Extracting all data
for i = 1:53
% Extracting name of gas
A = fget1(f1);
z = findstr(A,'');
species_name = A(1:z(1)-1);
%extraction Local Temperature of gas
a = findstr(A.'.');
t1 = A((a(1)-3):a(1)+3);
t1 = str2num(t1);
t2 = A(a(3)-4:a(3)+3);
t2 = str2num(t2);
t3 = A(a(2)-4:a(2)+3);
t3 = str2num(t3);
%t1 = low temperature
%t2 = mid temperature
%t3 = high temperature
% Extracting Co.efficient of gas species
B = fget1(f1);
b = findstr(B,'E');
a1 = B(1:b(1)+3);
a1 = str2num(a1);
a2 = B(b(1)+4:b(2)+3);
a2 = str2num(a2);
a3 = B(b(2)+4:b(3)+3);
a3 = str2num(a3);
a4 = B(b(3)+4:b(4)+3);
a4 = str2num(a4);
a5 = B(b(4)+4:b(5)+3);
a5 = str2num(a5);
c = fgetl(f1);
C = findstr (c,'E');
a6 = C(1:c(1)+3);
a6 = str2num(a6);
a7 = C(c(1)+4:c(2)+3);
a7 = str2num(a7);
a8 = C(c(2)+4:c(3)+3);
a8 = str2num(a8);
a9 = C(c(3)+4:c(4)+3);
a9 = str2num(a9);
a10 = C(c(4)+4:c(5)+3);
a10 = str2num(a10);
D = fgetl(f1);
d = findstr (D,'E');
a11 = D(1:d(1)+3);
a11 = str2num(a11);
a12 = D(d(1)+4:d(2)+3);
a12 = str2num(a12);
a13 = D(d(2)+4:d(3)+3);
a13 = str2num(a13);
a14 = D(d(3)+4:d(4)+3);
a14 = str2num(a14);
% First 7 are high temperature co. efficient from a1 to a7
% second 7 are high temperature co. efficient from a8 to a14
% Creating the Range of low and high values
T = linspace(t1,t3,1000);
R = 8.314;
% calculate for specific heat,Enthalpy and Entropy
for i = 1: length(T)
if T(i)>t2
cp(i) = (a1 + a2.*T(i) + a3.*T(i).^2 + a4.*T(i).^3 + a5.*T(i).^4)*R;
H(i) = (a1 + (a2.*T(i))/2 + (a3.*T(i).^2)/3 + (a4.*T(i).^3)/4 + (a5.*T(i).^4)/5 + (a6./T(i)))*R.*T(i);
S(i) = a1.log(T(i)) + a2.*T(i) + (a3.*T(i)^2)/2 + (a4.*T(i)^3)/3 + (a5.*T(i).^4)/4 + a7;
else
cp(i) = (a8 + a9.*T(i) + a10.*T(i).^2 + a11.*T(i).^3 + a12.*T(i).^4)*R;
H(i) = (a8 + (a9.*T(i))/2 + (a10.*T(i).^2)/3 + (a11.*T(i).^3)/4 + (a12.*T(i).^4)/5 + (a13./T(i)))*R.*T(i);
S(i) = a8.log(T(i)) + a9.*T(i) + (a10.*T(i)^2)/2 + (a11.*T(i)^3)/3 + (a12.*T(i).^4)/4 + a14;
end
end
% Molecular Weight Calculation
% Declaring species elements,atomic weight,molecular weight
elements = ['H','C','O','N','A','S'];
atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948 32.065];
mol_mass = 0;
 
for i = 1 : length (species_name)
for m = 1:length(atomic_weight)
if strcmp(species_name(1),elements(m))
mol_mass = mol_mass + atomic_weight(m);
position=m;
end
end
n = str2double(species_name(1));
if n>1
mol_mass + mol_mass + atomic_weight(position)*(n-1);
end
end
%Printing the molecular weight of the gas species
sprintf('Molecular Weight of %s is %f u',species_name,mol_mass)
% creating the folder for plots
mkdir(species_name)
cd(sprintf(species_name))
 
 
%Ploting specific heat Vs temperature
figure(1)
plot(T,(cp),'Color','r','lineWidth',2)
xlabel('Temperature(K)')
ylabel('Specific Heat(J/K kg)')
 
% ploting enthalpy vs temperature
figure(2)
plot(T,H,'Color','b','lineWidth',2)
xlabel('Temperature(K)')
ylabel('Enthalpy(J/K)')
 
%ploting entropy vs temperature
figure(3)
plot(T,S,'Color','g','lineWidth',2)
xlabel('Temperature(K)')
ylabel('Entropy(J/K)')
 
end
 
Results
 
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.

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.