Project

By using NASA thermodynamic data we have to plot various graph

AIM : By using NASA thermodynamic data we have to plot various graph

a1, a2, a3, a4, a5, a6, and a7 are the numerical coefficients provided in NASA thermodynamic files. The first 7 numbers starting on the second line of each species entry are the seven coefficients for the high-temperature range . .The next seven numbers are the coefficients for the low-temperature range

% NASA Thermodynamic data file Parsing
clear all 
close all
clc

% Opening Data file.
f1 = fopen('THERMO.dat','r');
Header= fgetl(f1);

%Global_Temperature
Global_temp = fgetl(f1);
A = strsplit(Global_temp,' ');
global_low_temp =str2num(A{2});         
global_mid_temp =str2num(A{3});        
global_high_temp =str2num(A{4});   

% Skipping lines whis has " 
for i = 1:3
    fgetl(f1);
end

for i = 1:53
    line= fgetl(f1);                                    
    q=strsplit(line,' ');                               
    element=q(1);                                       
    
    T = strfind(line,'G'); 
    local_low_temp = line(T+3:55); 
    local_high_temp = line(T+13:65);
    local_mid_temp = line(T+23:75); 
    llt = str2double(local_low_temp);         %local_low_temp
    lht = str2double(local_high_temp);        %local_high_temp 
    lmt = str2double(local_mid_temp);         %local_mid_temp

% coefficient of 1st line
    coff_l1= fgetl(f1);
    a1 =coff_l1(1*15-14 : 1*15); 
    a1 = str2double(a1)                     %1st coefficient 
    a2 = coff_l1(2*15-14 : 2*15);
    a2 = str2double(a2)                     %2nd coefficient 
    a3 = coff_l1(3*15-14 : 3*15);
    a3 = str2double(a3)                     %3rd coefficient 
    a4 = coff_l1(4*15-14 : 4*15);
    a4 = str2double(a4)                     %4th coefficient 
    a5 = coff_l1(5*15-14 : 5*15);
    a5 = str2double(a5)                     %5th coefficient
    
 %% coefficient of 2st line  
    coff_l2= fgetl(f1);
    a6 =coff_l2(1*15-14 : 1*15); 
    a6 = str2double(a6)                    %1st coefficient 
    a7 = coff_l2(2*15-14 : 2*15);
    a7 = str2double(a7)                    %2nd coefficient 
    a8 = coff_l2(3*15-14 : 3*15);
    a8 = str2double(a8)                    %3rd coefficient 
    a9 = coff_l2(4*15-14 : 4*15);
    a9 = str2double(a9)                    %4th coefficient 
    a10 = coff_l2(5*15-14 : 5*15);
    a10 = str2double(a10)                  %5th coefficient
    
    %% coefficient of 3st line 
    coff_l3= fgetl(f1);
    a11 =coff_l3(1*15-14 : 1*15); 
    a11 = str2double(a11);                 %1st coefficient 
    a12 = coff_l3(2*15-14 : 2*15);
    a12 = str2double(a12);                 %2nd coefficient 
    a13 = coff_l3(3*15-14 : 3*15);
    a13 = str2double(a13);                 %3rd coefficient 
    a14 = coff_l3(4*15-14 : 4*15);
    a14 = str2double(a14);                 %4rd coefficient
    
T=linspace(llt,lht,250);   %250 different Temperature from llt to lht
R = 8.314;    %gas constant 

% Specific Heat
if T>=lmt
    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

% Entropy
if T>=lmt
    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

% Enthapy
if T>=lmt
    H=(a1.*T+a2.*(T.^2)./2+a3.*(T.^3)./3+a4.*(T.^4)./4+a5.*(T.^5)./5+a6)*R;
else
    H=(a8.*T+a9.*(T.^2)./2+a10.*(T.^3)./3+a11.*(T.^4)./4+a12.*(T.^5)./5+a13)*R;
end

%Saving file in folder
chem=char(element); 
fd = sprintf('%s',chem);
cur_dir=pwd;
mkdir(chem);
cd(chem);
  
% Plotting
%Specific heat(Cp) vs Temperature(T)
figure(1);
plot(T,Cp,'linewidth',3,'color','black');
xlabel('Temperature in K');
ylabel('Specific heat in kJ');
title('Specific heat vs Temperature');
  
%Enthalpy(H) vs Temperature (T)  
figure(2);
plot(T,H,'linewidth',3,'color','r');
xlabel('Temperature in K');
ylabel('Enthalpy in kJ/(mol)');
title('Enthalpy vs Temperature');
  
%Entropy(S) vs Temperature(T)
figure(3);
plot(T,S,'linewidth',3,'color','b');
xlabel('Temperature in K');
ylabel('Entropy in kJ/(mol K)');
title('Entropy vs Temperature');

%Saving the graph
saveas(figure(1), 'cp.png');
saveas(figure(2), 'Enthalpy.png');
saveas(figure(3), 'Entropy.png');
cd(cur_dir);

% Molecular 
MW(i)= molecular_weight(element);

end
fclose(f1);

In this project we have given nasa data for the project, thus to use it we have wright a small code to open data file and read it “f1 = fopen('THERMO.dat','r'); where THERMO.DAT is the name of nasa file & .dat is the format of the file.

To go to next line of the nasa data we use “ fgetl(f1) ”

now we have to access wanted global temperature by using nasa data file , which is on the second line of the data. By writing " fget(f1) " we go to the next line of the data file and to store we write

“Global_temp = fgetl(f1); du to which the temperature is store in global temp as

Global_temp = ' 300.000 1000.000 5000.000 '

After storing we pass the command as “strsplit “ due to this the pack of 3 temperature are form and they are at position 1,2&3. Just call by position we get temperature.

eg : global_low_temp =str2num(A{2});

global_low_temp =1000.000

For skipping the data reading line we can write “fgetl(f1)” 3 time or we can pass the for loop as i=1:3

Now we have to calculate the value of cp, enthalpy, entropy. And pot the graph for the various element such as O,O2,H etc.

the main part of the coding we have to extract co_effi form data, so to extract that I have shown logic of it. For 1 element we have 14 coefficient thus from above logic we have to pass 1 to 14 number in the form of “num”. thus for every coefficient we have to change num value. Also first 7 are lower coefficient and next 7 are higher temperature coefficient thus to make or separate higher we use a “if else loop”.

After separating we use this formula for calculating of cp, entropy, enthalpy . and then we use plot command to plot graph with respect to temperature. since their is only two temperature for plotting(lower, medium) & plotting(medium, higher ) thus we use linspace command and take 250 value between two temperature

The formulae for calculating the NASA Thermodynamic are given

To save plot we pass the command “ saveas ” . saveas(figure number, plot name.png)

function :

function MW = molecular_weight(element)

atom = ['H','C','N','O','AR'];
atomic_weight = [1 12 14 16 40];
MW = 0;
for i = 1:length(element);
    for j = 1:length(atom);
        if strcmp(element(i),atom(j))
            
            MW = MW + atomic_weight(j);
            d = j;
        end
    end
    n = str2num(element{i});
   
    if n>1
        MW = MW + atomic_weight(d)*(n-1);
    end
end
end

ERROR:

when i was assigning temperature value I have assign to “small t “ and every where I have written I have assign T

2). R value not assign

output

2).O2

  • CP of O2
  • Enthalpy of O2
  • Entropy of O2

3.) N2

  • CP of N2
  • Enthalpy of N2
  • Entropy of N2

4). CO2

  • CP of CO2

  • Enthalpy of CO2

  • Entropy of CO2

Referance : https://in.mathworks.com/support.html?s_tid=gn_supp

conclusion: we have plot various graph with respect to temperature by reading nasa data file.

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.