Unable to Understand error: left and right side elements do not match

3 次查看(过去 30 天)
Here is my code to solve and ODE given by the function O_Hydrogen(~,C,japp,alpha,params) in the code, after running i keep getting the same error. I am unable to understand why ? Could anyone please explain.
clc
%% Parametrs Set of Electrochemical Cell
params.Volume= 0.0005; % m3
params.ElecArea= 87.6e-04; % m2
params.Masstransfercoefficient= 5.2e-05;% m/s
th=input("Input Time in hours ");
tend= 60*th; % Time in Seconds
%% Initial Values
C0=0.625; % mole O2 / m3
H0=0; % mole H2/m3
yi=[C0;H0;0];
jlim_0 = j(C0,params); % A/m2
japp = input("Input applied current density"); % A/m2
%% Calculation of critical time and crtical COD
alpha=japp/jlim_0; % Dimensionless
Cr=alpha*C0; % Critical COD mole O2 / m3
tcr= ((1-alpha)/alpha)*params.Volume/(params.ElecArea*params.Masstransfercoefficient); % Seconds
%% Determination of step size
% Number of points to plot
n=100;
dt1=2*tend/(n);
dt2=2*(tend-tcr)/(n);
dt3=tcr/n;
trange=0:dt3:tcr;
trange2=tcr:dt2:tend;
trange_H = 0:dt1:tend;
%% Equation solving
% [t1,C1]=ode45(@(t,C)COD(t,C,alpha,params),trange_H,C0);
%
% [t2,C2]=ode45(@(t,C)COD(t,C,alpha,params),trange2,Cr);
%
% [t,H]=ode45(@(t,H)Hydrogen(t,japp,params),trange_H,H0);
%% Test ODE
[t,Cc] = ode45(@(t,C)O_Hydrogen(t,japp,C,alpha,params),trange_H,yi);
%% Append All data
% [CC]=[C1;C2];
% [T]= [t1;t2];
%% Plot Data
% figure
% plot(T,CC);
% figure
% plot(t,H);
%% Calculation of limiting current Density
function jlim= j(C,params)
km=params.Masstransfercoefficient;
jlim = 4*96500*km*C;
end
%% Anodic Pollutant Oxidation Charge Control
function dCdt=COD(~,C,alpha,params)
a=alpha;
Vr=params.Volume;
A=params.ElecArea;
km=params.Masstransfercoefficient;
dCdt=zeros(1,1);
dCdt(1)=C(1)*(-a)*A*km/Vr ; % mol COD/s
end
%% Cathodic Hydrogen Genreanration
function dHdt=Hydrogen(~,japp,params)
A=params.ElecArea; % m2;
Vr=params.Volume; % m3;
j=japp; %A/m2
F=96500;
dHdt=zeros(1,1);
dHdt(1)=(j*A/(2*F*Vr)); % mol H2/s
end
%% Hydrogen production due to pollutant oxidation
function dOHdt=O_Hydrogen(~,C,japp,alpha,params)
a=alpha;
Vr=params.Volume;
A=params.ElecArea;
km=params.Masstransfercoefficient;
F=96500;
j=japp;
dOHdt=zeros(3,1);
dOHdt(1)=C.*(-a)*A*km/Vr; % mol COD/s
dOHdt(2)= j*A/(2*F*Vr) ; % mol H2/s Hydrogen Production from Electrolysis
dOHdt(3) = 36.*dOHdt(1); % mol H2/s due to organics oxidation
end
  6 个评论
Ranjeev Kumar Bhatia
Hi everyone,
Thank you for the feedback. It managed to work.
Much appreciated.
Corrected Code
clc
%% Parametrs Set of Electrochemical Cell
params.Volume= 0.0005; % m3
params.ElecArea= 87.6e-04; % m2
params.Masstransfercoefficient= 5.2e-05;% m/s
th=input("Input Time in hours ");
tend= 60*th; % Time in Seconds
%% Initial Values
C0=0.625; % mole O2 / m3
H0=0; % mole H2/m3
yi=[C0;H0;0];
jlim_0 = j(C0,params); % A/m2
japp = input("Input applied current density"); % A/m2
%% Calculation of critical time and crtical COD
alpha=japp/jlim_0; % Dimensionless
Cr=alpha*C0; % Critical COD mole O2 / m3
tcr= ((1-alpha)/alpha)*params.Volume/(params.ElecArea*params.Masstransfercoefficient); % Seconds
%% Determination of step size
% Number of points to plot
n=100;
dt1=2*tend/(n);
dt2=2*(tend-tcr)/(n);
dt3=tcr/n;
trange=0:dt3:tcr;
trange2=tcr:dt2:tend;
trange_H = 0:dt1:tend;
%% Equation solving
% [t1,C1]=ode45(@(t,C)COD(t,C,alpha,params),trange_H,C0);
%
% [t2,C2]=ode45(@(t,C)COD(t,C,alpha,params),trange2,Cr);
%
% [t,H]=ode45(@(t,H)Hydrogen(t,japp,params),trange_H,H0);
%% Test ODE
[t,Cc] = ode45(@(t,C)O_Hydrogen(t,C,japp,alpha,params),trange_H,yi);
%% Append All data
% [CC]=[C1;C2];
% [T]= [t1;t2];
%% Plot Data
% figure
% plot(T,CC);
% figure
% plot(t,H);
%% Calculation of limiting current Density
function jlim= j(C,params)
km=params.Masstransfercoefficient;
jlim = 4*96500*km*C;
end
%% Anodic Pollutant Oxidation Charge Control
function dCdt=COD(~,C,alpha,params)
a=alpha;
Vr=params.Volume;
A=params.ElecArea;
km=params.Masstransfercoefficient;
dCdt=zeros(1,1);
dCdt(1)=C(1)*(-a)*A*km/Vr ; % mol COD/s
end
%% Cathodic Hydrogen Genreanration
function dHdt=Hydrogen(~,japp,params)
A=params.ElecArea; % m2;
Vr=params.Volume; % m3;
j=japp; %A/m2
F=96500;
dHdt=zeros(1,1);
dHdt(1)=(j*A/(2*F*Vr)); % mol H2/s
end
%% Hydrogen production due to pollutant oxidation
function dOHdt=O_Hydrogen(~,C,japp,alpha,params)
a=alpha;
Vr=params.Volume;
A=params.ElecArea;
km=params.Masstransfercoefficient;
F=96500;
j=japp(1);
dOHdt=zeros(3,1);
dOHdt(1)=C(1).*(-a)*A*km/Vr; % mol COD/s
dOHdt(2)= j*A/(2*F*Vr) ; % mol H2/s Hydrogen Production from Electrolysis
dOHdt(3) = 36.*dOHdt(1); % mol H2/s due to organics oxidation
end

请先登录,再进行评论。

回答(1 个)

Spectro
Spectro 2022-6-9
I think you should replace in the O_Hydrogen function this:
j=japp;
with this:
j=japp(1);

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by