<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Testing the 1-D DVR
Use matplotlib inline so that plots show up in the notebook.
Step1:  Next import the dvr_1d module. We import dvr_1d using a series of ipython notebook magic commands so that we can make changes to the module file and test those changes in this notebook without having to restart the notebook kernel.
Step2:  First, we'll test the 1-D sinc function DVR on a simple harmonic oscillator potential.
Step3:  Let's try the same potential but with a Hermite basis. We see that since the Hermite polynomials are the exact solutions to the SHO problem, we can use npts == num_eigs. The eigenvectors will look horrible but the eigenvalues will be very accurate.
Step4:  Next we'll test the 1-D Sinc DVR on a finite and an infinite square well. "Infinite" here just means really really huge.
Step5:  And we might as well try it out with the Hermite basis set too.
Step6:  Let's repeat all these tests with the 1-D Fourier Sine DVR.
Step7:  Let's test the Bessel DVR
Step8:  Testing the 2-D DVR
We're going to be using 3D plots so let's change the matplotlib backend so the we can look at the plots in a separate window and manipulate them.
Step9:  Now we'll construct a 2-D Sinc DVR from a product basis of 1-D Sinc DVRs.
Step10:  Testing the 3-D DVR
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as sp
import scipy.sparse.linalg as sla
Explanation: Testing the 1-D DVR
Use matplotlib inline so that plots show up in the notebook.
End of explanation
# autoreload the lattice module so that we can make changes to it 
# without restarting the ipython notebook server
%load_ext autoreload
%autoreload 1
%aimport dvr_1d
%aimport dvr_2d
%aimport dvr_3d
Explanation: Next import the dvr_1d module. We import dvr_1d using a series of ipython notebook magic commands so that we can make changes to the module file and test those changes in this notebook without having to restart the notebook kernel.
End of explanation
d = dvr_1d.SincDVR(npts=200, L=14)
d.sho_test(precision=12)
Explanation: First, we'll test the 1-D sinc function DVR on a simple harmonic oscillator potential.
End of explanation
d = dvr_1d.HermiteDVR(npts=5)
d.sho_test(k=1., precision=11)
Explanation: Let's try the same potential but with a Hermite basis. We see that since the Hermite polynomials are the exact solutions to the SHO problem, we can use npts == num_eigs. The eigenvectors will look horrible but the eigenvalues will be very accurate.
End of explanation
d = dvr_1d.SincDVR(npts=500, L=20)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
Explanation: Next we'll test the 1-D Sinc DVR on a finite and an infinite square well. "Infinite" here just means really really huge.
End of explanation
d = dvr_1d.HermiteDVR(npts=268)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
Explanation: And we might as well try it out with the Hermite basis set too.
End of explanation
d = dvr_1d.SineDVR(npts=1000, xmin=-15, xmax=15)
d.sho_test(precision=12)
d.square_well_test(precision=6)
d.inf_square_well_test(precision=6)
Explanation: Let's repeat all these tests with the 1-D Fourier Sine DVR.
End of explanation
d = dvr_1d.BesselDVR(npts=100, R=20., dim=3, lam=1)
d.sho_test(xmin=0., xmax=8., ymin=0., ymax=12.)
Explanation: Let's test the Bessel DVR
End of explanation
%matplotlib osx
Explanation: Testing the 2-D DVR
We're going to be using 3D plots so let's change the matplotlib backend so the we can look at the plots in a separate window and manipulate them.
End of explanation
d1d = dvr_1d.SincDVR(npts = 30, L=10)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=14)
d1d = dvr_1d.HermiteDVR(npts=5)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=14)
d1d = dvr_1d.SincDVR(npts = 30, L=10)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, precision=10, uscale=3.5, doshow=True)
d1d = dvr_1d.SineDVR(npts = 30, xmin=-5., xmax=5.)
d2d = dvr_2d.DVR(dvr1d=d1d)
E, U = d2d.sho_test(num_eigs=5, uscale=3., doshow=False)
#plt.spy(d2d.t().toarray(), markersize=.1);
#plt.savefig('/Users/Adam/Dropbox/amath585_final/K_2D_sparsity.png', bbox_inches='tight', dpi=400)
Explanation: Now we'll construct a 2-D Sinc DVR from a product basis of 1-D Sinc DVRs.
End of explanation
d1d = dvr_1d.SincDVR(npts = 16, L=10)
d3d = dvr_3d.DVR(dvr1d=d1d, spf='csr')
E, U = d3d.sho_test(num_eigs=5)
#plt.spy(d3d.t().toarray(), markersize=.1);
#plt.savefig('/Users/Adam/Dropbox/amath585_final/K_3D_sparsity.png', bbox_inches='tight', dpi=400)
Explanation: Testing the 3-D DVR
End of explanation
<END_TASK>