How can I normalize a function solved numerically?
显示 更早的评论
I'm trying to make the pdf of a quantum harmonic oscillator, once the equation is solved numerically, the pdf area should be 1 but instead it is 2.2604e-28. Thanks for advanced
function test(n,y0,dy0)
syms y(x)
m=9.1093821545*1e-31; k=m*(4.57*1e14)^2; w=sqrt(k/m); hb=(6.6260695729*1e-34)/(2*pi); En=hb*w*(n+.5); c1=-2*m/(hb^2); c_i0=sqrt(hb/(m*w));
[V] = odeToVectorField(diff(y,x,2) == c1*(En-.5*k*x.^2).*y);
x1=0;
x2=2e-9;
M = matlabFunction(V,'vars',{'x','Y'});
[p,q]= ode45(M,[x1 x2],[y0 dy0]);
dens=(q(:,1).*q(:,1));
% A plotear
plot([-p p],En+dens,'-k') %psi quadrat
%plot(-p,En+q(:,1),'-k') psi
hold on
%plot(p,En+q(:,1),'-k') psi
potencial=0.5*k*p.^2;
plot([-p p],potencial,'-r') %potencial
plot([-p p], ones(1,length(p))*En,'-b') %En
% natural frequency of the oscillator w = 4.57e14 Hz
hold off
grid on
u=zeros(1,length(dens));
2*trapz(p,dens) %area of the pdf
end
6 个评论
Star Strider
2017-11-30
What are typical values for ‘n’, ‘y0’, and ‘dy0’ ?
david feldstein
2017-11-30
Walter Roberson
2017-12-1
Instead of doing the trapz for dens over time, you could add another variable to the ode which is V(1).^2 . The output at the corresponding position would automatically be the integral of that value.
david feldstein
2017-12-1
Torsten
2017-12-1
Walter means that you should add the equation
dy(3)/dt = y(1)^2
to your system of ordinary differential equations, integrate numerically and afterwards normalize y(1) according to
dense=dense/q(end,3).
Best wishes
Torsten.
david feldstein
2017-12-1
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Quantum Mechanics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!