FILE PARSING

 NASA THERMODYNAMIC DATA:

Thermodynamics is a branch of physics that deals with heat, work, and temperature, and their relation to energy, radiation, and physical properties of matter.  Thermodynamics applies to a wide variety of topics in science and engineering, especially physical chemistry, biochemistry, chemical engineering and mechanical engineering.

Some of thermodynamic data were given by NASA,that has been shown here…

In this senerio, we just extract the values,which is already written in that particular file and that values used to find some other datas like specific heat,entropy and enthalpy with the help of matlab.

Specific heat:

 The specific heat capacity of a substance is the heat capacity of a sample of the substance divided by the mass of the sample.

Entropy:

Entropy is a scientific concept as well as a measurable physical property that is most commonly associated with a state of disorder, randomness, or uncertainty.

Enthalpy:

Enthalpy, a property of a thermodynamic system, is the sum of the system's internal energy and the product of its pressure and volume. It is a state function used in many measurements in chemical, biological, and physical systems at a constant pressure.

Formulla to calculate specific heat(cp),entropy(h),enthalpy(s):

Write a function, to extarct the values form data file and to calculate specific heat(cp),entropy(h),enthalpy(s):

function [cp h s]=co_eff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T)
R=8.314;
for i=1:length(T)
    if T(i)<300;
        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+a5*T.^4+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+a12*T.^4+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

Already,we know how to write a function and all the stuff....

write a function to calculate molecular weight:

formulla:

molecular_wt=atomic_wt*mole

function molecular_weight = molecular_func(species_name)

elements = ['H','O','C','N','A'];
molecular_weight = 0;
atomic_weight = [1,12,14,16,40];

for i = 1:length(species_name)

   for j = 1:length(elements)
 
          if(strcmp(species_name(i),elements(j)))

             molecular_weight = molecular_weight + atomic_weight(j);
             position = j;
          end

   end

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

disp(molecular_weight)
end

In this function we find the element and compare with atmic wt throungh the strcmp.finally, we calculate molecular weight.

 

MAIN PROGRAM:

 

clear all
close all
clc
%FILE PARSING
%INPUTS WHICH TAKEN BY THE FILE..
f1=fopen('THERMO.dat','r');
%fgetl func is used to pick first line of the file...
s1=fgetl(f1);
s2=fgetl(f1);
%strcmp func split the numbers
S=strsplit(s2,' ');
%str2num func is used to convrt string to number
temp1=str2num(S{2});
temp2=str2num(S{3});
temp3=str2num(S{4});
%avoiding header lines
for i=1:3
s3=fgetl(f1);
end
%extract the co-eff and calc cp,h,s,molecular weight
for j=1:53
tline=fgetl(f1);
species_name=tline(1:6);
%strfind func is used to find string in that line
line1=fgetl(f1);
l=strfind(line1,'E');
a1=str2num(line1(1:l(1)+3));
a2=str2num(line1(l(1)+4:l(2)+3));
a3=str2num(line1(l(2)+4:l(3)+3));
a4=str2num(line1(l(3)+4:l(4)+3));
a5=str2num(line1(l(4)+4:l(5)+3))

line2=fgetl(f1);
m=strfind(line2,'E');
a6=str2num(line2(1:m(1)+3));
a7=str2num(line2(m(1)+4:m(2)+3));
a8=str2num(line2(m(2)+4:m(3)+3));
a9=str2num(line2(m(3)+4:m(4)+3));
a10=str2num(line2(m(4)+4:m(5)+3));


line3=fgetl(f1);
n=strfind(line3,'E');
a11=str2num(line2(1:n(1)+3));
a12=str2num(line2(n(1)+4:n(2)+3));
a13=str2num(line2(n(2)+4:n(3)+3));
a14=str2num(line2(n(3)+4:n(4)+3));
%open a folder and named as that species name,what ever it is...
mkdir(['C:\Users\AMEER\OneDrive\Documents\MATLAB\Examples\R2021b\matlab\FindArrayElementsThatMeetAConditionExample\',species_name])
T=linspace(temp1,temp3,500);
%calling a func(cp,h,s)
[cp,h,s]=co_eff(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T);


%plotting
figure(1)
plot(T,cp,'LineWidth',3)
title(species_name)
xlabel('temperature')
ylabel('specific heat')

figure(2)
plot(T,h,'LineWidth',3)
title(species_name)
xlabel('temperature')
ylabel('enthalpy')

figure(3)
plot(T,s,'LineWidth',3)
title(species_name)
xlabel('temperature')
ylabel('entropy')

directory = (['C:\Users\AMEER\OneDrive\Documents\MATLAB\Examples\R2021b\matlab\FindArrayElementsThatMeetAConditionExample\',species_name]);
cd(directory)
%save that figure in particular folder
saveas(1,'specific_heat.png')
saveas(2,'enthalpy.png')
saveas(2,'entropy.png')
%change tha folder path
cd('C:\Users\AMEER\OneDrive\Documents\MATLAB\Examples\R2021b\matlab\FindArrayElementsThatMeetAConditionExample\')
%calling a func(molecular wt)
molecular_weight = molecular_func(species_name)
end
fclose(f1)

outputs:

  • The spicies name's folder has been created by the code

  • Molecular weight has been displayed in the command window.

o2

N2

 

CO2


Comments

Popular posts from this blog

simple pendulum using matlab

DRAG FORCE

2r robotic arm