Using Matlab to solve 1D Schrödinger Equation (Strange Eigenfunctions)
21 次查看(过去 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:
whose solution is mainly determined by the potential V
setting we get:
writing the derivatives in discrete form brings:
This can be written in matrix-shape:
so basically a Matrix with a main diagonal consisting of:
and two side diagonals with a constants entry of:
The initial conditions are implemented already: respectively
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!