Project

COMPLETE NASA PROJECT ASSIGNMENT

%Part 1 To extract 14 coeff

function [coeff]= search_element(x)

f=fopen(\'therm.dat\',\'r\');

x1=[x,\' \'];
for i=1:200
g1=fgetl(f);
if strfind(g1,x1)
break;
end
end
g1=fgetl(f);
g2=fgetl(f);
g3=fgetl(f);
coeff=data_extractions(g1,g2,g3);
end

function [coeff]=data_extractions(a1,a2,a3)


j=findstr(a1,\'E\');
k=findstr(a2,\'E\');
m=findstr(a3,\'E\');

coeff(1)=str2num(a1(1:j(1)+3));
coeff(2)=str2num(a1(j(1)+4:j(2)+3));
coeff(3)=str2num(a1(j(2)+4:j(3)+3));
coeff(4)=str2num(a1(j(3)+4:j(4)+3));
coeff(5)=str2num(a1(j(4)+4:j(5)+3));
coeff(6)=str2num(a2(1:k(1)+3));
coeff(7)=str2num(a2(k(1)+4:k(2)+3));
coeff(8)=str2num(a2(k(2)+4:k(3)+3));
coeff(9)=str2num(a2(k(3)+4:k(4)+3));
coeff(10)=str2num(a2(k(4)+4:k(5)+3));
coeff(11)=str2num(a3(1:m(1)+3));
coeff(12)=str2num(a3(m(1)+4:m(2)+3));
coeff(13)=str2num(a3(m(2)+4:m(3)+3));
coeff(14)=str2num(a3(m(3)+4:m(4)+3));

end

%Part2 To calculate enthalpy entropy spc heat

function [enthalpy entropy spheat]=calculate(T,coeff)

if T<=1000

spheat=coeff(1)+(coeff(2)*T)+(coeff(3)*T*T) + (coeff(4)*T*T*T) + (coeff(5)*T*T*T*T);
spheat=spheat*8.314;
entropy=coeff(1)*log(T) + coeff(2)*T + coeff(3)*T*T/2 + coeff(4)*T*T*T/3 + coeff(5)*T*T*T*T/4 + coeff(7);
entropy=entropy*8.314;
enthalpy=coeff(1) + coeff(2)*T/2 + coeff(3)*T*T/3 + coeff(4)*T*T*T/4 + coeff(5)*T*T*T*T/5 + coeff(6)/T;
enthalpy=enthalpy*8.314*T;

else
spheat=coeff(8)+(coeff(9)*T)+(coeff(10)*T*T) + (coeff(11)*T*T*T) + (coeff(12)*T*T*T*T);
spheat=spheat*8.314;
entropy=coeff(8)*log(T) + coeff(9)*T + coeff(10)*T*T/2 + coeff(11)*T*T*T/3 + coeff(12)*T*T*T*T/4 + coeff(14);
entropy=entropy*8.314;
enthalpy=coeff(8) + coeff(9)*T/2 + coeff(10)*T*T/3 + coeff(11)*T*T*T/4 + coeff(12)*T*T*T*T/5 + coeff(13)/T;
enthalpy=enthalpy*8.314*T;
end
end

%Part 3 To calculate Molecular weight

function [Mol_weight]=weight(str)
k=length(str);
b=1;
if str2num(str(k))
for i=1:k
if str2num(str(i))
a(b)=str2num(str(i));
c(b)=str(i-1);
b=b+1;
end
end
else
for i=1:(k-1)
if str2num(str(i))
a(b)=str2num(str(i));
c(b)=str(i-1);
b=b+1;
end

end
a(b)=1;
c(b)=str(k);
end
no_element=length(a);
stdwhts=[\'O\',\'C\',\'N\',\'H\',\'R\'];
stwhts=[16,12,14,1,40];
Mol_weight=0;
for i=1:no_element
k=findstr(stdwhts,c(i));
Mol_weight=Mol_weight+(stwhts(k)*a(i));
end
end

%part 4 and part 5 To plot Cp,Enthalpy Entropy vs Temp in the specific name of that element subfolder

function []=plots(x)
i=1;
[coeff]=search_element(x);

for T=200:3500
[enthalpy(i),entropy(i),spheat(i)]= calculate(T,coeff);
i=i+1;
end
temp=200:3500;
currFolderName =x;
mkdir(currFolderName);
figure(1)
plot(temp,enthalpy)
xlabel(\'Temp\')
ylabel(\'Enthalpy\')
y=\'C:\\Users\\Apoorv Srivastava\\Desktop\\\';
y=[y,x,\'\\Enthalpy vs temp.jpg\']

print(\'Enthalpy vs temp\',\'-djpeg\')


figure(2)
plot(temp,entropy)
xlabel(\'Temp\')
ylabel(\'Entropy\')
print(\'Entropy vs temp\',\'-djpeg\')

figure(3)
plot(temp,spheat)
xlabel(\'Temp\')
ylabel(\'Specific Heat\')
print(\'Spheat vs temp\',\'-djpeg\')

movefile(\'Enthalpy vs temp.jpg\',y)
y=\'C:\\Users\\Apoorv Srivastava\\Desktop\\\';
y=[y,x,\'\\Entropy vs temp.jpg\']
movefile(\'Entropy vs temp.jpg\',y)
y=\'C:\\Users\\Apoorv Srivastava\\Desktop\\\';
y=[y,x,\'\\Spheat vs temp.jpg\']
movefile(\'Spheat vs temp.jpg\',y)


end

%Part 6 To save plot for all species in therm.dat

%TO SAVE PLOTS IN SUBFOLDER CREATED WITH SPECIES NAME
f1=fopen(\'therm.dat\',\'r\');
for i=1:5
g1=fgetl(f1);
end
for i=6:300
g1=fgetl(f1);
if rem((i-2),4)== 0
st=g1(1:8);
for q=1:8
if st(q)==\' \';
str=st(1:(q-1));
break;
elseif st(q)==\'(\';
str=st(1:(q-1));
break;
end
end
plots(str);
end


end

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.