Plotting a 3d hydrogen atomic orbital plot from a data file
5 Commenti
Hi Rasheed,
I do apologize since I was exhausted on working on a large scale software project. Thanks for noticing, there was a missing line in my code which was multiplying the wavefunction values with the corresponding spherical harmonic functions of 3dz^2. However, in this modified code, I fixed it.
To answer your question in the post, to create a 3D plot in Cartesian coordinates using your given dataset, you need to convert the radial coordinates 'r' to Cartesian coordinates (x, y, z) and then multiply the wavefunction values with the corresponding spherical harmonic functions of 3dz^2. Then, extract the radial coordinates 'r' and wavefunction values from the dataset into separate variables r and wavefunction. Next, convert the radial coordinates to Cartesian coordinates using the formulas x = r * sin(r), y = r * cos(r), and z = r. After that, multiply the wavefunction values with the corresponding spherical harmonic functions of 3dz^2 to obtain the wavefunction_cartesian values. Finally, create a 3D scatter plot using the scatter3 function, where the x, y, and z coordinates represent the Cartesian coordinates, and the wavefunction_cartesian values will determine the color of each point. I added a colorbar to the plot to indicate the color scale. The xlabel, ylabel, and zlabel functions are used to label the axes, and the title function sets the title of the plot. I also adjusted the plot settings using axis equal to ensure equal scaling on all axes and view to set the viewing angle for better visualization. Now, by running this code in MATLAB, you should obtain a 3D plot of the wavefunction in Cartesian coordinates, where the color represents the magnitude of the wavefunction. Here is the snippet code,
% Load the dataset
data = [0.00 0.000000 0.45 0.000627 0.90 0.002467 1.35 0.005404 1.80 0.009263 2.25 0.013828 2.70 0.018859 3.15 0.024107 3.60 0.029329 4.05 0.034296 4.50 0.038798 4.95 0.042653 5.40 0.045707 5.85 0.047850 6.30 0.049018 6.75 0.049205 7.20 0.048467 7.65 0.046926 8.10 0.044759 8.55 0.042183 9.00 0.039422 9.45 0.036660 9.90 0.033972 10.35 0.031248 10.80 0.028078 11.25 0.023511 11.70 0.016026 12.15 0.005061 12.60 -0.006867 13.05 -0.014665 13.50 -0.014647 13.95 -0.007211 14.40 0.003441 14.85 0.011842 15.30 0.015687 15.75 0.016839 16.20 0.016349 16.65 0.014982 17.10 0.013238 17.55 0.011416 18.00 0.009680 18.45 0.008110 18.90 0.006736 19.35 0.005560 19.80 0.004567];
% Extract the radial coordinates 'r' and wavefunction values
r = data(:, 1);
wavefunction = data(:, 2);
% Convert radial coordinates to Cartesian coordinates
x = r .* sin(r);
y = r .* cos(r);
z = r;
% Multiply wavefunction values with the corresponding spherical harmonic
functions of 3dz^2
modified_wavefunction = wavefunction .* (3 * z.^2);
% Create a 3D plot
figure;
scatter3(x, y, z, 50, modified_wavefunction, 'filled');
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
title('3D Plot of wavefunction(x, y, z)');
% Adjust the plot settings for better visualization
axis equal;
view(45, 30);
Please see attached snippet code and plot.

I hope this will make you happy now. Please let me know if you have further questions.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


