0% found this document useful (0 votes)
34 views5 pages

Code Particle in An Infinite Potential Well'

This code uses finite difference methods to plot and analyze the wavefunctions for a particle in a 1D infinite potential well. It defines constants, creates matrices for the kinetic energy and potential energy, calculates the Hamiltonian matrix, finds its eigenvalues and eigenvectors, and plots the eigenfunctions and probability densities for the first five energy levels.

Uploaded by

Lovely Chetan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

Code Particle in An Infinite Potential Well'

This code uses finite difference methods to plot and analyze the wavefunctions for a particle in a 1D infinite potential well. It defines constants, creates matrices for the kinetic energy and potential energy, calculates the Hamiltonian matrix, finds its eigenvalues and eigenvectors, and plots the eigenfunctions and probability densities for the first five energy levels.

Uploaded by

Lovely Chetan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A code in Scilab to plot and analyse the wavefunctions for particle in an infinite potential

well.

// Clearing the workspace


clear;
clc;

// Constants
m = 9.1e-31; // mass of electron
hplanck = 6.63e-34; // value of Planck's constant
hbar = hplanck / (2 * %pi); // value of hbar
hbarsqbytwo_m_term = (hbar ^ 2) / (2 * m); // value of hbar square by 2*m
eV = 1.6e-19; // value of electron volt in SI units
MeV = (1e+6) * eV; // Mega electron volt
Angst = 1e-10; // Value of one angstrom
x_min = 0;
x_max = 1 * Angst;
disp('The box size is (in meters):');
disp(x_max);

// Input the number of intervals


N = input('Input the number of intervals (should be around 500 to 750 for good computation): ');

A = (x_max - x_min); // width of 1D box


s = (x_max - x_min) / N; // step size
fac = -hbarsqbytwo_m_term / (s ^ 2); // factor (hbar^2/2m) divided by h^2

// making a row vector to input x values


X = zeros(1, N);
for i = 1:1:N
X(i) = x_min + (i - 1) * s;
end

// Kinetic energy matrix (Using central difference formula)


T = zeros(N, N);
for i = 1:1:N
T(i, i) = -2;
if (i < N)
T(i, i + 1) = 1;
T(i + 1, i) = 1;
end
end
T_matrix = fac * T / eV; // Kinetic Energy Matrix in eV

// Potential energy matrix


U_matrix = zeros(N, N);
for i = 1:1:N
U_matrix(i, i) = 0;
end
Dr. Chetan Chavan, Assistant Professor, Dept. of Physics, Kottureshwara College, Kottur
// Hamiltonian Matrix H=U+T
H_matrix = T_matrix + U_matrix;

[u, eigen] = spec(H_matrix);


eigval_numeric = spec(H_matrix);

// Normalization check
Normalization = sum((u(:, 1) .* conj(u(:, 1))));

// By theoretically achieved formulae


for n = 1:1:5
eigval_theory = (n^2 * %pi^2 * hbar^2) / (2 * m * A^2); // in SI units
eigval_th_eV(n) = eigval_theory / eV; // in eV
end

disp('The Eigen (eV) values obtained from finite difference method are:');
disp(eigval_numeric(1:5));
disp('The Eigen (eV) obtained from Analytic Formula are:');
disp(eigval_th_eV(1:5));

// Plotting the eigen values


figure;
for n = 1:1:5
temp1 = eigval_numeric(n);
eigval_numeric_vector = temp1 * ones(1, N);
plot(X / Angst, eigval_numeric_vector, 'r------------', 'linewidth', 2);
xlabel('x (in angstrom units)', 'fontsize', 3);
ylabel('Eigenvalue (eV)', 'fontsize', 3);
title('Eigenvalues for first 5 Eigen Functions', 'fontsize', 3);
end

// Plotting the probability functions (plot of mod psi squared)


figure;
for in = 1:1:5
psisq(:, in) = (u(:, in) .* conj(u(:, in)));
end
subplot(5, 1, 1);
title('First five probability density functions', 'fontsize', 3);
plot(X / Angst, psisq(:, 1)', 'r', 'linewidth', 2);
subplot(5, 1, 2);
plot(X / Angst, psisq(:, 2)', 'r', 'linewidth', 2);
subplot(5, 1, 3);
plot(X / Angst, psisq(:, 3)', 'r', 'linewidth', 2);
ylabel('Probability density', 'fontsize', 3);
subplot(5, 1, 4);
plot(X / Angst, psisq(:, 4)', 'r', 'linewidth', 2);
subplot(5, 1, 5);
plot(X / Angst, psisq(:, 5)', 'r', 'linewidth', 2);
xlabel('x (in angstrom units)', 'fontsize', 3);

Dr. Chetan Chavan, Assistant Professor, Dept. of Physics, Kottureshwara College, Kottur
Figure 5.1: 1D Box potential

Dr. Chetan Chavan, Assistant Professor, Dept. of Physics, Kottureshwara College, Kottur
Figure 5.2: 1D Box potential

Dr. Chetan Chavan, Assistant Professor, Dept. of Physics, Kottureshwara College, Kottur
Figure 5.3: 1D Box potential

Dr. Chetan Chavan, Assistant Professor, Dept. of Physics, Kottureshwara College, Kottur

You might also like