Data dimensions must agree error

조회 수: 1 (최근 30일)
Soloman Thokala
Soloman Thokala 2021년 8월 3일
답변: Walter Roberson 2021년 8월 3일
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