Project

NASA PROJECT

Aim:

1) To 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.

2) To calculate the molecular weight of each species and display it in the command window.

3) To plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.

Report:

1) Firstly, the NASA Thermodynamic Data \'Thermo.dat\' file was read by using fopen command.

2) Then to navigate through the data fgetl command was used. The header line \'Thermo\' was skipped by using fgetl command.

3) The temperature line \'300 1000 5000\' was stored as a single string in a variable. To split the string into 3 strings strsplit command was used. To convert the string values into numerical values str2num command was used. The three temperature values min, mid and max were then stored in seperate variables.

4) After that the three comment lines were skipped by using fgetl command.

5) The 14 coefficients for each species were calculated by using for loop. Each species contains 3 lines in which 14 coefficients are present. To distinguish the coefficients the position of exponent were determined for each coefficient by using strfind command.

6) The seperate folders were created for each species to save the plots for each species in seperate folders.

7) The value of Universal gas constant R = 8.314J/mol-K was declared. Based upon the 14 co-efficients and the value of R the values of Specific heat, Enthalpy and Entropy were calculated for each species by using the following formulaes

Cp=R(C1+C2⋅T+C3⋅T2+C4⋅T3+C5⋅T4)Cp=R(C1+C2⋅T+C3⋅T2+C4⋅T3+C5⋅T4)

H=RT(C1+C2⋅T2+C3⋅T23+C4⋅T34+C5⋅T45+C6T)H=RT(C1+C2⋅T2+C3⋅T23+C4⋅T34+C5⋅T45+C6T)

S=R(C1⋅ln(T)+C2⋅T+C3⋅T22+C4⋅T33+C5⋅T44+C7)S=R(C1⋅ln(T)+C2⋅T+C3⋅T22+C4⋅T33+C5⋅T44+C7)

8) The graphs were plotted of Temperature vs Entropy, Temperature vs Enthalpy and Temperature vs Specific heat and saved in the seperate created folders for each species.

9) Finally, the values of molecular weights were calculated for each species. For this pupose a different function was created and then called in the parsing code to display the molecular weight in command window.

CODE:

PARASING CODE
clc
clear all
close all

%Finding and opening the file
file = fopen(\'Thermo.dat\',\'r\')

%Heading
line1 = fgetl(file);

%Global Temperature Values
line2 = fgetl(file)
A = strsplit(line2,\' \');
Global_min_Temp = str2num(A{2});
Global_mid_Temp = str2num(A{3});
Global_max_Temp = str2num(A{4});

%Skipping Comments
line3 = fgetl(file);
line4 = fgetl(file);
line5 = fgetl(file);

for i = 1:53
    species = fgetl(file);
    species_name = species(1:6)
    
    Line_1 = fgetl(file);
    L1 = strfind(Line_1,\'E\');
    C1 = str2num(Line_1(1:(L1(1)+3)));
    C2 = str2num(Line_1((L1(1)+4):(L1(2)+3)));
    C3 = str2num(Line_1((L1(2)+4):(L1(3)+3)));
    C4 = str2num(Line_1((L1(3)+4):(L1(4)+3)));
    C5 = str2num(Line_1((L1(4)+4):(L1(5)+3)));
    
 Line_2 = fgetl(file);
    L2 = strfind(Line_2,\'E\');
    C6 = str2num(Line_2(1:(L2(1)+3)));
    C7 = str2num(Line_2((L2(1)+4):(L2(2)+3)));
    C8 = str2num(Line_2((L2(2)+4):(L2(3)+3)));
    C9 = str2num(Line_2((L2(3)+4):(L2(4)+3)));
    C10 = str2num(Line_2((L2(4)+4):(L2(5)+3)));


    Line_3 = fgetl(file);
    L3 = strfind(Line_3,\'E\');
    C11 = str2num(Line_3(1:(L3(1)+3)));
    C12 = str2num(Line_3((L3(1)+4):(L3(2)+3)));
    C13 = str2num(Line_3((L3(2)+4):(L3(3)+3)));
    C14 = str2num(Line_3((L3(3)+4):(L3(4)+3)));   



%creating folder for each species
mkdir(\'F:matlab practice skilllyncnewfolderSpecies\',species_name)

%Temperature Range assumed
Temp = linspace(300,5000,100);

%Universal gas constant
R = 8.314;

%Calculation
for j = 1:length(Temp)
    if Temp(j)<3000
Cp = (C1+C2.*Temp+C3.*Temp.^2+C4.*Temp.^3+C5.*Temp.^4).*R;
H = (C1+(C2.*Temp)./2+(C3.*Temp.^2)/3+(C4.*Temp.^3)/4+(C5.*Temp.^4/5)+C6./Temp).*Temp.*R;
S = (C1*log(Temp)+C2.*Temp+(C3.*Temp.^2)/2+(C4.*Temp.^3)/3+(C5.*Temp.^4)/4+C7).*R;
    else
Cp = (C8+C9.*Temp+C10.*Temp.^2+C11.*Temp.^3+C12.*Temp.^4).*R;
H = (C8+(C9.*Temp)/2+(C10.*Temp.^2)/3+(C11.*Temp.^3)/4+(C12.*Temp.^4/5)+C13./Temp).*Temp.*R;
S = (C8.*log(Temp)+C9.*Temp+(C10.*Temp.^2)/2+(C11.*Temp.^3)/3+(C12.*Temp.^4)/4+C14).*R;
    end
end
    
%plotting

%Temperature vs Entropy
figure(1)
plot(Temp,S,\'linewidth\',4,\'color\',\'b\')
title(species_name)
xlabel(\'Temperature\')
ylabel(\'Entropy\')

%Temperature vs Enthalpy
figure(2)
plot(Temp,H,\'linewidth\',4,\'color\',\'k\')
title(species_name)
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')

%Temperature vs Specific heat
figure(3)
plot(Temp,Cp,\'linewidth\',4,\'color\',\'y\')
title(species_name)
xlabel(\'Temperature\')
ylabel(\'Specific heat\')

directory = ([\'F:matlab practice skilllyncnewfolderSpecies\',species_name]);   %changing the filepath to save the plots
cd(directory)

%saving the plots

saveas(1,\'Entropy.jpg\');
saveas(2,\'Enthalpy.jpg\');
saveas(3,\'Specific heat.jpg\');

cd(\'F:matlab practice skilllync\')       %switching the directory back to read thermodat file for molecular mass calculation

MM = molecular_mass(species_name)

end

fclose(file)

MOLECULAR WIEGHT FUNCTION

function MM = molecular_mass(species_name)
  
species = upper(species_name); 

Constituents = [\'H\', \'C\', \'N\', \'O\', \'A\'];

Atomic_weight = [1.00794 12.0107 14.0067 15.9994 39.948]; 

MM = 0; 

for i=1:length(species)
    for j=1:length(Constituents)
        if strcmp(species(i),Constituents(j))
           MM = MM + Atomic_weight(j); 
           u = j;
        end
    end
    n = str2num(species(i));
    if n>1
        MM = MM + Atomic_weight(u)*(n-1);
    end
end
end

OUTPUT:

1) LOCATION OF SEPERATE FOLDERS CREATED FOR EACH SPECIES

\"\"

2) MOLECULAR WEIGHT DISPLAYED IN COMMAND WINDOW

\"\"

\"\"

\"\"

\"\"

\"\"

3) PLOTS

I) FOR O2

\"\"

\"\"

\"\"

II) FOR N2

\"\"

\"\"

\"\"

III) FOR CO2

\"\"

\"\"

\"\"

4) ERRORS

I)

\"\"

The value of universal gas constant was not defined. By defining variable R = 8.314J/mol-K, the problem was solved.

II) Another error was faced because of ending the for loop at irrelevant position. This error was solved by correcting the position of end statement of for loop.

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.