Skip to content

Commit 5b87f20

Browse files
authored
Jupyter notebook version added
1 parent 3f7d2ff commit 5b87f20

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

ch08/Program_8.1_qmplane.ipynb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"#\n",
10+
"# Program 8.1: A quantum plane wave (qmplane.ipynb)\n",
11+
"# J Wang, Computational modeling and visualization with Python\n",
12+
"#\n",
13+
"\n",
14+
"import matplotlib.pyplot as plt, numpy as np\n",
15+
"import matplotlib.animation as am\n",
16+
"%matplotlib notebook\n",
17+
"\n",
18+
"def updatefig(*args): # args[0] = frame\n",
19+
" wf = np.exp(1j*(x-0.1*args[0])) # traveling plane wave\n",
20+
" w = [prob, wf.real, wf.imag]\n",
21+
" for i in range(len(w)):\n",
22+
" plot[i].set_data(x, w[i]) # update data \n",
23+
"\n",
24+
"x = np.linspace(-2*np.pi, 2*np.pi, 101)\n",
25+
"wf, prob = np.exp(1j*x), [1]*len(x)\n",
26+
"fig = plt.figure()\n",
27+
"plot = plt.plot(x,prob, x,wf.real, x,wf.imag) # plot object \n",
28+
"ani = am.FuncAnimation(fig, updatefig, interval=10) # animate \n",
29+
"plt.ylim(-1.2, 1.2), plt.show()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": true
37+
},
38+
"outputs": [],
39+
"source": []
40+
}
41+
],
42+
"metadata": {
43+
"kernelspec": {
44+
"display_name": "Python 3",
45+
"language": "python",
46+
"name": "python3"
47+
},
48+
"language_info": {
49+
"codemirror_mode": {
50+
"name": "ipython",
51+
"version": 3
52+
},
53+
"file_extension": ".py",
54+
"mimetype": "text/x-python",
55+
"name": "python",
56+
"nbconvert_exporter": "python",
57+
"pygments_lexer": "ipython3",
58+
"version": "3.6.1"
59+
}
60+
},
61+
"nbformat": 4,
62+
"nbformat_minor": 2
63+
}

ch08/Program_8.6_gaussxw.ipynb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"#\n",
10+
"# Program 8.6: Gauss abscissa and weight (gaussxw.ipynb)\n",
11+
"# J Wang, Computational modeling and visualization with Python\n",
12+
"#\n",
13+
"\n",
14+
"from scipy.special import legendre\n",
15+
"\n",
16+
"n = 36 # order\n",
17+
"p = legendre(n)\n",
18+
"x = p.weights[:,0] # abscissa\n",
19+
"w = p.weights[:,1] # weight\n",
20+
"\n",
21+
"for i in range(n):\n",
22+
" print ('%20.16f %20.16f' %(x[i], w[i]))"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"metadata": {
29+
"collapsed": true
30+
},
31+
"outputs": [],
32+
"source": []
33+
}
34+
],
35+
"metadata": {
36+
"kernelspec": {
37+
"display_name": "Python 3",
38+
"language": "python",
39+
"name": "python3"
40+
},
41+
"language_info": {
42+
"codemirror_mode": {
43+
"name": "ipython",
44+
"version": 3
45+
},
46+
"file_extension": ".py",
47+
"mimetype": "text/x-python",
48+
"name": "python",
49+
"nbconvert_exporter": "python",
50+
"pygments_lexer": "ipython3",
51+
"version": "3.6.1"
52+
}
53+
},
54+
"nbformat": 4,
55+
"nbformat_minor": 2
56+
}

0 commit comments

Comments
 (0)