How to solve " Error using vertcat Dimensions of arrays being concatenated are not consistent " problem ?

4 views (last 30 days)
I am getting "Error using vertcat Dimensions of arrays being concatenated are not consistent" error for the following code. Would anyone please help me find what is the problem here and how to fix it please.
clc
clear
close all
T_ar=300; % Temparature of Argon gas
n=1.72e16; % plasma density in m^-3
m_e=9.109e-31; % mass of an electron in kg
e=1.60217663e-19; % electronic charge in Coulomb
epsilon=8.854e-12; % permittivity of free space in F*m^-1
A_sp=0.00502656; % Powered Electrode Area in m^2 (4 cm radious)
A_sg=0.007854; % Grounded Electrode Area in m^2 (5 cm radious)
lp=0.06; % plasma bulk length in m
T_e=2.64; % Electron Temparature in eV
p=60*10^-3; % pressure in Torr
n_g=3.3*10^22*p; % gas density in m^-3
Km=10^-13; % rate coefficient
v_m=Km*n_g; % momentum transfer collision frequency
k_B=1.380649e-23; % Boltzmann's Constant in J/K
v_e = sqrt(8*e*T_e/(pi*m_e)); % mean thermal speed
v_eff=v_m+((v_e)/lp); % effective collision frequency
m_i=40; % Argon mass in amu for determining bohm velocity
amu=1.660539e-27; % 1 Dalton
v_B=sqrt((e*T_e)/(m_i*amu)); % Bohm velocity
xx1=(1/(2*e*epsilon*n*A_sp^2));
xx2=(1/(2*e*epsilon*n*A_sg^2));
xx3=(1/(2*e*epsilon*n*A_sp^2*T_e));
xx4=(1/(2*e*epsilon*n*A_sg^2*T_e));
Lp= (lp*m_e)/(e^2*n*A_sp); % Plasma Bulk Inductance
Lp_inv=1/Lp;
J_e=e*n*v_e; % Coefficient of electron current
J_i=e*n*v_B; % Coefficient of ion current
Jip=J_i*A_sp; % Ion current at Powered Sheath
Jig=J_i*A_sg; % Ion current at Grounded Sheath
Jep=J_e*A_sp;
Jeg=J_e*A_sg;
V0=300; % Amplitude of RF input voltage
C_B=3.34e-6; % Dc blocking capacitor
Cb_inv=1/C_B;
f = @(t,x) [-(x(4))-(Jip) + (Jep.*exp(-(xx1.*(x(1)^2))));
(x(4))-(Jig) + (Jeg.*exp(-(xx2.*(x(2)^2))));
-(Cb_inv.*(x(4)));
(V0.*cos(t).*(Lp_inv))+(xx3.*(x(1)^2).*(Lp_inv))-(xx4.*(x(2)^2).*(Lp_inv))+(x(3).*(Lp_inv)) -(v_eff.*(x(4)))];
options = odeset('RelTol',1e-4,'AbsTol',1e-6);
[t,xa] = ode45(f,[0, 80],[0,0,-62,0],options);
Error using vertcat
Dimensions of arrays being concatenated are not consistent.

Error in solution>@(t,x)[-(x(4))-(Jip)+(Jep.*exp(-(xx1.*(x(1)^2))));(x(4))-(Jig)+(Jeg.*exp(-(xx2.*(x(2)^2))));-(Cb_inv.*(x(4)));(V0.*cos(t).*(Lp_inv))+(xx3.*(x(1)^2).*(Lp_inv))-(xx4.*(x(2)^2).*(Lp_inv))+(x(3).*(Lp_inv)),-(v_eff.*(x(4)))] (line 49)
f = @(t,x) [-(x(4))-(Jip) + (Jep.*exp(-(xx1.*(x(1)^2))));

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
figure(1)
plot(t,xa(:,1),'Color','blue')
title('xa1')
xlabel('t'), ylabel('Qsp (Powered Electrode Sheath Charge)')
grid on
figure(2)
plot(t,xa(:,2),'Color','blue')
title('xa2')
xlabel('t'), ylabel('Qsp (Grounded Electrode Sheath Charge)')
grid on
figure(3)
plot(t,xa(:,3),'Color','blue')
title('xa3')
xlabel('t'), ylabel('Self Bias Voltage')
grid on
figure(4)
plot(t,xa(:,4),'Color','blue')
title('xa4')
xlabel('t'), ylabel('Plasma Current')
grid on

Accepted Answer

Stephen23
Stephen23 on 7 Feb 2024
Edited: Stephen23 on 7 Feb 2024
You probably think that your square brackets are creating a 4x1 vector.
But they aren't, because of the random space characters that you included around the plus & minus operators: you need to be consistent: either all operators with spaces or none of them (simplest is none). This will fix your bug:
(V0.*cos(t).*(Lp_inv))+(xx3.*(x(1)^2).*(Lp_inv))-(xx4.*(x(2)^2).*(Lp_inv))+(x(3).*(Lp_inv))-(v_eff.*(x(4)))];
% ^ no space
Compare the effect of the space around the minus operator here:
[1 2 -3] % what you did
ans = 1×3
1 2 -3
[1 2-3] % what you should do
ans = 1×2
1 -1
[1 2 - 3] % best avoided
ans = 1×2
1 -1
Also you should get rid of most of those parentheses, they make the code hard to follow (which in turn makes it harder to debug). For example this:
-(x(4))-(Jip) + (Jep.*exp(-(xx1.*(x(1)^2))))
should be simply:
-x(4)-Jip+Jep.*exp(-xx1.*x(1).^2)

More Answers (0)

Categories

Find more on Particle & Nuclear Physics 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!