Skip to content

Commit

Permalink
Fix bug in cubic spline matrix setup
Browse files Browse the repository at this point in the history
Used the wrong boundary condition equation in one place.

Also compute nval from nknots instead of the reverse.
  • Loading branch information
markdewing committed Feb 1, 2019
1 parent 21d4ff6 commit 7c34d4a
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions Wavefunctions/Cubic Splines Basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Set up matrix with concrete number of knots\n",
"nval = 2\n",
"nknots = nval + 1\n",
"nknots = 3\n",
"nval = nknots -1\n",
"neqn = 4*nval\n",
"m = Matrix.eye(neqn, neqn)\n",
"rhs = Matrix.eye(neqn,1)\n",
Expand All @@ -404,7 +404,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -478,7 +478,7 @@
" m[jdx,idx] = get_coeff_for(eq6.lhs.subs(n,nval), sym , symlist)\n",
" else:\n",
" m[jdx,idx] = get_coeff_for(eq6b.lhs.subs(n,nval), sym , symlist)\n",
"rhs[jdx] = eq5.rhs.subs(n,nval)\n",
"rhs[jdx] = eq6.rhs.subs(n,nval)\n",
"\n",
"# Display of matrix-vector multiplication is not working - pretend the first equals is a multiplication\n",
"with evaluate(False):\n",
Expand All @@ -487,7 +487,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -523,7 +523,7 @@
"⎣ 4 2 4 ⎦"
]
},
"execution_count": 23,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -536,7 +536,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -548,7 +548,7 @@
"{y[0]: 0.5, y[1]: 1.1, y[2]: 1.5}"
]
},
"execution_count": 25,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -561,7 +561,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -583,7 +583,7 @@
" 2 4 ⎭"
]
},
"execution_count": 36,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -596,7 +596,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -637,7 +637,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -682,7 +682,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -723,7 +723,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand All @@ -735,7 +735,7 @@
"a[i] = y[i]"
]
},
"execution_count": 50,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -748,7 +748,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -764,7 +764,7 @@
"[i] = y[i + 1]"
]
},
"execution_count": 55,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -777,7 +777,7 @@
},
{
"cell_type": "code",
"execution_count": 96,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -790,7 +790,7 @@
"3⋅(x[i + 1] - x[i]) ⋅d[i] + 2⋅(x[i + 1] - x[i])⋅c[i] + b[i] = b[i + 1]"
]
},
"execution_count": 96,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -804,7 +804,7 @@
},
{
"cell_type": "code",
"execution_count": 97,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand All @@ -816,7 +816,7 @@
"6⋅(x[i + 1] - x[i])⋅d[i] + 2⋅c[i] = 2⋅c[i + 1]"
]
},
"execution_count": 97,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -830,7 +830,7 @@
},
{
"cell_type": "code",
"execution_count": 118,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -854,7 +854,7 @@
"6⋅(-x[n - 1] + x[n])⋅d[n - 1] + 2⋅c[n - 1] = 0"
]
},
"execution_count": 118,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -869,7 +869,7 @@
},
{
"cell_type": "code",
"execution_count": 117,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand All @@ -894,7 +894,7 @@
"3⋅(-x[n - 1] + x[n]) ⋅d[n - 1] + 2⋅(-x[n - 1] + x[n])⋅c[n - 1] + b[n - 1] = 0"
]
},
"execution_count": 117,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -910,7 +910,7 @@
},
{
"cell_type": "code",
"execution_count": 99,
"execution_count": 25,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -951,7 +951,7 @@
},
{
"cell_type": "code",
"execution_count": 100,
"execution_count": 26,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1017,7 +1017,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1032,7 +1032,7 @@
},
{
"cell_type": "code",
"execution_count": 116,
"execution_count": 28,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1080,7 +1080,7 @@
" 2 -6⋅x[1] + 6⋅x[2]⎦"
]
},
"execution_count": 116,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1129,15 +1129,15 @@
" m[jdx,idx] = get_coeff_for(eq6.lhs.subs(n,nval), sym , symlist)\n",
" else:\n",
" m[jdx,idx] = get_coeff_for(eq6b.lhs.subs(n,nval), sym , symlist)\n",
"rhs[jdx] = eq5.rhs.subs(n,nval)\n",
"rhs[jdx] = eq6.rhs.subs(n,nval)\n",
"\n",
"# Display just the matrix, displaying other pieces doesn't work, and they are the same as previously\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 103,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1149,7 +1149,7 @@
},
{
"cell_type": "code",
"execution_count": 104,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1160,7 +1160,7 @@
},
{
"cell_type": "code",
"execution_count": 105,
"execution_count": 31,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1199,7 +1199,7 @@
},
{
"cell_type": "code",
"execution_count": 112,
"execution_count": 32,
"metadata": {},
"outputs": [
{
Expand Down

0 comments on commit 7c34d4a

Please sign in to comment.