Why does the order of calculation change the result?

1 次查看(过去 30 天)
Dear all,
I have a simple calculation ending with plotting. But i have problem to get the result.
I need to do calculation in the order of 1E-9 but when i do, i get the plot in the first picture, which is wrong.
But when i do calculation in the order of 1E+1, result is as i want but then i can not use the result for the further calculation.
I could not figure out the problem.
What is wrong?
%%%%%%%%%%%%%%%%%%%%%%%%% This give wrong plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ltot=2E-9; % toplam kuyu kalınlığı
dz = 1E-11;
z=-Ltot/2:dz:Ltot/2;
Mass = 0.07;
m0 = 9.1E-31
e=1.602176487E-19;
eps_statik = 12.4;
h=6.62606896E-34; %% Planck constant [J.s]
% h = 4.135e-15;
hbar=h/2/pi;
Ndl = 3E+16; Ndr = 5E+16; %%% [1/m2] cinsinden
Ip = 0.6e-9;
alfa = e^2*(Mass*m0)^1.5;
alfa = alfa / (15 * pi * eps_statik * hbar^3)
zol = 2 .* eps_statik.^2 .* alfa.^3;
zol = (zol ./ (pi .* e.^2 .* Ndl)).^0.2;
zor = 2 .* eps_statik.^2 .* alfa.^3;
zor = (zor ./ (pi .* e.^2 .* Ndr)).^0.2;
V0 = (-1 .* alfa^2 ./ (alfa .* abs(z-Ip) + zor).^4 - alfa^2 ./ (alfa .* abs(z+Ip) + zol).^4)/e;
plot(V0)
%%%%%%%%%%%%%%%%%%%%%%%%% This is as i want %%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ltot=2; % toplam kuyu kalınlığı
dz = 0.01;
z=-Ltot/2:dz:Ltot/2;
e=1.602176487E-19;
eps_statik = 12.4;
h=6.62606896E-34; %% Planck constant [J.s]
% h = 4.135e-15;
hbar=h/2/pi;
Ndl = 3E+16; Ndr = 5E+16; %%% [1/m2] cinsinden
Ip = 0.6;
alfa = e^2*(Mass*m0)^1.5;
alfa = alfa / (15 * pi * eps_statik * hbar^3)
zol = 2 .* eps_statik.^2 .* alfa.^3;
zol = (zol ./ (pi .* e.^2 .* Ndl)).^0.2;
zor = 2 .* eps_statik.^2 .* alfa.^3;
zor = (zor ./ (pi .* e.^2 .* Ndr)).^0.2;
V0 = (-1 .* alfa^2 ./ (alfa .* abs(z-Ip) + zor).^4 - alfa^2 ./ (alfa .* abs(z+Ip) + zol).^4)/e;
plot(V0)

回答(2 个)

Cameron
Cameron 2023-1-14
It looks like the main differences between the two are Ltot, dz, and Ip. The variable Ip is especially weird. Which of these were you trying to do?
Ip = 0.6;
Ip = 0.6*e^-9;
Ip = 0.6E-9;
%or something else

Walter Roberson
Walter Roberson 2023-1-14
%missing variables
syms Mass m0
%rest of code
syms scale positive
Pi = sym(pi);
Q = @(v) sym(v);
dz = scale/100;
Ltot = 2 * scale; % toplam kuyu kalınlığı
z = -Ltot/2:dz:Ltot/2;
e = Q(1602176487) * Q(10)^(-28);
eps_statik = Q(124)/Q(10);
h = Q(662606896) * Q(10)^(-42); %% Planck constant [J.s]
hbar = h/2/Pi;
Ndl = Q(3)*Q(10)^(16);
Ndr = Q(5)*Q(10)^(16);; %%% [1/m2] cinsinden
Ip = Q(6)/Q(10) * scale
Ip = 
alfa = e^2*(Mass*m0)^Q(1.5);
alfa = alfa / (15 * Pi * eps_statik * hbar^3)
alfa = 
zol = 2 .* eps_statik.^2 .* alfa.^3;
zol = (zol ./ (pi .* e.^2 .* Ndl)).^0.2;
zor = 2 .* eps_statik.^2 .* alfa.^3;
zor = (zor ./ (pi .* e.^2 .* Ndr)).^0.2;
V0 = (-1 .* alfa^2 ./ (alfa .* abs(z-Ip) + zor).^4 - alfa^2 ./ (alfa .* abs(z+Ip) + zol).^4)/e;
V0(1:3).'
ans = 
Tracing that backwards: and and are indepedent of scale, so and are independent of scale -- all of the are independent of scale.
So in V0(1) the numerator is independent of scale. In the denominator, in each of the two terms, the leading numeric factor 48477...41 is independent of scale.. In each of the two terms with the second being subtracted from the first, the structure is a σ variable being added to a numeric value times scale times times a σ variable. But we have established that the σ variables are independent of scale, so the terms are CONSTANT1 + CONSTANT2*scale . The result is, of course, going to depend upon the scale.
We have demonstrated that with those equations the results are going to depend upon the scale.
  2 个评论
Walter Roberson
Walter Roberson 2023-1-14
Note that if you change only Ltot or only Ip to be independent of scale then the resulting V0 would still involve scale in much the same way (with differences in the exact numeric factors generated.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by