Using Matlab to solve 1D Schrödinger Equation (Strange Eigenfunctions)
15 次查看(过去 30 天)
显示 更早的评论
First of, here the Python Code:
% import numpy as np
%
% import matplotlib.pyplot as plt
%
% from scipy.linalg import eigh_tridiagonal
%
% N = 2000
%
% dy = 1/N
%
% y = np.linspace(0,1,N+1)
%
% def mL2V(y):
% return 1000*(y-1/2)**2
%
% d = 1/dy**2 + mL2V(y)[1:-1]
%
% e = -1/(2*dy**2) * np.ones(len(d)-1)
%
% w, v = eigh_tridiagonal(d,e)
%
% plt.plot(v.T[0])
Now my attempt converting this to Matlab:
%% Initialise
% Number of Steps
N = 100;
dy = 1/N;
y = linspace(0,1,N+1);
% Potential
V = @(y,m,L) m*L*(y-1/2).^2;
Vy = V(y,1,1);
% Differential Matrix
d = 1/dy.^2 + Vy(1:end-1);
n = length(d);
e = -1/(2*dy.^2).*ones(n,1);
A = spdiags([e d' e],[-1 0 1],n,n);
%% Solve
[v,w] = eig(full(A));
%% Plot
plot(y(1:end-1),v(:,2),'-','LineWidth',2)
axis([0 1 -1 1])
However the solutions from Matlab are totally off also comparing them with textbook-ones
How is this to explain?
___________
Background:
the goal is to solve the 1D SG:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400629/image.png)
whose solution is mainly determined by the potential V
setting
we get:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400634/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400639/image.png)
writing the derivatives in discrete form brings:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400644/image.png)
This can be written in matrix-shape:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400649/image.png)
so basically a Matrix with a main diagonal consisting of:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400654/image.png)
and two side diagonals with a constants entry of:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400659/image.png)
The initial conditions are implemented already:
respectively ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400669/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400664/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1400669/image.png)
Now the function Ψ is directly given by determing the eigenfunctions of the Matrix
_________________________________________________________________
- This is where the magic happens and where Matlab somehow finds solutions that don't suite the physics content.
2 个评论
Torsten
2023-5-31
Most probably because you didn't transfer the Python code correctly.
But since I don't have experience with Python, it would be easier if you include the mathematical description of your problem instead of code in a different computer language.
采纳的回答
更多回答(1 个)
James Tursa
2023-6-1
编辑:James Tursa
2023-6-1
Python:
return is misspelled retrun
The mL2V( ) function returns 1000*(y-1/2)**2
I don't see where y is defined prior to the line d = 1/dy**2 + mL2V(y)[1:-1]
MATLAB:
The V( ) function returns 1*1*(y-1/2).^2
I stopped looking after that. Maybe post a working Python code that we can run on the side before comparing that to MATLAB.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!