Explanation of conditional statements.
Show older comments
Hello,
I am working on mathematical modeling of multicomponent dissolution and biodegradation of BTEX compounds in oily sludge of petrochemical refinery industries. I have two matlab codes which have I to run simulataneously to obtain the result and there's no error in the code. I got these codes from my instructor and I couldn't understand the syntax of the conditonal statements (for, if, elseif) in the attached Matlab Code 2; as why are they used to get the result? Could someone please comment and explain at each Conditional statement syntax that is mentioned in MATLAB 2 code? Please find the attached.
MATLAB CODE 1
%Define t as t
t = t;
%define variable involved in final differential equations expressions
diap = 150*10^-6; %diameter of particle in meters
Dab = 2.808*10^-6; %diffusion coefficient of xylene into water in m2/hr
vel=18000; %velocity in m/h
dwater=1000000; %density for water given in g/m^3
vis=3204; % viscosity given in g/m*hr
%Calculate mass transfer coefficient
Nre=(diap*vel*dwater)/vis; % reynolds number
Nsc=vis/(dwater*Dab); %smiths number
Nsh=2+(0.95*(Nre^0.5)*(Nsc^(1/3))); %Sherwood number
kc = (Nsh*Dab)/diap; %mass transfer coefficient in m/hr
cstar = 160; %solubility limit for xylene in grms/m3
kr = 0.00165; %decay rate constant in 1/s for xylene in aeronic processes
m0 = 354; %initial mass of xylene in grms per 1 m3 of NAPL
dxyl = 860000; %density of xylene in grms/m3
cons=(6*(m0^(1/3)))/(dxyl*diap);
%define dependent variables as a two element vector
mx = y(1); %variable for mass of xylene
cx = y(2); %variable for concentration of xylene in water
%define differential equations dy1 and dy2 as a two element vector
dy(1)= -cons*kc*(cstar-y(2))*(y(1)^(2/3));
dy(2) = cons*kc*(cstar-y(2))*(y(1)^(2/3))-(kr*y(2));
%transpose dy
dy = dy' ;
end
MATLAB CODE 2
clear; clc
y0(1) = 354; %initial condition of mx at t=0
y0(2) = 0; %initial condition of cx at t=0
tspan = 0:0.001:800; %solve differential equations from 0 to 15000 hrs
[T,Y] = ode23s(@biodegkc,tspan,y0); %solve for y1, y2
for i=1:length(Y)
if Y(i,1)<0
Y(i,1)=0;
elseif i>1
if Y(i,1)>Y(i-1,1)
Y(i,1)=0;
end
if Y(i,2)<0
Y(i,2)=0;
end
end
end
%plot the results'
figure('units','normalized','outerposition',[0 0 1 1])
plot(T,Y(:,1),'*',T,Y(:,2),'+');
xlabel('time,hr');
ylabel('mx,mass(g) or cx,concentration(g/m3)');
title('Mass and Concentration profile ');
legend('mx','cx');
save('filenameT.txt','T','-ascii')
save('filenameY.txt','Y','-ascii')
Accepted Answer
More Answers (0)
Categories
Find more on Special Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!