Final: WIP: Draft something for task 3.1

Fully vectorizing seems not the way to go.
This commit is contained in:
2022-03-29 19:08:18 +02:00
parent 3a2f92bfbf
commit b7a7a08798

View File

@ -86,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {
"deletable": false,
"nbgrader": {
@ -135,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {
"deletable": false,
"nbgrader": {
@ -202,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {
"deletable": false,
"nbgrader": {
@ -289,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {
"deletable": false,
"nbgrader": {
@ -342,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {
"deletable": false,
"nbgrader": {
@ -398,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {
"deletable": false,
"nbgrader": {
@ -606,7 +606,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 114,
"metadata": {
"deletable": false,
"nbgrader": {
@ -628,8 +628,26 @@
" \n",
" \"\"\"\n",
" \n",
" x = np.linspace(-1e12, 1e12, 1e12)\n",
" V = lambda x: -1 \n",
" sigma = .25\n",
" positions = atomic_positions(n)\n",
" \n",
" infty = 1e3\n",
" epsilon = 1e-5\n",
" x = np.arange(-infty, infty, epsilon)\n",
" \n",
" # V is calculated by creating a matrix len(x) by len(positions) over which\n",
" # we sum each row to create a matching value V(x) for each element of x.\n",
" #V = lambda x: np.sum(-1/(np.abs(x - positions)) + 0.001, axis=1)\n",
" #V = lambda x: np.sum( -1/( x - np.tile(positions, (len(x), 1)).T) + 0.001 ), axis=0 )\n",
" def V(x):\n",
" value = np.zeros(x.shape)\n",
" for x_i in positions:\n",
" value += -1./(np.abs(x - x_i) + 0.001)\n",
" return value\n",
" #V = lambda x: np.sum( -1/( np.abs(np.tile(x, (len(positions), 1)) - np.tile(positions, (len(x), 1)).T) + 0.001 ), axis=0 )\n",
" #V = lambda x: np.sum( -1/( np.abs(x - np.tile(positions, (len(x), 1)).T) + 0.001 ), axis=0 )\n",
" # OMG IT EXISTS\n",
" #V = lambda x: np.sum( -1/( np.abs(np.subtract.outer(x, positions)) + 0.001 ), axis=1 )\n",
" integrand = lambda x: atomic_basis(x, positions[i], sigma)*V(x)*atomic_basis(x, positions[j], sigma)\n",
" return integrate(integrand, x)\n",
"\n",
@ -645,7 +663,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 115,
"metadata": {
"deletable": false,
"nbgrader": {
@ -660,12 +678,21 @@
"task": false
}
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"21.9 s ± 35.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"# Verify that long-range hoppings are negligible here ...\n",
"#print(hopping(1, 0, 10), hopping(0, 1, 10))\n",
"%timeit hopping(1, 0, 10)\n",
"\n",
"# YOUR CODE HERE\n",
"raise NotImplementedError()"
"#raise NotImplementedError()"
]
},
{