MATLAB Answers

scatter3 error i not understand

13 ビュー (過去 30 日間)
Severin Handelshauser
Severin Handelshauser 2020 年 1 月 18 日
コメント済み: John D'Errico 2020 年 1 月 18 日
I want to draw the hydrogen orbitals with the 3D-scatter-diagram. The probability density P should determine the size of the points. But I get the error-message
Error using scatter3scatter3 (line 135)
Error setting property 'SizeData' of class 'Scatter':
Value must be a vector of positive numeric type or nan
Error in HydrogenEigen2 (line 885)
scatter3(X,Y,Z,P)
And my X, Y, Z and my P are double-type vectors. What I do wrong?
% quantum numbers
n = 3;
l = 1; % 0 <= l < n
m = 0; % -l <= m <= l
a = 1; % Bohr radius
%Grid
[x,y,z] = meshgrid(-15*a:a:15*a, -15*a:a:15*a, -15*a:a:15*a);
%Grid Spherical coordinates
r=sqrt(x.^2+y.^2+z.^2);
theta=acot(z./(sqrt(x.^2+y.^2)));
phi=atan2(y,x);
%Spherical Harmonics
b1 = (2*l+1)*factorial(l-m);
b2 = 4*pi*factorial(l+m);
b3 = sqrt(b1/b2);
Pl = legendre(l,cos(theta));
%Plm =reshape(Pl(m+1,:,:,:),size(phi));
Plm=squeeze(Pl(m+1,:,:,:));
V= b3 .* Plm .* exp(1i*m*phi);
%Radial Part
R =sqrt((2 / (a * n))^3 * factorial(n-l-1) / (2 * n * factorial(n + l))).*exp(-r / (a * n)) .* (2 * r / (a * n)).^l * 1 / factorial(n-l-1 + 2 * l + 1).*laguerreL(n-l-1, 2 * l + 1, 2 * r / (a * n));
%Ges
Phi=R.*V;
p=Phi.*conj(Phi);
%Plot preparation
Nx=size(x);
Ny=size(y);
Nz=size(z);
X=[];
for k=1:(Nz(1));
for i=1:(Ny(1));
X=[X;x(:,i,k)];
end
end
X=squeeze(X(:,1));
Y=[];
for k=1:(Nz(1));
for i=1:(Ny(1));
Y=[Y;y(:,i,k)];
end
end
Y=squeeze(Y(:,1));
Z=[];
for k=1:(Nz(1));
for i=1:(Ny(1));
Z=[Z;z(:,i,k)];
end
end
Z=squeeze(Z(:,1));
P=[];
for k=1:(Nz(1));
for i=1:(Ny(1));
P=[P;p(:,i,k)];
end
end
P=squeeze(P(:,1));
X=(X.');
Y=(Y.');
Z=(Z.');
P=((P.')/1.85*1e8);
%Plot
scatter3(X,Y,Z,P)

  0 件のコメント

サインイン to comment.

回答 (1 件)

John D'Errico
John D'Errico 2020 年 1 月 18 日
編集済み: John D'Errico 2020 年 1 月 18 日
Hmm. It took me a minute to see what the answer was from the error that was generated.
scatter3(X,Y,Z,P)
Error using scatter3 (line 135)
Error setting property 'SizeData' of class 'Scatter':
Value must be a vector of positive numeric type or nan
This line confused me at first.
Error setting property 'SizeData' of class 'Scatter':
But next, I checked to see if your data was perhaps complex. No. But then, I looked at your data more closely.
min(P)
ans =
0
Now read the eror message.
Value must be a vector of positive numeric type or nan
so...
find(P == 0)
ans =
Columns 1 through 12
9130 10926 10930 10986 10994 11110 11118 11174 11178 12846 12854 13094
Columns 13 through 24
13102 14710 14890 14896 14902 15082 16690 16698 16938 16946 18614 18618
Columns 25 through 31
18674 18682 18798 18806 18862 18866 20662
There are 31 elements in P that are exactly zero.
Then I tried:
scatter3(X,Y,Z,max(P,1.e-15))
As is often the case, the answer is found in the error message, if we read the error message carefully. Not like the "good" old days, when an error message was written in code, that could only be deciphered by consulting a manual that listed all possible error codes, and even then the document often did not explain what the real problem was or how to fix it. ;-)

  2 件のコメント

Severin Handelshauser
Severin Handelshauser 2020 年 1 月 18 日
Ok, the size must be bigger than 0. = 0 does not work either. Thank you very much
John D'Errico
John D'Errico 2020 年 1 月 18 日
"0." typivally means in MATLAB that the number was only zero to within a tolerance.
format long
X = [0 1.e-20 1.e-16 1.e-15 .1 1 10]
X =
0 0.000000000000000 0.000000000000000 0.000000000000001 0.100000000000000 1.000000000000000 10.000000000000000
As you can see only the first case do we have an explicit true zero. The others are just small numbers.
Feel free to accept this answer if it answered your question.

サインイン to comment.

サインイン してこの質問に回答します。


Translated by