Project

Project 1

%to read the thermaldata file and display the cofficients

A = fopen(\'thermaldata.txt\',\'r\');
fgetl(A)
global_low_temp = fscanf(A,\'%f\',[1 1]);
global_mid_temp = fscanf(A,\'%f\',[1 1]);
global_high_temp = fscanf(A,\'%f\',[1 1]);
fprintf(\'global_low_temp= %iK \\n\',global_low_temp)
fprintf(\'global_mid_temp= %iK  \\n\',global_mid_temp)
fprintf(\'global_high_temp= %iK  \\n\',global_high_temp)
fgetl(A);
fgetl(A)
fgetl(A) 
fgetl(A)
for k=fgetl(A)
    k=k+1;
    molecular_weight=weight(k);
fprintf(\'molecular weight= %f \\n\', molecular_weight)
L1 = fgetl(A);
x=findstr(L1,\'E\');
c1 = L1(1:x(1)+6);
c1=str2num(c1);
fprintf(\'C1= %f \\n\',c1)
c2 = L1(x(1)+4:x(2)+3);
c2=str2num(c2);
fprintf(\'C2= %.10f \\n\',c2)
c3 = L1(x(2)+4:x(3)+3);
c3=str2num(c3);
fprintf(\'C3= %.15f \\n\',c3)
c4 = L1(x(3)+4:x(4)+3);
c4=str2num(c4);
fprintf(\'C4= %.20f \\n\',c4)
c5 = L1(x(4)+4:x(5)+3);
c5=str2num(c5);
fprintf(\'C5= %.20f \\n\',c5)


L2 = fgetl(A);
y=findstr(L2,\'E\');
c6 = L2(1:y(1)+3);
c6=str2num(c6);
fprintf(\'C6= %.4f \\n\',c6)
c7 = L2(y(1)+4:y(2)+3);
c7=str2num(c7);
fprintf(\'C7= %f \\n\',c7)
c8 = L2(y(2)+4:y(3)+3);
c8=str2num(c8);
fprintf(\'C8= %f \\n\',c8)
c9 = L2(y(3)+4:y(4)+3);
c9=str2num(c9);
fprintf(\'C9= %.6f \\n\',c9)
c10 = L2(y(4)+4:y(5)+3);
c10=str2num(c10);
fprintf(\'C10= %.9f \\n\',c10)

L3=fgetl(A);
z=findstr(L3,\'E\');
c11 = L3(1:z(1)+3);
c11=str2num(c11);
fprintf(\'C11= %.15f \\n\',c11)
c12 = L3(z(1)+4:z(2)+3);
c12=str2num(c12);
fprintf(\'C12= %.15f \\n\',c12)
c13 = L3(z(2)+4:z(3)+3);
c13=str2num(c13);
fprintf(\'C13= %f \\n\',c13)
c14 = L3(z(3)+4:z(4)+3);
c14=str2num(c14);
fprintf(\'C14= %.6f \\n\',c14)
fgetl(A)
output=TEMP_PROP(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14);

end


functions:

%to calculate entropy,enthalpy,specific heat and plot the graphs

function [CP,H,S] = TEMP_PROP(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)
T =linspace(500,2000,200);
R=8.41;

if T<=1000

CP=R.*(c1+(c2.*T)+(c3.*T.^2)+(c4.*T.^3)+(c5.*T.^5));
H=R.*T.*(c1+(c2.*(T./2))+(c3.*((T.^2)./3))+(c4.*((T.^3)./4))+(c5.*((T.^4)./5))+(c6./T));
S=R.*((c1.*log(T))+(c2.*T)+(c3.*((T.^2)./2))+(c4.*((T.^3)./3))+(c5.*((T.^4)./4))+c7);

else    
CP =R.*(c8+(c9.*T)+(c10.*T.^2)+(c11.*T.^3)+(c12.*T.^5));
H =R.*T.*(c8+(c9.*(T./2))+(c10.*((T.^2)./3))+(c11.*((T.^3)./4))+(c12.*((T.^4)./5))+(c13./T));
S =R.*((c8.*log(T))+(c9.*T)+(c10.*((T.^2)./2))+(c11.*((T.^3)./3))+(c12.*((T.^4)./4))+c14);
end

figure
subplot(2,2,1)
plot(T,CP)
xlabel(\'Temperature (K)\')
ylabel(\'Specific heat (J/kg-K)\')
grid on 

subplot(2,2,2)
plot(T,H)
xlabel(\'Temperature (K)\')
ylabel(\'Enthalpy (J)\')
grid on

subplot(2,2,3)
plot(T,S)
xlabel(\'Temperature(K)\')
ylabel(\'Entropy (J/K)\')
grid on


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

end
a(b)=1;
c(b)=k(m);
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
m=findstr(stdwhts,c(i));
Mol_weight=Mol_weight+(stwhts(m)*a(i));
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.