0% found this document useful (0 votes)
13 views12 pages

Biswas49 HW3

The document describes a computational approach to solving the Schrödinger equation using the shooting method to find the lowest eigenvalue and variational methods to minimize energy. It includes code for defining the differential equation, solving it, and plotting results for different epsilon values, as well as comparing variational results with numerical ones. Key findings include an optimal alpha value of approximately 0.500 and a percentage difference of 15.76% between variational and numerical energy results.

Uploaded by

fdgwre
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)
13 views12 pages

Biswas49 HW3

The document describes a computational approach to solving the Schrödinger equation using the shooting method to find the lowest eigenvalue and variational methods to minimize energy. It includes code for defining the differential equation, solving it, and plotting results for different epsilon values, as well as comparing variational results with numerical ones. Key findings include an optimal alpha value of approximately 0.500 and a percentage difference of 15.76% between variational and numerical energy results.

Uploaded by

fdgwre
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/ 12

In [15]: #Problem 3b

import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt

# Define the differential equation as a system of first-order ODEs


def schrodinger_system(z, y, epsilon):
psi, dpsi = y
return [dpsi, - (epsilon - z**4) * psi]

# Function to solve the ODE and check boundary condition at z_max


def shoot(epsilon, z_min=0.0, z_max=10.0, max_step=0.01):
y0 = [1.0, 0.0] # psi(0) = 1, psi'(0) = 0
sol = solve_ivp(schrodinger_system, [z_min, z_max], y0, args=(epsilon,),
dense_output=True, max_step=max_step)
z_vals = np.linspace(z_min, z_max, 1000)
psi_z = sol.sol(z_vals)[0]
return psi_z[-1], psi_z, z_vals # Return final value, psi, and z for plotting

# Find the lowest eigenvalue using the shooting method


def find_lowest_eigenvalue(epsilon_range=[0, 5], z_max=5.0):
epsilon_vals = np.linspace(epsilon_range[0], epsilon_range[1], 100)
for i in range(len(epsilon_vals) - 1):
e1, e2 = epsilon_vals[i], epsilon_vals[i + 1]
final1, _, _ = shoot(e1, z_max=z_max)
final2, _, _ = shoot(e2, z_max=z_max)
if final1 * final2 < 0: # Sign change indicates an eigenvalue
from scipy.optimize import brentq
epsilon = brentq(lambda e: shoot(e, z_max=z_max)[0], e1, e2)
print(f"Lowest eigenvalue (epsilon) found: {epsilon:.6f}")
return epsilon
raise ValueError(f"No eigenvalue found in range {epsilon_range}")

# Main execution
z_max = 5 # Increased to better capture decay
epsilon_guesses = [1, 5, 10, 20, 50, 100] # Initial guesses for plotting
solutions = []

# Find the lowest eigenvalue


try:
epsilon_lowest = find_lowest_eigenvalue(z_max=z_max)
epsilon_guesses.insert(0, epsilon_lowest) # Add lowest eigenvalue to guesses
except ValueError as e:
print(e)

# Solve for all epsilon values


for epsilon in epsilon_guesses:
sol = shoot(epsilon, z_max=z_max)
solutions.append(sol)

# Plot
plt.figure(figsize=(9, 6))
z_vals = np.linspace(0, z_max, 1000) # Define z_vals here
for i, (final_val, psi_z, z) in enumerate(solutions):
plt.plot(z, psi_z, label=f'Epsilon = {epsilon_guesses[i]:.2f} (final psi = {final_val:.2e})')
plt.title('Wavefunction Solutions for Different Epsilon Values')
plt.xlabel('z')
plt.ylabel('Psi(z)')
plt.legend()
plt.grid()
plt.show()

Lowest eigenvalue (epsilon) found: 1.060362

In [16]: # Problem 3c
import numpy as np
from scipy.optimize import minimize_scalar
import matplotlib.pyplot as plt

# Define physical constants (consistent with previous parts)


hbar = 1.0
m = 1.0
lambda_ = 1.0 # Coefficient of the x^4 potential

# Define the energy expectation value


def energy_alpha(alpha):
if alpha <= 0: # Ensure alpha is positive
return float('inf')
kinetic = (3 * hbar**2 * alpha) / (4 * m) # Kinetic energy term
potential = (3 * lambda_) / (64 * alpha**2) # Potential energy term
return kinetic + potential

# Step 1: Minimize E(alpha) with respect to alpha


result = minimize_scalar(energy_alpha, bounds=(0.1, 1.0), method='bounded')
alpha_opt = result.x # Optimal alpha
E_min = result.fun # Minimum energy

print(f"Optimal alpha: {alpha_opt:.6f}")


print(f"Variational minimum E(alpha): {E_min:.6f}")

# Step 2: Compare with the numerical result from part (b)


# From part (b), epsilon ≈ 1.060

alpha_rescale = (2 * m * lambda_ / hbar**2)**(1/6)


epsilon = 1.060
E_numerical = (epsilon * alpha_rescale**2) / (2 * m / hbar**2)
print(f"Alpha from rescaling (part a): {alpha_rescale:.6f}")
print(f"Numerical E from part (b): {E_numerical:.6f}")

# Compute the percentage difference


percent_diff = abs(E_min - E_numerical) / E_numerical * 100
print(f"Percentage difference between variational and numerical E: {percent_diff:.2f}%")

# Step 3: Plot E(alpha) to visualize the minimum


alpha_vals = np.linspace(0.1, 2, 100)
E_vals = [energy_alpha(alpha) for alpha in alpha_vals]

plt.figure(figsize=(8, 6))
plt.plot(alpha_vals, E_vals, label='E(α)', color='blue')
plt.axvline(alpha_opt, color='red', linestyle='--', label=f'Optimal α = {alpha_opt:.3f}')
plt.axhline(E_min, color='green', linestyle='--', label=f'Min E = {E_min:.3f}')
plt.xlabel('α')
plt.ylabel('E(α)')
plt.title('Variational Energy E(α) vs α')
plt.legend()
plt.grid()
plt.show()

Optimal alpha: 0.499998


Variational minimum E(alpha): 0.562500
Alpha from rescaling (part a): 1.122462
Numerical E from part (b): 0.667758
Percentage difference between variational and numerical E: 15.76%

In [ ]:
In [13]: ! jupyter nbconvert --to html /content/HW.ipynb

[NbConvertApp] Converting notebook /content/HW.ipynb to html


[NbConvertApp] WARNING | Alternative text is missing on 2 image(s).
[NbConvertApp] Writing 400228 bytes to /content/HW.html

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy