I am getting error, "array indices must be positive or logical integer values". Please help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
[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')
0 Kommentare
Antworten (1)
Alan Stevens
am 23 Feb. 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')
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!