0% found this document useful (0 votes)
133 views

MATLAB

The document contains code for several MATLAB programs that solve various engineering problems: 1) A program that calculates concentration of a brine solution in molar, molal, or normal units depending on user input. 2) A program that determines the phase of water (gas, liquid, or solid) based on the temperature input by the user. 3) A program that uses the half interval method to numerically find the root of a given equation between initial estimates provided by the user.

Uploaded by

Benedict Marzan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

MATLAB

The document contains code for several MATLAB programs that solve various engineering problems: 1) A program that calculates concentration of a brine solution in molar, molal, or normal units depending on user input. 2) A program that determines the phase of water (gas, liquid, or solid) based on the temperature input by the user. 3) A program that uses the half interval method to numerically find the root of a given equation between initial estimates provided by the user.

Uploaded by

Benedict Marzan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CONCENTRATION

clc;
disp('This program will enable you to compute for
the concentration of brine solution');
m=input('Enter the amount of NaCl in grams: ');
d=input('Enter the density of brine solution in g/ml:
');
v=input('Enter the volume of the solvent in ml: ');
disp(' Selection for the concentration
computation:');
disp(' A) Compute for the concentration in Molar:');
disp(' B) Compute for the concentration in Molal:');
disp(' C) Compute for the concentration in
Normal:');
choice=input('Enter your choice: ', 's');
choice=lower(choice);
c=0; Vsolvent=0; msolvent=0;
switch choice
case ('a')
Vsoln=((m+v)/(d*1000));
c=((m/58.45)/Vsoln);
fprintf('The concentration is %f Molar',c);
case ('b')
msolvent=(V/1000);
c=((m/58.45)/msolvent);
fprintf('The concentration is %f Molal',c);
case ('c')
Vsoln=((m+v)/d*1000);
c1=((m/58.45)/Vsoln);
c=(c1*1);
fprintf('The concentration is %f Normal',c);
otherwise
disp('You have entered the wrong choice');
end
PHASE OF WATER
clc,
disp ('This program will determine the phase of
water:');
t=input('Enter the temperature of water in Degree
Celsius:' );
if t>100
disp('The water is in Gas Phase');
elseif t<=100 & t>0
disp('The water is in Liquid Phase');
else t<0
disp('The water is in Solid Phase');
end

C=input('Enter the number of Carbon atoms:');


H=input('Enter the number of Hydrogen atoms:');
O=input('Enter the number of Oxygen atoms:');
N=input('Enter the number of Nitrogen atoms:');
S=input('Enter the number of Sulfur atoms:');
MW=((C*12)+(H*1)+(O*16)+(N*14)+(S*32));
fprintf('The molecular weight of the fuel is
%f\n',MW);
ZERO ORDER KINETICS
clc;
Cao=15.0;
k=0.0567;
fprintf('Time(s)\tCa(gmole/L-s)');
for t=0:10:60
Ca=Cao-(k*t);
fprintf('%d\t%f\n',t,Ca);
end
HEAT TRANSFER
clc;
disp('This program will compute the heat transfer
coefficient');
disp('The operating temperature is 370 degrees F.');
M=input('Enter the mass flowrate of the liquid in
lbm/hr:');
D=input('Enter the diameter of the pipe in inches:');
L=input('Enter the length of the pipe in feet:');
K=input('Enter the thermal conductivity:');
Vo=input('Enter the viscosity of the oil:');
Vw=input('Enter the viscosity of the water:');
Re=input('Enter the reynolds number:');
Pr=input('Enter the prandl number:');
d=D/12;
A=(Re*Pr*d/L)^(1/3);
B=(Vo/Vw)^0.14;
h=1.86*K*A*B/d;
fprintf('The heat transfer coefficient is %f\n',h);
HEAT TRANS

MOLECULAR WEIGHT

clc;
K=input('Enter the thermal conductivity:');
Ti=input('Enter the inlet temperature in degree F:');
Tw=input('Enter the wall temperature in degree F:');
m=input('Enter the mass flowrate:');
L=input('Enter the length of the pipe in ft:');
D=input('Enter the diameter in inches:');
Cp=input('Enter the Cp of oil:');

clc;
disp('This program will compute the molecular
weight of the fuel');

To=150;
while To<=350
Tm=((Tw-Ti)+(Tw-To))/2;

Tave=(To+Ti)/2;
fprintf('\n');
fprintf('Enter the viscosity of oil in lbm/fthr @ %f
degree F:',Tave);
fprintf('\n');
Vo=input('Enter the viscosity of oil:');
fprintf('\n')
fprintf('Enter the viscosity of water in lbm/fthr @
%f degree F:',Tave);
fprintf('\n')
Vw=input('Enter the viscosity of water:');
fprintf('\n')
d=D/12;
Re=(4*m)/(Vo*d*3.1416);
Pr=(Cp*Vo)/K;
A=(Re*Pr*d/L)^(1/3);
B=(Vo/Vw)^0.14;
h=1.86*K*A*B/d;
q=(h*d*L*3.1416*Tm);
Toc=(q/(m*Cp))+Ti;
fprintf('\n%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t
%f\n',To,Tm,Tave,Re,Pr,h,q,Toc);
To=To+50;
End

A=(Re*Pr*d/L)^(1/3);
B=(Vo/Vw)^0.14;
h=1.86*K*A*B/d;
q=(h*d*L*3.1416*Tm);
Toc=(q/(m*Cp))+Ti;
fprintf('\n%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t
%f\n',To,Tm,Tave,Re,Pr,h,q,Toc);
To=To+25;
End
HALF INTERVAL
clc;
disp('This is Half Interval Numerical Integration
method which will compute the root of a given
equation');
a=input('Enter the first initial estimate:');
b=input('Enter the second initial estimate:');
k=0;
fxc=82.0-26.0-(3*a)-(88*a*a)+(45.4*a*a*a)(9*a*a*a*a)+(0.65*a*a*a*a*a);
if(fxc>0)
x1=a
x2=b;

HEAT TRANS 25
else
clc;
K=input('Enter the thermal conductivity:');
Ti=input('Enter the inlet temperature in degree F:');
Tw=input('Enter the wall temperature in degree F:');
m=input('Enter the mass flowrate:');
L=input('Enter the length of the pipe in ft:');
D=input('Enter the diameter in inches:');
Cp=input('Enter the Cp of oil:');
To=150;
while To<=350
Tm=((Tw-Ti)+(Tw-To))/2;
Tave=(To+Ti)/2;
fprintf('\n');
fprintf('Enter the viscosity of oil in lbm/fthr @ %f
degree F:',Tave);
fprintf('\n');
Vo=input('Enter the viscosity of oil:');
fprintf('\n')
fprintf('Enter the viscosity of water in lbm/fthr @
%f degree F:',Tave);
fprintf('\n')
Vw=input('Enter the viscosity of water:');
fprintf('\n')
d=D/12;
Re=(4*m)/(Vo*d*3.1416);
Pr=(Cp*Vo)/K;

x1=b;
x2=a;
end
fprintf('\n k\t
xa\t

x1\t
fx\t');

x2\t

do
xa=((x1+x2)/2.0);
fx=82.0-26.0-(3*xa)-(88*xa*xa)
+(45.4*xa*xa*xa)-(9*xa*xa*xa*xa)
+(0.65*xa*xa*xa*xa*xa);
if(fx>0)
x1=xa;
else
x2=xa;
k=k+1;
fprintf('\n%d\t%f\t%f\t%f\t
%f\t',k,x1,x2,xa,fx);
end
while(abs(fx>0.0001));
fprintf('The value of x is %f:',xa);
end

You might also like