I am getting error, "array indices must be positive or logical integer values". Please help

1 次查看(过去 30 天)
[X,Y] = meshgrid(-4:0.2:4);
n=2;
k=1;
%n=1, k=1
w1=-sqrt(k.^2+2*n+1);
w2=sqrt(k.^2+2*n+1);
w3=k./(k.^2+2*n+1);
phi_func = @(n,Y) exp(-0.5*Y.^2).*hermiteH(n,Y);
phi_x=exp(1i*k.*X);
v=1i*(w1.^2-k.^2).*phi_func(n,Y).*phi_x;
u=(0.5*(w1-k).*phi_func(n+1,Y)+n(w1+k).*phi_func(n-1,Y)).*phi_x;
z=(0.5*(w1-k).*phi_func(n+1,Y)-n(w1+k).*phi_func(n-1,Y)).*phi_x;
U=real(u);
V=real(v);
Z=real(z)
contour(X,Y,Z,10)
colorbar
hold on
quiver(X,Y,U,V,'r')

回答(1 个)

Alan Stevens
Alan Stevens 2022-2-23
You need multiplication signs between n and (w1+k) in calculations of u and z:
[X,Y] = meshgrid(-4:0.2:4);
n=2;
k=1;
%n=1, k=1
w1=-sqrt(k.^2+2*n+1);
w2=sqrt(k.^2+2*n+1);
w3=k./(k.^2+2*n+1);
phi_func = @(n,Y) exp(-0.5*Y.^2).*hermiteH(n,Y);
phi_x=exp(1i*k.*X);
v=1i*(w1.^2-k.^2).*phi_func(n,Y).*phi_x;
u=(0.5*(w1-k).*phi_func(n+1,Y)+n*(w1+k).*phi_func(n-1,Y)).*phi_x;
z=(0.5*(w1-k).*phi_func(n+1,Y)-n*(w1+k).*phi_func(n-1,Y)).*phi_x;
U=real(u);
V=real(v);
Z=real(z);
contour(X,Y,Z,10)
colorbar
hold on
quiver(X,Y,U,V,'r')

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by