使用MATLAB ode45求解时间相关的Schrodinger方程 [英] Solving time-dependent Schrodinger equation using MATLAB ode45
问题描述
与时间有关的哈密顿量的薛定inger方程为:
The Schrodinger equation for a time-dependent Hamiltonian is:
我尝试为ode45
中的时间依赖型哈密顿量实现Schrodinger方程的求解器.但是,由于哈密顿量$ H(t)$取决于时间.我不知道如何在ode45
中进行插值.你能给我一些提示吗?
I try to implement a solver for the Schrodinger equation for a time-dependent Hamiltonian in ode45
. However, because the Hamiltonian $H(t)$ is dependent on time. I do not know how to do interpolation in ode45
. Can you give me some hints?
psi0 = [0 1];
H = [1 0;0 1]*cos(t); %this is wrong, I do not know how to implement this and pass it to ode45
hbar = 1;
t = [0:1:100];
[T, psi] = ode45(dpsi, t, psi);
function dpsi = f(t, psi, H, psi0)
dpsi = (1/i)*H*psi;
我还尝试提出一种矩阵插值的解决方案 MATLAB:涉及矩阵的插值.
I also try to come up with a solution of matrix interpolation in MATLAB: Interpolation that involve a matrix.
推荐答案
H
在您的情况下只是一个单位矩阵,因此我们可以将其与psi
向量相乘以返回psi
向量本身.然后,将i*hbar
带到方程式的右侧,以便最终方程式成为ode45
接受的形式.最后,我们使用以下代码求解psi
:
H
is just an identity matrix in your case, so we can just multiply it with the psi
vector to get back the psi
vector itself. Then, we bring i*hbar
to the right-hand-side of the equation so that the final equation is in a form that ode45
accepts. Finally, we use the following code to solve for psi
:
function schrodinger_equation
psi0 = [0;1];
hbar = 1;
t = [0 100];
[T,psi] = ode45(@(t,psi)dpsi(t,psi,hbar),t,psi0);
for i = 1:length(psi0)
figure
plot(T,real(psi(:,i)),T,imag(psi(:,i)))
xlabel('t')
ylabel('Re(\psi) or Im(\psi)')
title(['\psi_0 = ' num2str(psi0(i))])
legend('Re(\psi)','Im(\psi)','Location','best')
end
end
function rhs = dpsi(t,psi,hbar)
rhs = 1/(1i*hbar)*cos(t).*ones(2,1);
end
请注意,我分别绘制了psi
的两个分量,对于每个这样的图,我也分别绘制了实分量和虚分量.这是psi0
的两个不同值的图:
Note that I have plotted the two components of psi
separately and for each such plot, I have also plotted the real and imaginary components separately. Here are the plots for two different values of psi0
:
这篇关于使用MATLAB ode45求解时间相关的Schrodinger方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!