Pyslise

These two classes are able to solve the one dimensional time independent Schrödinger equation. The first one (Pyslise) solves the general case. The second class (PysliseHalf) implements half range reduction, for this it assumes the problem is symmetric.

class pyslise.Pyslise

>>> from math import pi, cos >>> p = Pyslise(lambda x: 2*cos(2*x), 0, pi, 1e-8) >>> i, E = p.eigenvaluesByIndex(0, 1, (0,1))[0] >>> abs(E - -0.1102488054219) < 1e-6 True

__init__(self: pyslise.Pyslise, V: Callable[[float], float], min: float, max: float, tolerance: float = 1e-08) → None

In the __init__ function all needed data will be precomputed to effectively solve the Schrödinger equation with given potential on the interval [min; max]. Because of the precomputation the function V is only evaluated at the moment of initalisation. Calling other methods after the object is created never will evaluate V.

Note: only one of steps and tolerance have to be set.

Parameters
  • V ((float)->float) – the potential.

  • min, max (float) – the ends of the domain.

  • steps (int) – the number of steps to take.

  • tolerance (int) – automatically choose steps with at least the given accuracy.

property domain
eigenfunction(self: pyslise.AbstractPyslise, E: float, xs: numpy.ndarray[float64[m, 1]], left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → Tuple[numpy.ndarray[float64[m, 1]], numpy.ndarray[float64[m, 1]]]

Calculate the eigenfunction corresponding to the eigenvalue E in the points xs.

Parameters
  • E (float) – the eigenvalue.

  • left, right ((float,float)) – the boundary conditions.

  • xs – the points to calculate the eigenfunction for.

Returns

a pair of lists which each a length of len(xs). The first list contains the values of the eigenfunction in the points xs. The second contains the derivative of the eigenfunction in those points.

eigenfunctionCalculator(self: pyslise.AbstractPyslise, E: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → Callable[[float], Tuple[float, float]]

Returns the eigenfunction corresponding to the eigenvalue E as a python function. The returned function can be evaluated in all the points in the domain.

Parameters
  • E (float) – the eigenvalue.

  • left, [right] ((float,float)) – the boundary conditions.

  • [index] (int) – the index of the eigenvalue

Returns

a function that takes a value and returns a tuple with the eigenfunction and derivative in that value.

eigenvalueError(self: pyslise.AbstractPyslise, E: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → float

Calculate the error for a given eigenvalue. It will use a less accurate method to estimate another (worse) guess for that eigenvalue. The true error on the given eigenvalue will be less than the value returned by this method.

Parameters
  • E (float) – the eigenvalue to calculate the error for.

  • left, right ((float,float)) – the boundary conditions.

Returns

the error.

eigenvalues(self: pyslise.AbstractPyslise, Emin: float, Emax: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None) → List[Tuple[int, float]]

Calculate the eigenvalues in an interval [Emin; Emax]. The boundary conditions have to be specified.

Parameters
  • Emin, Emax (float) – the ends of the search interval.

  • left, right ((float,float)) – the boundary conditions. The corresponding eigenfunctions will have as left value a scaling of left[0] and derivative left[1].

Returns

a list of tuples. Each tuples contains the index and the eigenvalue with that index.

eigenvaluesByIndex(self: pyslise.AbstractPyslise, Imin: int, Imax: int, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None) → List[Tuple[int, float]]

Calculate all eigenvalues with index between Imin and Imax. The first eigenvalue has index 0. Imin inclusive, Imax exclusive.

Parameters
  • Imin (int) – the first eigenvalue to find, by index.

  • Imax (int) – only the first Imax eigenvalues will be considered.

  • left, right ((float,float)) – the boundary conditions.

Returns

a list of tuples. Each tuples contains the index and the eigenvalue with that index.

propagate(*args, **kwargs)

Overloaded function.

  1. propagate(self: pyslise.Pyslise, E: float, y: numpy.ndarray[float64[2, 1]], a: float, b: float) -> Tuple[numpy.ndarray[float64[2, 1]], float]

For a given E and initial condition in point a, propagate the solution of the Schrödinger equation to the point b.

Parameters
  • E (float) – the fixed eigenvalue to use. This value doesn’t have to be a true eigenvalue.

  • y ((float,float)) – the initial condition in point a.

  • a (float) – the start of the propagation.

  • b (float) – the point in which the solution is sought.

Returns

a tuple of length two. The first element is a tuple with the value and the derivative in the point b. The second element is the angle found by the Prüfer transformation.

  1. propagate(self: pyslise.Pyslise, E: float, y: numpy.ndarray[float64[2, 1]], dy: numpy.ndarray[float64[2, 1]], a: float, b: float) -> Tuple[numpy.ndarray[float64[2, 1]], numpy.ndarray[float64[2, 1]], float]

For a given E and initial condition in point a, propagate the solution of the Schrödinger equation to the point b. In this method the derivative with respect to E is also calculated.

Parameters
  • E (float) – the fixed eigenvalue to use. This value doesn’t have to be a true eigenvalue.

  • y ((float,float)) – the initial condition in point a.

  • dy ((float,float)) – the initial condition derived to E in point a.

  • a (float) – the start of the propagation.

  • b (float) – the point in which the solution is sought.

Returns

a tuple of length three. The first element is a tuple with the value and the derivative in the point b. The second element contains the derivative to E of the first element. The third element is the angle found by the Prüfer transformation.

Half range reduction can be applied when the problem is symmetric. This symmetry has following requirements:

  • The potential is even: V(x) = V(-x). (The potential will only be evaluated on the positive part of the domain.)

  • The domain is symmetric around zero: [-max; max].

  • The boundary conditions are symmetric left and right.

class pyslise.PysliseHalf
__init__(self: pyslise.PysliseHalf, V: Callable[[float], float], xmax: float, tolerance: float = 1e-08) → None

In the __init__ function all needed data will be precomputed to effectively solve the Schrödinger equation with given potential on the interval [min; max]. Because of the precomputation the function V is only evaluated at the moment of initalisation. Calling other methods after the object is created never will evaluate V.

Note: only one of steps and tolerance have to be set.

Parameters
  • V ((float)->float) – the potential.

  • min, max (float) – the ends of the domain.

  • steps (int) – the number of steps to take.

  • tolerance (int) – automatically choose steps with at least the given accuracy.

property domain
eigenfunction(self: pyslise.AbstractPyslise, E: float, xs: numpy.ndarray[float64[m, 1]], left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → Tuple[numpy.ndarray[float64[m, 1]], numpy.ndarray[float64[m, 1]]]

Calculate the eigenfunction corresponding to the eigenvalue E in the points xs.

Parameters
  • E (float) – the eigenvalue.

  • left, right ((float,float)) – the boundary conditions.

  • xs – the points to calculate the eigenfunction for.

Returns

a pair of lists which each a length of len(xs). The first list contains the values of the eigenfunction in the points xs. The second contains the derivative of the eigenfunction in those points.

eigenfunctionCalculator(self: pyslise.AbstractPyslise, E: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → Callable[[float], Tuple[float, float]]

Returns the eigenfunction corresponding to the eigenvalue E as a python function. The returned function can be evaluated in all the points in the domain.

Parameters
  • E (float) – the eigenvalue.

  • left, [right] ((float,float)) – the boundary conditions.

  • [index] (int) – the index of the eigenvalue

Returns

a function that takes a value and returns a tuple with the eigenfunction and derivative in that value.

eigenvalueError(self: pyslise.AbstractPyslise, E: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None, index: int = - 1) → float

Calculate the error for a given eigenvalue. It will use a less accurate method to estimate another (worse) guess for that eigenvalue. The true error on the given eigenvalue will be less than the value returned by this method.

Parameters
  • E (float) – the eigenvalue to calculate the error for.

  • left, right ((float,float)) – the boundary conditions.

Returns

the error.

eigenvalues(self: pyslise.AbstractPyslise, Emin: float, Emax: float, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None) → List[Tuple[int, float]]

Calculate the eigenvalues in an interval [Emin; Emax]. The boundary conditions have to be specified.

Parameters
  • Emin, Emax (float) – the ends of the search interval.

  • left, right ((float,float)) – the boundary conditions. The corresponding eigenfunctions will have as left value a scaling of left[0] and derivative left[1].

Returns

a list of tuples. Each tuples contains the index and the eigenvalue with that index.

eigenvaluesByIndex(self: pyslise.AbstractPyslise, Imin: int, Imax: int, left: numpy.ndarray[float64[2, 1]], right: Optional[numpy.ndarray[float64[2, 1]]] = None) → List[Tuple[int, float]]

Calculate all eigenvalues with index between Imin and Imax. The first eigenvalue has index 0. Imin inclusive, Imax exclusive.

Parameters
  • Imin (int) – the first eigenvalue to find, by index.

  • Imax (int) – only the first Imax eigenvalues will be considered.

  • left, right ((float,float)) – the boundary conditions.

Returns

a list of tuples. Each tuples contains the index and the eigenvalue with that index.