Data dimensions must agree error

1 次查看(过去 30 天)
This is the program I executed and it has thrown an error that data dimensions must agree.
X dimenion: 129 129 129
y dimension: 129 129 129
q dimension: 129 129 129
u0 dimension: 129 129.
Kindly help me.
% physical constants
m =1;
omega =1;
hbar =1;
% constants defining the Gaussian IC
a =4;
b =1;
% number of grid points ( total is N+1) and the grid
N =128;
z=linspace(-10,10,N +1);
[y,x,q]= meshgrid(z,z,z);
psi = @(q)(1/sqrt(2.*b.*sqrt(pi))).*(exp(-(q - a ).^2/(2.*b^2)));
s1=exp(-1i*q.*y);
s2=conj(psi(x+q/2));
s3=psi(x-q/2);
u0=trapz(z,s1.*s2.*s3,3);
figure(1)
clf
caxis([-0.1 ,0.1])
axis([-10 10 -10 10 -0.05 0.1])
colorbar ;
surf(x,y,u0)

回答(1 个)

Walter Roberson
Walter Roberson 2021-8-3
x and y coordinates for surf() must be either vectors or 2 dimensional, never 3 dimensional.
If you have 3 independent variables and one result variable, then you cannot use surf()

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by