Dimensions of arrays being concatenated are not consistent

1 回表示 (過去 30 日間)
Lewis McKee
Lewis McKee 2019 年 10 月 30 日
回答済み: Stephen23 2019 年 10 月 30 日
Was given an assignment with this code below:
%% Fixed parameters
C=20;
phi=1/15;
VK =-83.3365;
VCa=120;
VL=-60;
gK=8;
gL=2;
gCa=4;
V1=-1.2;
V2=18; % 18
V3=12; % 12
V4=17.4; % 17.4
%% nonlinear functions of V
boltz=@(V,Vh,Vt)(0.5)*(1+tanh((V-Vh)/Vt));
minf=@(V)boltz(V,V1,V2);
dminf=@(V)1/(2*V2)*(sech((V-V1)/V2)).^2;
winf=@(V)boltz(V,V3,V4);
dwinf=@(V)1/(2*V4)*(sech((V-V3)/V4)).^2;
tauw=@(V)1./cosh((V-V3)/(2*V4));
%% Define the right hand side rhs for the model x(1)=V, x(2)=w
I =@(V,w)gK*w*(V-VK)+gCa*minf(V).*(V-VCa)+gL*(V-VL);
rhs=@(x,I0)[1/C*(I0-I(x(1,:),x(2,:)));...
phi*(winf(x(1,:))-x(2,:))/tauw(x(1,:))];
One of the questions was plot all equilibria of rhs(x,I0), where x = [V ; w]', determine the different phase portraits and plot periodic orbits for each portrait.
I begin by redifining rhs with new variables:
M = @(t,x)rhs(x,I0);
t = [0,2*pi];
x0 = [-20;0.4];
M(t,x0);
dM = MyJacobian(M,x0,h);
and I receive:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
And I do not know why this is so.
Does anybody know?

採用された回答

Stephen23
Stephen23 2019 年 10 月 30 日
You included definitions for every variable except for the one that likely causes the problem, I0.
Running your code gives an error that I0 is undefined.
Defining I0 as a scalar double lets your code run without error.
Defining I0 as anything with more than one column will result in your code throwing that "Dimensions of arrays being concatenated are not consistent" error. The cause of the error is quite simple, it is because you are doing this:
[I0 + scalar; scalar]
Clearly the 1st row will have whatever size I0 has, the 2nd row is scalar.
Note that while using subscript indexing like this x(2,:) is semantically correct, the colon implies that there are multiple columns, which is not the case (indeed, x only has one column). It would be clearer to use linear indexing x(2) or specify the column explicitly x(2,1).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by