%Cp,H,S function
function [Cp,H,S] = thermofunc(local_low_temp,local_mid_temp,local_high_temp,Lt,Ht)
for i=1:local_high_temp-local_low_temp+1
R = 8.34;
T=i+local_low_temp-1;
if T<= local_mid_temp
Cp(i) = R*(Lt(1)+(Lt(2)*T)+(Lt(3)*T^2)+(Lt(4)*T^3)+(Lt(5)*T^4));
H(i) = R*T*(Lt(1)+((Lt(2)*T)/2)+((Lt(3)*T^2)/3)+((Lt(4)*T^3)/4)+((Lt(5)*T^4)/5)+(Lt(6)/T));
S(i) = R*(Lt(1)*log(T)+(Lt(2)*T)+((Lt(3)*T^2)/2)+((Lt(4)*T^3)/3)+((Lt(5)*T^4)/4)+(Lt(7)));
else
Cp(i) = R*(Ht(1)+(Ht(2)*T)+(Ht(3)*T^2)+(Ht(4)*T^3)+(Ht(5)*T^4));
H(i) =R*T*(Ht(1)+((Ht(2)*T)/2)+((Ht(3)*T^2)/3)+((Ht(4)*T^3)/4)+((Ht(5)*T^4)/5)+(Ht(6)/T));
S(i) = R*((Ht(1)*log(T))+(Ht(2)*T)+((Ht(3)*T^2)/2)+((Ht(4)*T^3)/3)+((Ht(5)*T^4)/4)+(Ht(7)));
end
end
end
%molecular weight function
function Mo=molwt(Species_Name)
atomicwt = [1 12 14 16 32 40];
Gas=['H' 'C' 'N' 'O' 'S' 'A'];
number=[1 2 3 4];
Molecular_weight=0;
SPECIES=char(Species_Name);
for i=1:length(SPECIES)
for j=1:length(Gas)
if SPECIES(i)==Gas(j)
Molecular_weight(i)=atomicwt(j);
end
for j=1:length(number)
if str2double(SPECIES(i))==number(j)
Molecular_weight(i)=Molecular_weight(i-1)*(number(j)-1);
end
end
end
end
Mo=sum(Molecular_weight);
Display = sprintf('Molecular weight of %s is %d',SPECIES,Mo);
disp(Display)
end
%Main code
clear all
close all
clc
%reading file
f1 = fopen('THERMO.dat','r');
%reading first line of file
first_line = fgetl(f1);
%reading global temperature range
global_temp_range = fgetl(f1);
%spliting the string
A = strsplit(global_temp_range,' ');
%allocating global temperature ranges
global_low_temp = str2double(A{2});
global_mid_temp = str2double(A{3});
global_high_temp = str2double(A{4});
%reading unnecessary lines
for i=1:3
fgetl(f1);
end
%reading the local temp range for each element
for k=1:53
local_temp_line = fgetl(f1);
local_temp_split = strsplit(local_temp_line,' ');
Species_Name = (local_temp_split(1));
b = strfind(local_temp_line,'.');
local_low_temp = str2double(local_temp_line(b(1)-4:b(1)+4));
local_high_temp = str2double(local_temp_line(b(2)-4:b(2)+4));
local_mid_temp = str2double(local_temp_line(b(3)-4:b(3)+4));
%extracting 14 coefficients of the Species
ct=1;
for j=1:3
line=fgetl(f1);
B = strfind(line,'E');
for i=1:length(B)
if ct<=7
Ht(ct)=str2double(line(B(i)-11:B(i)+3));
ct=ct+1;
else
Lt(ct-7)=str2double(line(B(i)-11:B(i)+3));
ct=ct+1;
end
end
end
%initialising values of Cp,S,H to zero
Cp=0;
H=0;
S=0;
%Using the function to calculate specific heat,entropy and enthalpy
[Cp,H,S] = thermofunc(local_low_temp,local_mid_temp,local_high_temp,Lt,Ht);
%Using the function to calculate molecular weight
Molecular_weight = molwt(Species_Name);
%Plotting the outputs as required
%Specific Heat data
SPECIES = char(Species_Name);
T = local_low_temp:local_high_temp;
CurrentFolder = pwd;
mkdir(SPECIES);
cd(SPECIES)
figure(1);
plot(T,Cp,'linewidth',3);
legend(Species_Name);
xlabel('TEMPERATURE');
ylabel('SPECIFIC HEAT');
title('Cp vs T');
%Enthalpy data
figure(2);
plot(T,H,'linewidth',3);
legend(Species_Name);
xlabel('TEMPERATURE');
ylabel('ENTHALPY');
title('H vs T');
%Entropy Data
figure(3);
plot(T,S,'linewidth',3);
legend(Species_Name);
xlabel('TEMPERATURE');
ylabel('ENTROPY');
title('S vs T');
%Saving the plots
saveas(figure(1),'Cp.jpg');
saveas(figure(2),'H.jpg');
saveas(figure(3),'S.jpg');
cd(CurrentFolder);
end