Схема кранка николсона python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Solving the one-dimensional time-dependent Schrodinger Equation for different potentials using the Crank-Nicolson method and analyzing the wavefunctions.

aychun/Crank-Nicolson-Method-for-Time-Dependent-Schrodinger-Equation

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Пока не равно питон

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Crank-Nicolsan method is used for numerically solving partial differential equations. This program implements the method to solve a one-dimensinal time-dependent Schrodinger Equation (TDSE)

and we will analyze the solutions for Infinite Sqaure Well $V(x)=0$ , Harmonic Oscillator $V(x)=\fracm\omega^2x^2$ , and Double Well $V(x)=V_0\left(\frac — 1\right)^2$

WaveFunction.py contains a WaveFunction class that has methods to initialize, solve, and calculate the expected position $< x >$ .

TDSE_constants.py and TDSE_functions.py contain required constants and helper functions for the TDSE.

TDSE_plots.py contains functions to generate plots of the real part of the wavefunction, the expected position, and an animated plot of the probability density over time.

solver.py initilizes three WaveFunctions with different potentials and solve the TDSE using the Crank-Nicolsan method. It will also save the solutions as .npz files in the same directory.

main.py loads the saved solution data files and plots $\Re (\psi(x, t))$ at $t=0, \fracT, \fracT$ , and $T$ . Then plot the expected position of each wavefunction over $t$ .

«For general systems, if the wave function is highly concentrated around a point $x_0$ , then $V’\left(\left\langle x\right\rangle \right)$ and $\left\langle V'(x)\right\rangle$ will be almost the same, since both will be approximately equal to $V'(x_)$ . In that case, the expected position and expected momentum will approximately follow the classical trajectories, at least for as long as the wave function remains localized in position»

We can observe that both $\Re(\psi(x))$ and $|\psi(x)|^2$ have centralized points, in which the amplitude is highest. This implies that we would be able to (or at least high chance of) identify the position of the particle at some given point in time, as we would be able to do in a classical trajectory. Looking at the expected position plots, we can see that the particle linearly moves towards the ’wall’ of the infinite well, then ’bounces’ off it, then linearly moves again. Before once again ’bouncing’ off the opposite ’wall’ of the infinite well.

We have a well-defined trajectory of the particle which corresponds to a trajectory of a classical particle under no external force.

Similarly, we can observe the centralized points of the wavefunction and the probability density. The expected position also mimics the behaviour of a classical particle on a string.

Unlike the previous parts, it is really hard to identify the centralized point of the wavefunction. This is not something that we would expect from a classical particle and the plot of the expected position also illustrate its special (quantum mechanical) behaviour. The trajectory doesn’t follow any particular motion and doesn’t resemble any classical trajectory.

About

Solving the one-dimensional time-dependent Schrodinger Equation for different potentials using the Crank-Nicolson method and analyzing the wavefunctions.

Источник

The Crank-Nicolson method combined with Runge-Kutta implemented from scratch in Python

In this article we implement the well-known finite difference method Crank-Nicolson in combination with a Runge-Kutta solver in Python.

Combining Crank-Nicolson and Runge-Kutta to Solve a Reaction-Diffusion System

We have already derived the Crank-Nicolson method to integrate the following reaction-diffusion system numerically:

Please refer to the earlier blog post for details.

In our previous derivation, we constructed the following stencil that we would go on to rearrange into a system of linear equations that we needed to solve every time step:

where $j$ and $n$ are space and time grid points respectively.

Rearranging the above set of equations, we effectively integrate the reaction part with the explicit Euler method like so:

For functions $f$ that change rapidly for small changes in their input (stiff equations), using the explicit Euler method may pose stability problems unless we choose a sufficiently small $\Delta t$.

Therefore, I have been wondering if it would be possible to use a more sophisticated and stable numerical scheme to integrate the reaction part in the context of our Crank-Nicolson scheme.

For instance, to integrate the reaction part with the classical Runge-Kutta method, we would write out the following set of equations instead of the aforementioned one:

$$\frac — U_j^n> = \frac \left( U_^n — 2 U_j^n + U_^n + U_^ — 2 U_j^ + U_^\right) + \frac \left(k_1 + 2 k_2 + 2 k_3 + k_4 \right),$$

$$k_2 = f\left( U_j^n + \frac k_1 \right),$$

$$k_3 = f\left( U_j^n + \frac k_2 \right),$$

$$k_4 = f\left( U_j^n + \Delta t k_3 \right).$$

Whether or not doing this makes sense theoretically I am not certain. But going ahead and implementing this to the numerical example we discussed earlier seems to suggest that this does work.

In the following Python code that is mostly a copy of our previous code we compare the time behaviour and accuracy (measured by mass conservation as our reaction diffusion system preserves mass) of the explicit Euler and Runge-Kutta 4 reaction integration.

We realize that the differences between the obtained numerical results are negligible and we shall compare both approaches with a stiffer reaction term another time.

We shall also take a look at more sophisticated measures of numerical stability another time.

%matplotlib inline import numpy from matplotlib import pyplot 

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Heat Equation: Crank-Nicolson / Explicit Methods, designed to estimate the solution to the heat equation. Python, using 3D plotting result in matplotlib.

glider4/Crank_Nicolson_Explicit

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Heat Equation: Crank-Nicolson / Explicit Methods, designed to estimate the solution to a 1D heat equation problem. Coding: Python (Anaconda / Spyder) via NumPy, plotting: matplotlib.

Together_Crank_Explicit

3DPlotExact

About

Heat Equation: Crank-Nicolson / Explicit Methods, designed to estimate the solution to the heat equation. Python, using 3D plotting result in matplotlib.

Источник

Оцените статью