Challenge

Project 1 - Parsing NASA thermodynamic data

AIM:

  • Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.
  • Download this file using this link given in the question above=> NASA thermodynamic data

SPECIFIC HEAT:

  • It is defined as the quantity of heat required to raise the temperature of one gram of a substance by one Celsius degree.

Formula,

Cp = (a1 + a2T + a3T^2 + a4T^3 + a5T^4)*R

FUNCTION PROGRAM:

function cp=specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,r,global_medium_temp)
if temp<=global_medium_temp
    cp=r*(a8+(a9*temp)+(a10*(temp).^2)+(a11*(temp).^3)+(a12*(temp).^4));
else
    cp=r*(a1+(a2*temp)+(a3*(temp).^2)+(a4*(temp).^3)+(a5*(temp).^4));
end

EXPLANATION:

  • Using functions i have made a template to calculate the specific heat.

ENTROPHY:

  • It is the measure of a system's thermal energy per unit temperature that is unavailable for doing useful work.
  • Because work is obtained from ordered molecular motion, the amount of entropy is also a measure of the molecular disorder, or randomness, of a system.

Formula,

S = (a1 logT + a2T + (a3T^2/2) + (a4T^3)/3 + (a5T^4)/4 + a7)*R

FUNCTION PROGRAM:

function s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,r,global_medium_temp)
if temp<=global_medium_temp
    s=r.*(a8.*log(temp)+(a9.*temp)+(a10*((temp).^2)/2)+(a11*((temp).^3)/3)+(a12*((temp).^4)/4)+a14);
else
    s=r.*(a1.*log(temp)+(a2.*temp)+(a3*((temp).^2)/2)+(a4*((temp).^3)/3)+(a5*((temp).^4)/4)+a7);
end

EXPLANATION:

  • Using functions i have made a template to calculate the entropy.

ENTHALPHY:

  • It is the sum of the internal energy. and pressure times volume.
  • We cannot measure the enthalpy of a system, but we can look at changes in enthalpy.

Formula,

H=(a1 + a2T/2 + a3T^2/3 + a4T^3/4 + a5T^4/5)*RT

FUNCTION PROGRAM:

function h=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,r,global_medium_temp)
if temp<=global_medium_temp
    h=r*temp.*(a8+((a9*temp)/2)+((a10*(temp).^2)/3)+((a11*(temp).^3)/4)+((a12*(temp).^4)/5)+((a13./temp)));
else
    h=r*temp.*(a1+((a2*temp)/2)+((a3*(temp).^2)/3)+((a4*(temp).^3)/4)+((a5*(temp).^4)/5)+((a6./temp)));
end

EXPLANATION:

  • Using functions i have made a template to calculate the enthalphy.

MOLECULAR WEIGHT:

  • Molecular weight is a measure of the sum of the atomic weight values of the atoms in a molecule.

FUNCTION PROGRAM:

function molecularweight=Molecular_weight(species_sp)
atomic_name=['H','C','O','N','A'];
fprintf('Molecualr Weight of');
fprintf(':');
atomic_weight=[1.088 12.011 15.999 14.007 39.948];
molecularweight=0;

for i=1:length(species_sp)
    for j=1:length(atomic_name)
        if strcmpi(species_sp(i),atomic_name(j))
            molecularweight=molecularweight+atomic_weight(j);
            position=j;
        end
    end
    n=str2num(species_sp(i));
    
    if n>1
    
    molecularweight=molecularweight+atomic_weight(position)*(n-1);
    end
end
fprintf('molecular weight %s :',species_sp);
fprintf('%d',molecularweight);
disp('');
end

    

EXPLANATION:

  • Using functions i have made a template to calculate the molecular weigth.

MAIN PROGRAM:

close all
clear all
clc

f1=fopen('THERMO.dat','r')
gt=fgetl(f1);

global_temp=fgetl(f1);

t=strsplit(global_temp);

global_low_temp=str2num(t{2});
global_medium_temp=str2num(t{3});
global_high_temp=str2num(t{4});

temp=linspace(global_low_temp,global_high_temp,1000);

r=8.314;

for i=1:3
    gt=fgetl(f1);
end

for i=1:53
    gt=fgetl(f1);
    A=strsplit(gt,'');
    species_sp=(A{1})
    
    line_1=fgetl(f1);
    a=strfind(line_1,'E');
    
    a1=line_1(1:a(1)+3);
    a1=str2num(a1);     %1
 
    a2=line_1(a(1)+4:a(2)+3);
    a2=str2num(a2);     %2
    
    a3=line_1(a(2)+4:a(3)+3);
    a3=str2num(a3);     %3
    
    a4=line_1(a(3)+4:a(4)+3);
    a4=str2num(a4);     %4
    
    a5=line_1(a(4)+4:a(5)+3);
    a5=str2num(a5);     %5
    
    line_2=fgetl(f1);
    b=strfind(line_1,'E');
    
    a6=line_2(1:b(1)+3);
    a6=str2num(a6);     %6
    
    a7=line_2(a(1)+4:b(2)+3);
    a7=str2num(a7);     %7
    
    a8=line_2(b(2)+4:b(3)+3);
    a8=str2num(a8);     %8
    
    a9=line_2(b(3)+4:b(4)+3);
    a9=str2num(a9);     %9
    
    a10=line_2(b(4)+4:b(5)+3);
    a10=str2num(a10);   %10

    line_3=fgetl(f1);
    c=strfind(line_1,'E');
    
    a11=line_3(1:c(1)+3);
    a11=str2num(a11);   %11
    
    a12=line_3(c(1)+4:c(2)+3);
    a12=str2num(a12);   %12
    
    a13=line_3(c(2)+4:c(3)+3);
    a13=str2num(a13);   %13
    
    a14=line_3(c(3)+4:c(4)+3);
    a14=str2num(a14);   %14
    
    cp=specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,r,global_medium_temp);
    
    h=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,r,global_medium_temp);
    
    s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,r,global_medium_temp);
    
    molecularweight=Molecular_weight(species_sp);
    
    Molecular_list = fopen('Molecular weight.txt','a+');
    fprintf(Molecular_list,'Molecular weight of %s is %d n',species_sp,molecularweight);
    fclose(Molecular_list);
    
    cur_dir=pwd;
    mkdir(species_sp);
    cd(species_sp);
    
    figure(1)
    
    plot(temp,cp,'linewidth',2,'color','r');
    xlabel('Temperature [k]');
    ylabel('Specific Heat [kj]');
    title(sprintf('Varying Specific Heat with Temperature Range of %s',species_sp));
    grid on
    saveas(figure(1),'Specific Heat.jpg');
    
    figure(2)
    
    plot(temp,h,'linewidth',2,'color','g');
    xlabel('Temperature [k]');
    ylabel('Enthalpy [kj/(mol)]');
    title(sprintf('Varying Enthalphy with Temperature Range of %s',species_sp));
    grid on
    saveas(figure(2),'Enthalphy.jpg');
    
    figure(3)
    
    plot(temp,s,'linewidth',2,'color','b');
    xlabel('Temperature [k]');
    ylabel('Enthalpy [kj/(mol-k)]');
    title(sprintf('Varying Entropy with Temperature Range of %s',species_sp));
    grid on
    saveas(figure(3),'Entropy.jpg');
    
    cd(cur_dir);
    
    M=Molecular_weight(species_sp)
    f2=fopen('molecular mass','w');
    fprintf('%s n %s n %f n','species','Molecular mass',M)
    fclose(f2)
end

EXPLANATION:

1.Using fopen and fgetl command is used to read the thermo.dat file

f1=fopen('THERMO.dat','r')
gt=fgetl(f1);

global_temp=fgetl(f1);

2.Assinging the values and formula to calculate the sepcific heat,entropy,enthalphy

t=strsplit(global_temp);

global_low_temp=str2num(t{2});
global_medium_temp=str2num(t{3});
global_high_temp=str2num(t{4});

temp=linspace(global_low_temp,global_high_temp,1000);

r=8.314;

for i=1:3
gt=fgetl(f1);
end

for i=1:53
gt=fgetl(f1);
A=strsplit(gt,'');
species_sp=(A{1})

line_1=fgetl(f1);
a=strfind(line_1,'E');

a1=line_1(1:a(1)+3);
a1=str2num(a1); %1

a2=line_1(a(1)+4:a(2)+3);
a2=str2num(a2); %2

a3=line_1(a(2)+4:a(3)+3);
a3=str2num(a3); %3

a4=line_1(a(3)+4:a(4)+3);
a4=str2num(a4); %4

a5=line_1(a(4)+4:a(5)+3);
a5=str2num(a5); %5

line_2=fgetl(f1);
b=strfind(line_1,'E');

a6=line_2(1:b(1)+3);
a6=str2num(a6); %6

a7=line_2(a(1)+4:b(2)+3);
a7=str2num(a7); %7

a8=line_2(b(2)+4:b(3)+3);
a8=str2num(a8); %8

a9=line_2(b(3)+4:b(4)+3);
a9=str2num(a9); %9

a10=line_2(b(4)+4:b(5)+3);
a10=str2num(a10); %10

line_3=fgetl(f1);
c=strfind(line_1,'E');

a11=line_3(1:c(1)+3);
a11=str2num(a11); %11

a12=line_3(c(1)+4:c(2)+3);
a12=str2num(a12); %12

a13=line_3(c(2)+4:c(3)+3);
a13=str2num(a13); %13

a14=line_3(c(3)+4:c(4)+3);
a14=str2num(a14); %14

3.Functions program has been involved in the program

cp=specificheat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,temp,r,global_medium_temp);

h=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,temp,r,global_medium_temp);

s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,temp,r,global_medium_temp);

molecularweight=Molecular_weight(species_sp);

Molecular_list = fopen('Molecular weight.txt','a+');
fprintf(Molecular_list,'Molecular weight of %s is %d n',species_sp,molecularweight);
fclose(Molecular_list);

4.Plot the graph for entropy enthalphy and specific heat

cur_dir=pwd;
mkdir(species_sp);
cd(species_sp);

figure(1)

plot(temp,cp,'linewidth',2,'color','r');
xlabel('Temperature [k]');
ylabel('Specific Heat [kj]');
title(sprintf('Varying Specific Heat with Temperature Range of %s',species_sp));
grid on
saveas(figure(1),'Specific Heat.jpg');

figure(2)

plot(temp,h,'linewidth',2,'color','g');
xlabel('Temperature [k]');
ylabel('Enthalpy [kj/(mol)]');
title(sprintf('Varying Enthalphy with Temperature Range of %s',species_sp));
grid on
saveas(figure(2),'Enthalphy.jpg');

figure(3)

plot(temp,s,'linewidth',2,'color','b');
xlabel('Temperature [k]');
ylabel('Enthalpy [kj/(mol-k)]');
title(sprintf('Varying Entropy with Temperature Range of %s',species_sp));
grid on
saveas(figure(3),'Entropy.jpg');

cd(cur_dir);

M=Molecular_weight(species_sp)
f2=fopen('molecular mass','w');
fprintf('%s n %s n %f n','species','Molecular mass',M)
fclose(f2)
end

ERRORS:

Error: Instead of cp I have typed Cp (cp is used in all function and in main program i have typed Cp)

Action: Cp has been changed to cp.

OUTPUT:

OXEYGEN (O2) :

NITROGEN (N2):

CARBONDIOXIDE (CO2):

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.