How do I plot multiple curves on the graphs for different values of variable (plot effect of changing the variable)

18 views (last 30 days)
% clear
% Parameters A=0.19038; Ea=69710; Hr=-23237; Dp=0.013; roecatbulk=2000; eps=0.41; cpa=30; cpb=40; cpc=70; ma=15; mb=20; mc=35; viscosity=0.18e-4; Ta=410; ntube=1;
D= 1.7; % want to graph lines for D = [ 1.3 1.5 1.7 1.9 2.1] on the same plot
dw=1; wplot=0; np=0; Areac=pi*(D^2)/4; L=40 / Areac; Wmax=L*Areac*roecatbulk;
% Initial conditions w=0; fc=0; fto=0.52; ya0=0.32; yb0=0.68; temp=450; p=50; fao=fto*ya0; fbo=fto*yb0; X=0; %Integration loop while w<Wmax
fa=fao-fc;
fb=fbo-fc;
ya=fa/(fa+fb+fc);
yb=fb/(fa+fb+fc);
yc=fc/(fa+fb+fc);
k=A*exp(-Ea/8.314/temp); rate=k*ya*yb*p^2; roegasmolar=p/(temp*1.01325*82.057e-3); flowvoltube=(fa+fb+fc)/roegasmolar/ntube; maverage=ya*ma+yb*mb+yc*mc; roegas=roegasmolar*maverage; vel=flowvoltube/Areac; reynolds=Dp*vel*roegas/viscosity; friction=(1-eps)*(1.75+150*(1-eps)/reynolds)/(eps^3); U=0.227;
%Save for plotting
if w>=wplot;np=np+1;wp(np)=w/1000;tempp(np)=temp;pp(np)=p;yap(np)=ya*100;
ycp(np)=yc*100;Xp (np)=X;wplot=wplot+10;end
%Derivative evaluation
dfcdw=rate;
dpdw=-friction*L*roegas*(vel^2)/(Dp*Wmax*1e5);
dtempdw=(-Hr*rate-4*U*(temp-Ta)/(roecatbulk*D))/(cpa*fa+cpb*fb+cpc*fc);
dXdw= rate / fao;
% Integration
fc=fc+dfcdw*dw;
temp=temp+dtempdw*dw;
p=p+dpdw*dw;
X=X+dXdw*dw;
w=w+dw;
if p<10;break;end
end
clf
subplot(2,2,1);plot(wp,tempp);grid;ylabel('T (K)');title ('Cooled; Ta=400'); axis ([0 80 450 600]); %subplot(2,2,2);plot(wp,ycp);grid;ylabel('yC (%)'); subplot(2,2,3); plot(wp,yap);grid;ylabel('yA (%)'); xlabel('w (1000kg)'); axis ([0 80 0 40]); subplot(2,2,2); plot(wp,pp);grid;ylabel('P (bar)'); xlabel('w (1000kg)'); axis ([0 80 49.5 50]); subplot(2,2,4); plot(wp,Xp);grid;ylabel('X'); xlabel('w(1000kg)'); axis ([0 80 0 1]);

Accepted Answer

KSSV
KSSV on 1 Dec 2021
You need to run a loop like shown below:
clear
% Parameters
A=0.19038; Ea=69710; Hr=-23237; Dp=0.013; roecatbulk=2000; eps=0.41; cpa=30; cpb=40; cpc=70; ma=15; mb=20; mc=35; viscosity=0.18e-4; Ta=410; ntube=1;
DD = [ 1.3 1.5 1.7 1.9 2.1];
for i = 1:length(DD)
D = DD(i) ;
dw=1; wplot=0; np=0;
Areac=pi*(D^2)/4;
L=40 / Areac;
Wmax=L*Areac*roecatbulk;
% Initial conditions
w=0; fc=0; fto=0.52; ya0=0.32; yb0=0.68; temp=450; p=50; fao=fto*ya0; fbo=fto*yb0; X=0;
%Integration loop
while w<Wmax
fa=fao-fc;
fb=fbo-fc;
ya=fa/(fa+fb+fc);
yb=fb/(fa+fb+fc);
yc=fc/(fa+fb+fc);
k=A*exp(-Ea/8.314/temp); rate=k*ya*yb*p^2; roegasmolar=p/(temp*1.01325*82.057e-3); flowvoltube=(fa+fb+fc)/roegasmolar/ntube; maverage=ya*ma+yb*mb+yc*mc; roegas=roegasmolar*maverage; vel=flowvoltube/Areac; reynolds=Dp*vel*roegas/viscosity; friction=(1-eps)*(1.75+150*(1-eps)/reynolds)/(eps^3); U=0.227;
%Save for plotting
if w>=wplot;np=np+1;wp(np)=w/1000;tempp(np)=temp;pp(np)=p;yap(np)=ya*100;
ycp(np)=yc*100;Xp (np)=X;wplot=wplot+10;end
%Derivative evaluation
dfcdw=rate;
dpdw=-friction*L*roegas*(vel^2)/(Dp*Wmax*1e5);
dtempdw=(-Hr*rate-4*U*(temp-Ta)/(roecatbulk*D))/(cpa*fa+cpb*fb+cpc*fc);
dXdw= rate / fao;
% Integration
fc=fc+dfcdw*dw;
temp=temp+dtempdw*dw;
p=p+dpdw*dw;
X=X+dXdw*dw;
w=w+dw;
if p<10;break;end
end
subplot(2,2,1); hold on ; plot(wp,tempp);grid;ylabel('T (K)');title ('Cooled; Ta=400'); axis ([0 80 450 600]);
%subplot(2,2,2);plot(wp,ycp);grid;ylabel('yC (%)');
subplot(2,2,3); hold on ; plot(wp,yap);grid;ylabel('yA (%)'); xlabel('w (1000kg)'); axis ([0 80 0 40]);
subplot(2,2,2); hold on ; plot(wp,pp);grid;ylabel('P (bar)'); xlabel('w (1000kg)'); axis ([0 80 49.5 50]);
subplot(2,2,4); hold on ; plot(wp,Xp);grid;ylabel('X'); xlabel('w(1000kg)'); axis ([0 80 0 1]);
end
The effective way would be to save the data for each D into an array and then plot at the end.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!