
Program(1)
clear my fun;
close all;
clc;
% function to calculate specific_heat function
%inputs
% gas constant
R=8.314;
% open file and reading THERMO.dat file
f1=fopen('THERMO.dat','r');
pavan=fgetl(f1);
% reading temperature from this file
T1=fgetl(f1);
%splitting the data
A=strsplit(T1,' ');
%converting sting cells into numbers
lowertemp = str2num(A{2});
mideltemp = str2num(A{3});
highertem = str2num(A{4});
%for skipping comments lines
for i=1:3
comments=fgetl(f1);
end
%reading the species
for j=1:53
species=fgetl(f1);
%spliting into cell array
B=strsplit(species);
% to read the name of the species
species_name =(B{1});
% for getting next line
list_1 = fgetl(f1);
%finding the string E
l1 = strfind(list_1,'E');
%finding first 7 higher co efficients are
a1 = str2num(list_1(1:(l1(1)+3)));
a2 = str2num(list_1((l1(1)+4):(l1(2)+3)));
a3 = str2num(list_1((l1(2)+4):(l1(3)+3)));
a4 = str2num(list_1((l1(3)+4):(l1(4)+3)));
a5 = str2num(list_1((l1(4)+4):(l1(5)+3)));
list_2 = fgetl(f1);
l2 = strfind(list_2,'E');
a6 = str2num(list_2(1:(l2(1)+3)));
a7 = str2num(list_2((l2(1)+4):(l2(2)+3)));
a8 = str2num(list_2((l2(2)+4):(l2(3)+3)));
a9 = str2num(list_2((l2(3)+4):(l2(4)+3)));
a10 = str2num(list_2((l2(4)+4):(l2(5)+3)));
list_3=fgetl(f1);
l3=strfind(list_3,'E');
a11=str2num(list_3(1:(l3(1)+3)));
a12=str2num(list_3((l3(1)+4):(l3(2)+3)));
a13=str2num(list_3((l3(2)+4):(l3(3)+3)));
a14=str2num(list_3((l3(3)+4):(l3(4)+3)));
% gas constant
R=8.314;
% creating an array temperature
T=linspace(lowertemp,highertem,100);
% for calculating specific heat
cp = specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,mideltemp);
% for calculate Entropy
s=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,mideltemp);
% for enthalpy calculation
h=Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,mideltemp);
% ploting CP,H AND S with temperature
%for ploting 1 CP VS T
figure(1)
plot(T,cp,'LineWidth',3,'Color','k');
xlabel('x-axis Temperature in (k)');
ylabel('y axis in specific heat in (KJ)');
title(species_name,'specific heat vs Temperature range ');
grid on;
saveas(figure(1),'specific heat.jpg')
% for ploting 2 entopy vs temperature
figure(2)
plot(T,s,'LineWidth',3,'Color','r');
xlabel('x axis Temperature in(k)');
ylabel('y axis Entropy in (KJ/Mol-k)');
title(species_name,'Entropy vs temperature range');
grid on
saveas(figure(2),'Entropy.jpg')
% for ploting 3 Enthalpy vs temperature
figure(3)
plot(T,h,'LineWidth',2,'Color','g');
xlabel('x axis Temperature in (k)');
ylabel('y axis Enthalpy in(KJ/Mol)');
title(species_name,'Enthalpy vs Temperature range')
grid on
saveas(figure(3),'Enthalpy.jpg');
% for changing directory to original mat lab path
cd('c:/Users/PAVANRAJPRAJJU/OneDrive/Documents/MATLAB/pavanraj')
% for molecular weight
mw = Molecular_weight(species_name);
fprintf('Molecular weight of %s is %d',species_name,mw);
disp(' ')
end
Program(2)
function [s] = Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,mideltemp)
% for calculating entropy for higher and lower temperature respectivly
if(T>=mideltemp)
s=R.*(a1.*log(T)+(a2.*T)+(a3.*((T).^2)./2)+(a4.*((T)./3)./3)+(a5.*((T)./4)./4)+a7);
else
s=R.*(a8.*log(T)+(a9.*T)+(a10.*((T)./2)./2)+(a11.*((T)./3)./3)+(a12.*((T)./4)./4)+a14);
end
end
Program(3)
function [h]=Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,mideltemp)
%for calculating enthalpy for higher and lower temperature respectively
if (T>=mideltemp)
h = R.*T.*(a1+(a2.*(T./2))+(a3.*(T./3))+(a4.*(T./4))+(a5.*(T./5))+(a6.*(T./6)));
else
h =R.*T.*(a8+(a9.*(T./2)))+(a10.*(T./3))+(a11.*(T./4))+((a12.*(T./5))+(a13.*(T./6)));
end
end
Program(4)
% calling function program for specific heat
function[cp]= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,R,T,mideltemp)
if T>= mideltemp
cp=R*(a1+(a2*T)+(a3*(T).^2)+(a4*(T).^3)+(a5*(T).^4));
else
cp=R*(a8+(a9*T)+(a10*(T).^2)+(a11*(T).^3)+(a12*(T).^4));
end
end
Program(5)
function [mw] = Molecular_weight(species)
% for defining automic name of the species
elements = {'H' 'C' 'N' 'O' 'Ar'};
% for defining atomic weight of the main species
atomic_weight=[1.008 12.011 14.007 15.999 39.948];
% for molecular weight starting range will be 0
mw=0;
% for loop is using the find the species
for i=1:length(species)
%for loop runs the atomicnames
for j=1:length(atomic_weight)
%function to compare 2 string
if strcmp(species(i),elements(j))
mw=mw+atomic_weight(j);
u=j;
end
end
%now we will find if ther is moew element in the species
n = str2num (species(i));
if n>1
mw=mw+atomic_weight(u)*(n-1);
end
end