From 30aecda6dc9c5932f5822f84b16d75bf1d798a9a Mon Sep 17 00:00:00 2001 From: Dane Sabo Date: Tue, 29 Oct 2024 16:44:38 -0400 Subject: [PATCH] i hate --- NUCE_2100/HW6.ipynb | 157 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 127 insertions(+), 30 deletions(-) diff --git a/NUCE_2100/HW6.ipynb b/NUCE_2100/HW6.ipynb index 11d77db..8113205 100644 --- a/NUCE_2100/HW6.ipynb +++ b/NUCE_2100/HW6.ipynb @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 1, "id": "af61cdf6-cb10-43e3-81b5-703acbc893a0", "metadata": {}, "outputs": [], @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "id": "ecaad9e9-6ee3-4096-8bc6-4d07dbbe3802", "metadata": {}, "outputs": [], @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "id": "9f577d98-27db-451c-a60e-bb03d24070af", "metadata": {}, "outputs": [ @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 4, "id": "cf574d6a-da52-4bc3-8691-df9314c52376", "metadata": {}, "outputs": [ @@ -179,7 +179,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 5, "id": "ab38a583-abac-40a5-934d-f09bd2db8e7f", "metadata": {}, "outputs": [], @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 6, "id": "3119b774-40ab-4598-bfe1-517ab3cf549a", "metadata": {}, "outputs": [ @@ -206,7 +206,6 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.02256498080663735\n", "\n", "=========FINAL ANSWER=========\n", "2A:\n", @@ -234,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 7, "id": "5a353c72-3a91-4eb2-a30c-65af14628be3", "metadata": {}, "outputs": [ @@ -269,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 8, "id": "35215138-3a47-42bc-b702-adba0373eace", "metadata": {}, "outputs": [ @@ -319,7 +318,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 9, "id": "fce5c667-36be-46c9-8183-fafe4b3f28a3", "metadata": {}, "outputs": [], @@ -336,8 +335,9 @@ ] }, { + "attachments": {}, "cell_type": "markdown", - "id": "950dbab5-ece9-4f26-a8bf-8aca2a4cd947", + "id": "478f0c67-cd5b-4323-940d-fdf3ced0e2f6", "metadata": {}, "source": [ "## Part A\n", @@ -346,41 +346,55 @@ "\n", "But because we're steady state $\\frac{\\partial T}{\\partial t} = 0$:\n", "\n", - "$$ -q''' = k \\nabla^2 T $$\n", + "$$ 0 = k \\nabla^2 T + q''' $$\n", "\n", "And because we're in one dimension...\n", "\n", - "$$ k \\frac{d^2 T}{dx^2} = -q'''$$\n", + "$$ k \\frac{d^2 T}{dx^2} + q''' = 0$$\n", "\n", "Now we integrate:\n", "\n", - "$$ k\\frac{dT}{dx} = -q'''x + C_1 $$\n", + "$$ k\\frac{dT}{dx} + q'''x + C_1 = 0 $$\n", + "\n", + "$$ \\frac{dT}{dx} = -\\frac{ q'''x + C_1}{k} $$\n", "\n", "and integrate again:\n", "\n", - "$$ kT(x) = -\\frac{q'''x^2}{2} + C_1 x + C_2 $$\n" + "$$ T(x) = -(\\frac{ q'''}{2k} x^2 + \\frac{C_1}{k} x + C_2) $$\n" ] }, { "cell_type": "markdown", - "id": "d00a9406-b75b-4227-a9c4-fe4cdc194e98", + "id": "8bc55c33-7c5c-4596-ad22-b3482eac3a4f", "metadata": {}, "source": [ "This gives us our governing equation. Now we need to solve for our boundary conditions. We do this first on the left side:\n", - "$$ k\\frac{dT}{dx}_{x=0} = h_\\text{left} (T(0) - T_\\text{left})$$\n", + "$$ -k\\frac{dT}{dx}_{x=0} = h_\\text{left} ( T_\\text{left}- T(0))$$\n", "\n", - "$$ C_1 = h_\\text{left} (C_2/k - T_\\text{left})$$\n", + "$$ -k(-q''' \\times 0 / k - C_1/k) = h_\\text{left} (T_\\text{left} - C_2)$$\n", "\n", + "$$ C_1 = h_\\text{left} (T_\\text{left} - C_2)$$" + ] + }, + { + "cell_type": "markdown", + "id": "40964535-3127-4082-bdc3-9226e7d5a780", + "metadata": {}, + "source": [ "And now for our right side:\n", "\n", - "$$ k\\frac{dT}{dx}_{x=0.2/12 \\text{[ft]}} = h_\\text{right} (T(0.2/12)\\text{[ft]} - T_\\text{right})$$\n", + "$$ -k\\frac{dT}{dx}_{x=0.2/12 \\text{[ft]}} = h_\\text{right} (T_\\text{right} - T(0.2/12)\\text{[ft]}) $$\n", + "\n", + "$$ -k \\left(-\\frac{q''' x_\\text{right}+ C_1}{k}\\right) = h_\\text{right} (T_\\text{right} + (\\frac{ q'''}{2k} x_\\text{right}^2 + \\frac{C_1}{k} x_\\text{right} + C_2)) $$\n", + "\n", + "$$ q''' x_\\text{right}+ C_1 = h_\\text{right} (T_\\text{right} + (\\frac{ q'''}{2k} x_\\text{right}^2 + \\frac{C_1}{k} x_\\text{right} + C_2)) $$\n", "\n", "Now at this point I'm going to introduce SymPy to do the algebra heavy lifting. We can get away with this because I've organized all the units to be compatible when writing the code cell above:" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 37, "id": "0766e4d9-1f49-4449-a35d-05de86a3580e", "metadata": {}, "outputs": [ @@ -396,10 +410,10 @@ { "data": { "text/latex": [ - "$\\displaystyle C_{1} = 40 C_{2} - 280000$" + "$\\displaystyle - C_{1} = 280000 - 40 C_{2}$" ], "text/plain": [ - "Eq(C_1, 40*C_2 - 280000)" + "Eq(-C_1, 280000 - 40*C_2)" ] }, "metadata": {}, @@ -417,10 +431,10 @@ { "data": { "text/latex": [ - "$\\displaystyle C_{1} - 833333.333333333 = 0.5 C_{1} + 30 C_{2} - 418333.333333333$" + "$\\displaystyle C_{1} + 833333.333333333 = 0.5 C_{1} + 300 C_{2} + 418333.333333333$" ], "text/plain": [ - "Eq(C_1 - 833333.333333333, 0.5*C_1 + 30*C_2 - 418333.333333333)" + "Eq(C_1 + 833333.333333333, 0.5*C_1 + 300*C_2 + 418333.333333333)" ] }, "metadata": {}, @@ -430,10 +444,10 @@ "source": [ "C_1, C_2 = sm.symbols('C_1, C_2')\n", "\n", - "left_BC = sm.Eq(C_1, h_left*(C_2/k - T_left))\n", + "left_BC = sm.Eq(C_1, h_left*(T_left - C_2/k ))\n", "display('Left BC', left_BC)\n", "\n", - "right_BC = sm.Eq(k*(-q_ppprime*x_right + C_1)/k, h_right*((-q_ppprime*x_right**2/2 + C_1*x_right + C_2)/k - T_right))\n", + "right_BC = sm.Eq(q_ppprime*x_right + C_1, h_right*(T_right + (q_ppprime*x_right**2/2/k + C_1/k*x_right + C_2)))\n", "display('Right BC', right_BC)" ] }, @@ -447,14 +461,14 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 38, "id": "765d2f17-7d1a-43a8-8b46-88ffed3ddaa3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{C_1: -2500000.00000000, C_2: -55500.0000000000}" + "{C_1: -240714.285714286, C_2: 982.142857142858}" ] }, "metadata": {}, @@ -476,12 +490,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "736b23d6-b2b3-43fe-bc16-5b1e5ae5c07b", "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle -997.420634920635$" + ], + "text/plain": [ + "-997.420634920635" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "T = lambda x: (-q_ppprime*x**2/2 + soln[C_1]*x + soln[C_2])/k\n", + "T(0.2/12)" + ] + }, + { + "cell_type": "markdown", + "id": "38a944a7-43bd-425d-a5d9-b502f5fc1246", + "metadata": {}, + "source": [ + "Just trying some stuff" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "7af1e713-fc89-4679-99aa-f2bbacfb0c8e", + "metadata": {}, "outputs": [], "source": [ - "T = lambda x: -q_ppprime*x**2/2 + soln[C_1]*x + " + "x = sm.symbols('x')\n", + "T = sm.Function('T')(x)\n", + "gov_eq = sm.Eq(0,T.diff(x)+q_ppprime)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "5edad66f-d4c8-4b51-8c92-343f83f65944", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle T{\\left(x \\right)} = C_{1} - 50000000.0 x$" + ], + "text/plain": [ + "Eq(T(x), C1 - 50000000.0*x)" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sm.dsolve(gov_eq)" ] }, { @@ -500,6 +573,30 @@ "## Part C" ] }, + { + "cell_type": "code", + "execution_count": 24, + "id": "ca0c2b96-652e-4f67-81b0-f98aecfb1707", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "=========FINAL ANSWER=========\n", + "3C:\n", + "At the left face: -5550 F \n", + "At the right face:-10411 F\n", + "=========FINAL ANSWER=========\n", + "\n" + ] + } + ], + "source": [ + "answer_print('3C',f'At the left face: {T(x_left):.0f} F \\nAt the right face:{T(x_right):.0f} F')" + ] + }, { "cell_type": "markdown", "id": "ea13e251-33e4-4578-9ba1-27c31caff0b7",