2016-06-23 106 views
0

薛定諤方程與時間相關的哈密頓是:解決時薛定諤方程ODE45

$$i\hbar\frac{d}{dt}\psi(t) = H(t)\psi(t) \, .$$

我嘗試實施薛定諤方程爲ode45時間哈密頓求解器。但是,因爲哈密爾頓函數$ H(t)$取決於時間。我不知道如何做插值ode45。你能給我一些提示嗎?

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: Interpolation that involve a matrix的解決方案。

回答

2

H只是您的情況下的一個單位矩陣,所以我們可以將它乘以psi向量來獲得psi向量本身。然後,我們將i*hbar帶到方程的右側,以便最終方程式的形式爲ode45接受。最後,我們用下面的代碼來解決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兩個不同的值的地塊:

enter image description here

enter image description here

+0

這是否意味着你不必做插在ODE45? $ cos(t)$術語在ode45內部有所不同嗎? – kyle

+0

'cos(t)'這個術語當然可以解釋爲你在'dpsi'函數中看到的。 – edwinksl

+0

謝謝。如果我的時間依賴性不是那麼簡單以至於'H'不能表示成一個單位矩陣?我該怎麼辦?例如'H = [t 1; 3t t^2]'? – kyle