Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
2 views (last 30 days)
Show older comments
clear
%Variables
m=10;
gamma_anode = 0.5; %reactant concentration at anode
gamma_cathode = 1; %reactant concentration at cathode
a_anode = 0.54; %transfer coefficient at anode
a_cathode = 0.52; %transfer coeffiecent at cathode
i0_ref_a = 3.5e-3;%reference exchange current density at anode
Glucose_conc = linspace(3e-3,10e-3,m);%glucose concnetration
Glucose_ref = 0.0001;%reference glucose concentration
i0_ref_c = 1.9e5;%reference exchange current desnity at cathode
Oxygen_conc = 0.016;%oxygen concentration
Oxygen_ref = 1.95e5;%reference oxygen concentration
Er_a = 0; %reference potential at anode
Ea = -0.853; %potential at anode for glucose oxidation
Er_c = 1.229; %reference potential at cathode
Ec = 0.403; %potential at cathode for oxygen reduction
R = 8.314;%Gas constant
F = 96485;%Faraday constant
T = 300; %Temperature of cell
A = 5; %area of fuel cell
Rin = 2.6; %Internal resistance of the cell
n_anode = 2; %moles per reactant at the anode
n_cathode =4;%moles per reactant at the cathode
D_anode = 6.5e-6; %diffusion coefficient of glucose in KOH
D_cathode = 0.0056;%diffusion coefficient of oxygen in plain medium
d_l_a = 0.035; %diffsuion layer thickness anode
d_l_c= 0.03 ;%diffsuion layer thickness cathode
%--------------------------------------------------------------------------
%EXCHANGE CURRENT DENSITY
%Anode
i0_a = (i0_ref_a) * (Glucose_conc/Glucose_ref)^(gamma_anode);%exchage current density at anode
display(i0_a)
%Cathode
i0_c = (i0_ref_c) * (Oxygen_conc/Oxygen_ref)^(gamma_cathode);%exchange current density at cathode
display(i0_c)
%--------------------------------------------------------------------------
%CURRENT DENSITY AT ELECTRODES
%Anode
i_a = (-i0_a) * (exp(a_anode*F*(Ea-Er_a)/(R*T)));%current density at anode
display(i_a)
%Cathode
i_c = (i0_c) * (exp(a_cathode*F*(Ec-Er_c)/(R*T)));%current density at cathode
display(i_c)
%--------------------------------------------------------------------------
%Activation Overpotential
%Anode
V_act_a = ((R*T)/(a_anode*F))*log(i_a/i0_a);%activation potential at anode
V_act_anode = abs(V_act_a);
display(V_act_anode)
%Cathode
V_act_c = ((R*T)/(a_cathode*F))*log(i_c/i0_c);%activation potential at cathode
V_act_cathode = abs(V_act_c);
display(V_act_cathode)
%Total activation overpotential
V_act = V_act_cathode + V_act_anode;
display(V_act)
%--------------------------------------------------------------------------
%Ohmic overpotential
j = i_a + i_c ; %current density of anode and cathode
i = j / A; %current density of fuel cell
R = Rin * A; %resisitance of fuel cell
V_ohm = i * R;%ohmic overpotential of cell
display(V_ohm)
%--------------------------------------------------------------------------
%Concentration overpotential
%limiting current at anode
i_L_a = (n_anode*F*D_anode*Glucose_conc)/d_l_a;
%limiting current at cathode
i_L_c = (n_cathode*F*D_cathode*Oxygen_conc)/d_l_c;
%concentration overpotential at anode
V_conc_anode = ((R*T)/(n_anode*F))*log(i_L_a/(i_L_a-i));
%concentration overpotential at cathode
V_conc_cathode = ((R*T)/(n_cathode*F))*log(i_L_c/(i_L_c-i));
%concentration overpotential
V_conc = V_conc_anode + V_conc_anode;
%--------------------------------------------------------------------------
%Cell potential
Et =1.3; %thermodynamic potential of fuel cell
%Fuel cell voltage
V_cell = Et - V_act - V_conc - V_ohm;
%--------------------------------------------------------------------------
%Power of fuel cell
P_cell = V_cell * i;
%--------------------------------------------------------------------------
%Plots
Plot(P_cell)
1 Comment
Jan
on 8 Mar 2022
Edited: Jan
on 8 Mar 2022
Okay. This is some code and a part of the error message. What is your question?
If you want the readers to find the cause of the problem, post the complete error message, such that we do not have to guess, where the error occurs. I've simply hit the run button here in the forum, such that the error message is inserted.
The message contains some baluable hints. So did you read and consider them? Is a matrix power wanted or an elementwise power?
Accepted Answer
Jan
on 8 Mar 2022
Edited: Jan
on 8 Mar 2022
This line is failing:
i0_a = (i0_ref_a) * (Glucose_conc/Glucose_ref)^(gamma_anode);
The error message contains some valuable hints. Did you read and consider them? Is a matrix power wanted or an elementwise power? If the latter is wanted:
i0_a = i0_ref_a * (Glucose_conc / Glucose_ref) .^ gamma_anode;
% ^
Hint: Avoid overdoing the parentheses. Spaces increase the readability.
There are some more occurrences of this problem:
i0_c = i0_ref_c * (Oxygen_conc/Oxygen_ref) .^ gamma_cathode;
...
V_conc_cathode = (R * T / (n_cathode * F)) * log(i_L_c ./ (i_L_c - i));
...
P_cell = V_cell .* i;
Finally there is not "Plot" command in Matlab, but "plot". The case matters.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!