Challenge

Project 1 - Parsing NASA thermodynamic data

To calculates the enthalpy, entropy and specific heats for all the species from the NASA Thermodynamic data and plot the graph for Cp, Enthalpy and Entropy for the local temperature range specific for each species.

code for the function is as follows :-

function MM = molecular_mass(species)

species = char(species)

% species = upper(species_name)

elements = ['H', 'C', 'N', 'O', 'A'];

atomic_mass = [1.00794 12.0107 14.0067 15.9994 39.948];

MM = 0;

for i = 1:length(species)

    for j = 1:length(elements)

        if strcmp(species(i),elements(j))

            MM = MM+atomic_mass(j);

            u = j;

        end

    end

    n = str2num(species(i));

    if n>1

        MM = MM+atomic_mass(u)*(n-1);

    end

end

code for following project 1 :

clear all

close all

clc

f1 = fopen('THERMO.dat','r'); %opening the file

fgetl(f1); %reading the first line

L1 = fgetl(f1); %reading the second line

L2 = fgetl(f1); %reading the third line

L3 = fgetl(f1); %reading the forth line

L4 = fgetl(f1); %reading the fifth line

tline = L1;

B = strsplit(tline,' ');

global_low_temp = str2num(B{2});

global_mid_temp = str2num(B{3});

global_high_temp = str2num(B{4});

for i = 1:inf % for reading the remaining lines in the file

    L5 = fgetl(f1); % if the end of the file is not yet reached then assign the first line of each element to L5

    if 

        (findstr(L5,'END')) % check whether we reached the end of the file

        break

    end

% if the end of the file is not yet

% reached then continue with reading

% the rest of the file

L6 = fgetl(f1); % read the first set of coefficient

L7 = fgetl(f1); % read the second set of coefficient

L8 = fgetl(f1); % read the third set of coefficient

split_data = strsplit(L5,' ');

species = string(split_data(1));

tline1 = L5(49:end);

A = strsplit(tline1,' ');

local_low_temp = str2num(A{1});

local_high_temp = str2num(A{2});

local_mid_temp = str2num(A{3});

tline = L6;

tline2 = L7;

tline3 = L8;

a = findstr(tline,'E');

a1 = tline(1:a(1)+3);

a1 = str2num(a1);

a2 = tline(a(1)+4:a(2)+3);

a2 = str2num(a2);

a3 = tline(a(2)+4:a(3)+3);

a3 = str2num(a3);

a4 = tline(a(3)+4:a(4)+3);

a4 = str2num(a4);

a5 = tline(a(4)+4:a(5)+3);

a5 = str2num(a5);

a6 = tline2(1:a(1)+3);

a6 = str2num(a6);

a7 = tline2(a(1)+4:a(2)+3);

a7 = str2num(a7);

a8 = tline2(a(2)+4:a(3)+3);

a8 = str2num(a8);

a9 = tline2(a(3)+4:a(4)+3);

a9 = str2num(a9);

a10 = tline2(a(4)+4:a(5)+3);

a10 = str2num(a10);

a11 = tline3(1:a(1)+3);

a12 = tline3(a(1)+4:a(2)+3);

a13 = tline3(a(2)+4:a(3)+3);

a14 = tline3(a(3)+4:a(4)+3);

a11 = str2num(a11);

a12 = str2num(a12);

a13 = str2num(a13);

a14 = str2num(a14);

R = 8.314; % R = Universal Gas constant.

T_l = linspace(local_low_temp,local_mid_temp,50)

T_h = linspace(local_mid_temp,local_high_temp,50)

% HIGH-temperature coefficients

Cp_h = (a1 + a2*(T_h) + a3*(T_h.^2) + a4*(T_h.^3) + a5*(T_h.^4)).*R

H_h = (a1 + (a2.T_h)./2 + (a3.*T_h.^2)./3 + (a4.*T_h.^3)./4 + (a5.*T_h.^4)./5 + (a6./T_h)).(R*T_h)

S_h = (a1.log(T_h) + a2.*T_h + (a3.*T_h.^2)./2 + (a4.*T_h.^3)./3 + (a5.*T_h.^4)./4 + a7).(R)

% LOW-temperature coefficients

Cp_l = (a8 + a9*(T_l) + a10*(T_l.^2) + a11*(T_l.^3) + a12*(T_l.^4)).*R

H_l = (a8 + (a9.T_l)./2 + (a10.*T_l.^2)./3 + (a11.*T_l.^3)./4 + (a12.*T_l.^4)./5 + (a13./T_l)).(R*T_l)

S_l = (a8.log(T_l) + a9.*T_l + (a10.*T_l.^2)./2 + (a11.*T_l.^3)./3 + (a12.*T_l.^4)./4 + a14).(R)

figure(1)

title("T Vs C")

plot(T_l,Cp_l,'linewidth',2,'color','r')

hold on

plot(T_h,Cp_h,'linewidth',2,'color','r')

xlabel('Specific heat at constant pressure (Cp)')

ylabel('Temperature (T)')

grid on

hold off

figure(2)

title("T Vs H ")

plot(T_l,H_l,'linewidth',2,'color','g')

hold on

plot(T_h,H_h,'linewidth',2,'color','g')

xlabel('Enthalpy (H)')

ylabel('Temperature (T)')

grid on

hold off

figure(3)

title("T Vs S ")

plot(T_l,S_l,'linewidth',2,'color','b')

hold on

plot(T_h,S_h,'linewidth',2,'color','b')

xlabel('Entropy (S)')

ylabel('Temperature (T)')

grid on

hold off

mass = molecular_mass(species)

mkdir('PT')

cd('PT')

mkdir(species)

cd(species)

saveas(1,'cp.jpg')

saveas(2,'h.jpg')

saveas(3,'s.jpg')

cd ..

cd ..

end

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.