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

1 vue (au cours des 30 derniers jours)
Mehak S
Mehak S le 23 Fév 2022
Commenté : Mehak S le 23 Fév 2022
[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')

Réponses (1)

Alan Stevens
Alan Stevens le 23 Fév 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')

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by