Tabulating a Function with exponential values and using fprintf
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to tabulate my function. However, when I do, all my y values are zeros since my numbers are really small from the range of 10^-18 to 10^-14. My prof commented how I should use fprintf instead of disp and that fprintf statement having z(j) and y(j) as the varialbes print. How can I make a table where my table will show y-values with an exponential notation.
----------------------------------------------
%script to call Bohr_Model_RJP
%prepare for loop
npts=118;
dz = 118/(npts-1);
disp( 'z' )
n=1;
%loop
for j=1 : npts
z(j) = dz*(j-1);
y(j) = zeff(z(j),n);
disp ([ z(j), y(j) ])
end
function E = zeff(z,n)
%n-value represents an electron circular-orbit around a nucleus; the higher the n-value, the farther the orbit%;
%z-value represents the atomic number of an element, randomly generated from 0 to 118 because there are 118 elements on the periodic table;
R= 2.178*10^-18;
%R-value represents the Rydberg constant which is measured in Joules
E=-(R*z^2/n^2);
% Formula calculating the energy a nucleus exerts on an electron
%value is negative because the nucleus pulls the electron towards it.
end
0 commentaires
Réponses (1)
Stephen23
le 19 Fév 2021
Modifié(e) : Stephen23
le 19 Fév 2021
The loop is not required. By vectorizing the function you can simplify your code.
npts = 118;
n = 1;
z = linspace(0,npts,npts); % odd, but exactly the same as what you have.
y = zeff(z,n);
fprintf('%+.4e %+.4e\n',[y;z])
function E = zeff(z,n)
%n-value represents an electron circular-orbit around a nucleus; the higher the n-value, the farther the orbit%;
%z-value represents the atomic number of an element, randomly generated from 0 to 118 because there are 118 elements on the periodic table;
R = 2.178*10^-18;
%R-value represents the Rydberg constant which is measured in Joules
E = -(R*z.^2/n^2); % !!! vectorized power operation !!!
% Formula calculating the energy a nucleus exerts on an electron
%value is negative because the nucleus pulls the electron towards it.
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!