Challenge

Project 1 - Parsing NASA thermodynamic data

aim- to write a function to extracts the 14 coefficients and calculate the enthalpy, entropy and specific heat in matlab.

to find a molecular mass of each species and plot the graphs between entropy,enthalpy and specific heat w.r.t. temperature.

theory- file parsing is used to split the file and extracts the data into different parts in which data easily can stored or manipulated.

here is nasa thermodynamic data for gas species, here we have to extract the data and read that data than we have to calculation of that parsed data into number from string file.

program-

function code for entropy,enthalpy and specific heat

function[cp,H,S]= inputs(T,R,t_mid,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)

for i=1:length(T)

    if T(i)>t_mid
        cp= (a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4)*R;
        H= (a1+(a2.*T)/2+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+(a6./T))*R.*T;
        S= (a1.*log(T)+a2.*T+((a3.*T.^2)/2)+(a4.*T.^3)/3+(a5.*T.^4)/4+a7)*R;

    else

 cp= (a8+a9.*T+a10.*T.^2+a11.*T.^3+a12.*T.^4)*R;
        H= (a8+(a9.*T)/2+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+(a13./T))*R.*T;
        S= (a8.*log(T)+a9.*T+((a10.*T.^2)/2)+(a11.*T.^3)/3+(a12.*T.^4)/4+a14)*R;
    end
end
end

function code for calculation of molecular weight-

function[Mw]=molecular_weight(species_name)

elements=['H','C','O','N','A','S'];
atomic_weight= [ 1.0079 12.0107 15.999 14.0067 39.948 32.065 ];

Mw=0;

for i=1:length(species_name)

    for j=1:length(elements)

       if strcmp(species_name(i),elements(j))
           Mw=Mw+atomic_weight(j);
           a=j;
       end
    end

n=str2double(species_name(l));
if n>1
    Mw=Mw+atomic_weight(position)*(n-1);
end 
end

main program-

clear all
close all
clc

% getting the data
f1= fopen('THERMO.dat','r');
fgetl(f1);
fgetl(f1);
fgetl(f1);
fgetl(f1);
fgetl(f1);

% Extracting the coefficients and temperature data

for i= 1:53
    % Name of Gas species

    A = fgetl(f1);
    tline=strfind(A,'.');
    species_name = A(1:tline(1)-1);

    % Extracting coefficient of gas species
    X= fgetl(f1);
    x= strfind(X,'E');

    a1=X(1:x(1)+3);
    a1= str2num(a1);

    a2= X(x(1)+4:x(2)+3);
    a2= str2num(a2);

    a3= X(x(2)+4:x(4)+3);
    a3= str2num(a3);

    a4=X(x(3)+4:x(4)+3);
    a4= sr2num(a4);

    a5= X(x(4)+x(5)+3);
    a5= str2num(a5);

    Y= fgetl(f1);
    y=strfind(Y,'E');

    a6= Y(1:y(1)+3);
    a6=str2num(a6);

    a7= Y(y(1)+4:(2)+3);
    a7= str2num(a7);

    a8= Y((2)+4:(3)+3);
    a8= str2num(a8);

    a9= Y(y(3)+4:y(4)+3);
    a9= str2num(a9);

    a10= Y(y(4)+4:(5)+3);
    a10= str2num(a10);

    Z= fgetl(f1);
    z=strfind(Z,'E');

    a11= Z(1:z(1)+3);
    a11= str2num(a11);

    a12=Z(z(1)+4:z(2)+3);
    a12= str2num(a12);

    a13= Z(z(2)+4:z(3)+3);
    a13=str2num(a13);

    a14=Z(z(3)+4:z(4)+3);
    a14= str2num(a14);

  
end
T= linspace(t_low,t_high,1000);
R=8.314 % Local temperatures for each species
    t= strfind(A,'.');

    t_low = A(t(1)-3):t(1)+3;
    t_low = str2num(t_low);

    t_mid =A(t(3)-4:t(3)+3);
    t_mid= str2num(t_mid);

    t_high= A(t(2)-4:t(2)+3);
    t_high = str2num(t_high);

     % first 7 Coefficients are High Temp Coeff

    % second 7 coefficients are low Temp Coeff

% creating a folder to save plots
mkdir(['C:\Users\hmt78\OneDrive\Documents\MATLAB\NASA',species_name]);
cd(sprintf(species_name));

%plotting graph between specific heat and temp
figue(1)

plot(T,cp,'color','r','LineWidth',3)
xlabel('Temperature[k]')
ylabel('specific heat[J/K-kg')
title('specific heat')
saveas('Specific Heat.png')

%plotting graph between enthalpy and temperature
plot(T,H,'Color','b','LineWidth',3)
xlabel('Temperature')
ylabel('Enthalpy[J/K]')
title('Enthalpy')
saveas('Enthalpy.png')

%plotting the graph between entropy and Temperature
plot(T,S,'color','y','linewidth',3)
xlabel('Temperature')
ylabel('entropy')
title('Entropy')
saveas('entropy.png')

results-

here after programing i am not able to find results due to mass errors so ot enough time to discuss about errors bcz of timeline of challenge.

i didn't get any result .

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.