Trying to code from Polymath

5 次查看(过去 30 天)
this Polymath code into a Matlab code but I don't know how. Please I need to help. Please.......
  2 个评论
Juan Camilo Guerrero Paredes
function A =function14(V,F)
A=zeros(6,1);
k1d = 0.25;
k2e = 0.10;
k3f = 5;
V=50;
v0=10;
tau= V/v0;
Ca0=1.5;
Cb0=2.0;
C_T0=3.5;
r1d = k1d*Ca*Cb^2;
r2e = k2e*Ca*Cd;
r3f = k3f*Cb*Cc^2;
ra = -r1d-3*r2e;
rb = -2*r1d-3*r3f;
rc = r1d+ r2e -2*r3f;
rd = r1d-2*r2e+r3f;
re = r2e;
rf = r3f;
F(1) = Ca-Ca0-ra*tau;
F(2) = Cb-Cb0-rb*tau;
F(3) = rc*tau-Cc;
F(4) = rd*tau-Cd;
F(5) = re*tau-Ce;
F(6) = rf*tau-Cf;
FT = F(1) + F(2) + F(3) + F(4) + F(5)+ F(6);
Ca = C_T0*(F(1)/ FT );
Cb = C_T0*(F(2)/ FT );
Cc = C_T0*(F(3)/ FT );
Cd = C_T0*(F(4)/ FT );
A(1)=1;
A(2)=1;
A(3)=1;
A(4)=1;
A(5)=1;
A(6)=1;
end
Juan Camilo Guerrero Paredes
Later I did this but dont work.
[V,F] = ode15s('Function14',[0 50],[ 15 , 20 , 0 , 0 , 0 , 0 ]);
v0 =10;
Ca0= 1.5;
La0= 1.5/v0;
Lb0= 2.0/v0;
Xa = (15-F(:,1))/15;
figure
plot(V,F(:,1),V,F(:,2),V,F(:,3),V,F(:,4),V,F(:,5),V,F(:,6))
xlabel('Volumen (dm3)'),
ylabel('Flujo molar (mol/s)')
legend('Fa','Fb','Fc','Fd','Fe','Ff')

请先登录,再进行评论。

采纳的回答

Navya Singam
Navya Singam 2022-1-13
Hi,
MATLAB Version of the Polymath code
%%Initial conditions
IC=[1,1,1,1,1,1];
Vspan=[0 50];
[V,CT]=ode15s(@fn,Vspan,IC);
%%Extracting the parameters
ca=CT(:,1);
cb=CT(:,2);
cc=CT(:,3);
cd=CT(:,4);
ce=CT(:,5);
cf=CT(:,6);
%Plot graph
figure
plot(V,ca,V,cb,V,cc,V,cd,V,ce,V,cf)
xlabel('Volume (dm3)')
ylabel('Flujo molar (mol/s)')
legend('Fa','Fb','Fc','Fd','Fe','Ff')
%ODE function
function dCTdV = fn(~,CT)
%data
V=50;
v0=10;
ca0=1.5;
cb0=2.0;
kd1=0.25;
ke2=0.1;
kf3=5;
tau=V/v0;
%extract parameters
ca=CT(1);
cb=CT(2);
cc=CT(3);
cd=CT(4);
ce=CT(5);
cf=CT(6);
%supporting functions
rd1=kd1*ca*cb^2;
re2=ke2*ca*cd;
rf3=kf3*cb*cc^2;
ra=-rd1-3*re2;
rb=-2*rd1-rf3;
rc=rd1+re2-2*rf3;
rd=rd1-2*re2+rf3;
re=re2;
rf=rf3;
%odes
dCTdV = [(ca-ca0-ra*tau);(cb-cb0-rb*tau);(rc*tau-cc);(rd*tau-cd);(tau*re-ce);(tau*rf-cf)];
end
Refer to this to know more about ode15s solver.
  1 个评论
Juan Camilo Guerrero Paredes
Thanks very much. Navya Singam.....Thanks for helping me I try the code and it works I'm still learning about matLab. Greetings from Colombia.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by