Challenge

Project 1 - Parsing NASA thermodynamic data

function to find specific heat

function Cp=Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,temp2)
%calculating specific heat 
%calculating specific heat for higher and lower temperature respectively
if (T<=temp2)
    Cp=R*(a8+(a9*T)+(a10*(T).^2)+(a11*(T).^3)+(a12*(T).^4));
else
    Cp=R*(a1+(a2*T)+(a3*(T).^2)+(a4*(T).^3)+(a5*(T).^4));
end
end

function to find entropy

function S=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,temp2)
%calculating entropy
%calculating entropy for higher and lower temperature respectively
if(T<=temp2)
    S=R*(a8.*log(T)+(a9*T)+((a10*(T).^2)/2)+((a11*(T).^3)/3)+((a12*(T).^4)/4)+a14);

else
    S=R*(a1.*log(T)+(a2*T)+((a3*(T).^2)/2)+((a4*(T).^3)/3)+((a5*(T).^4)/4)+a7);
end
end

function to find enthalphy

function H=Enthalphy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,temp2)
%calculating enthalphy
%calculating enthalphy for higher and lower temperature respectively
if (T<=temp2)
    H=R*T.*(a8+((a9*T)/2)+((a10*(T).^2)/3)+((a11*(T).^3)/4)+((a12*(T).^4)/5)+((a13./T)));
else
    H=R*T.*(a1+((a2*T)/2)+((a3*(T).^2)/3)+((a4*(T).^3)/4)+((a5*(T).^4)/5)+((a6./T)));
end
end

code

clear all
close all
%input
R=8.314;
f1=fopen('THERMO.dat','r')
get=fgetl(f1);
temp=fgetl(f1);
s=strsplit(temp);
temp1=str2num(s{2});
temp2=str2num(s{3});
temp3=str2num(s{4});

T=linspace(temp1,temp3,1000);
for i=1:3
get=fgetl(f1);
end

%Reading the species
for j=1:53
tline=fgetl(f1);
A=strsplit(tline,' ');
species=(A{1});

%converting
lowtemp=str2num(A{end-3});
midtemp=str2num(A{end-2});
hightemp=str2num(A{end-1});

tline1=fgetl(f1);
%find the string E
a=strfind(tline1,'E'); 
%finding the coefficients

a1=tline1(1:a(1)+3);
a1=str2num(a1);
a2=tline1(a(1)+4:a(2)+3);
a2=str2num(a2);
a3=tline1(a(2)+4:a(3)+3);
a3=str2num(a3);
a4=tline1(a(3)+4:a(4)+3);
a4=str2num(a4);
a5=tline1(a(4)+4:a(5)+3);
a5=str2num(a5);


tline2=fgetl(f1);
%find the string E
b=strfind(tline2,'E'); 
a6=tline2(1:b(1)+3);
a6=str2num(a6);
a7=tline2(b(1)+4:b(2)+3);
a7=str2num(a7);

%lower coefficients
a8=tline2(b(2)+4:b(3)+3);
a8=str2num(a8);
a9=tline2(b(3)+4:b(4)+3);
a9=str2num(a9);
a10=tline2(b(4)+4:b(5)+3);
a10=str2num(a10);



tline3=fgetl(f1);
%find the string E
c=strfind(tline3,'E'); 
a11=tline3(1:c(1)+3);
a11=str2num(a11);
a12=tline3(c(1)+4:c(2)+3);
a12=str2num(a12);
a13=tline3(c(2)+4:c(3)+3);
a13=str2num(a13);
a14=tline3(c(3)+4:c(4)+3);
a14=str2num(a14);
%calculate Cp
Cp=Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,temp2);
%calculate S
S=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,temp2);
%calculate Enthalphy
H=Enthalphy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,temp2);


%plot 1 Cp vs T
figure(1)
plot(T,Cp,'linewidth',2,'color','b');
xlabel('Temperature(k)');
ylabel('Specific heat (KJ)');
title(sprintf('specific heat vs temperature range of %s',species));
grid on
saveas(figure(1),'Specific Heat.jpg');


%plot 2 S vs T
figure(2)
plot(T,S,'linewidth',2,'color','r');
xlabel('Temperature(k)');
ylabel('Entropy (KJ/mol-k)');
title(sprintf('Entropy vs temperature range of %s',species));
grid on
saveas(figure(2),'Entropy.jpg');


%plot 3 H vs T
figure(1)
plot(T,H,'linewidth',2,'color','g');
xlabel('Temperature(k)');
ylabel('Enthalphy(KJ/mol)');
title(sprintf('Enthalphy vs temperature range of %s',species));

clear all

end

STEPS:

* Firstly open a file THERMO.dat file and read through fopen.

*read first thermo using fgetl command and read temperature file and split the temp using strsplit

*then assign temperature range using linspace

*find first 7coefficients which for higher temperature and second 7coefficients

*specify Cp,entropy and H to find parameters

*plot Cp,Entropy and Enthalphy with temp for O.

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.