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

1 visualización (últimos 30 días)
[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')

Respuestas (1)

Alan Stevens
Alan Stevens el 23 de Feb. de 2022
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')

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by