Skip to content

Commit

Permalink
work on parabolic module
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleniemeyer committed Mar 11, 2020
1 parent 0f6a26b commit e863912
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions content/pdes/parabolic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,39 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Implicit scheme\n"
"## Implicit scheme\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"clear all\n",
"\n",
"alpha = 2.3e-1;\n",
"dx = 0.1;\n",
"x = [0 : dx : 1]; n = length(x);\n",
"\n",
"% choose a Fourier number that is deliberately past the explicit method stability limit\n",
"Fo = 0.75;\n",
"alpha = 2.3e-1;\n",
"dt = Fo * dx^2 / alpha;\n",
"\n",
"x = [0 : dx : 1]; n = length(x);\n",
"t = [0 : dt : 10]; m = length(t);\n",
"t = [0 : dt : 1]; m = length(t);\n",
"\n",
"T = zeros(m, n);\n",
"\n",
"% Initial conditions\n",
"T(1,:) = 200;\n",
"\n",
"for k = 1 : m-1\n",
"plot(x, T(1,:))\n",
"axis([0 1 50 200]);\n",
"xlabel('Distance'); ylabel('Temperature');\n",
"F(1) = getframe(gcf);\n",
"\n",
"for k = 1 : m - 1\n",
" A = zeros(n,n);\n",
" b = zeros(n,1);\n",
" for i = 1 : n\n",
Expand All @@ -276,10 +288,41 @@
" b(i) = -T(k,i);\n",
" end\n",
" end\n",
" \n",
" T(k+1, :) = A \\ b;\n",
" plot(x, T(k+1,:))\n",
" axis([0 1 50 200]);\n",
" xlabel('Distance'); ylabel('Temperature');\n",
" F(k+1) = getframe(gcf);\n",
"end\n",
"close\n",
"\n",
"%% This generates a GIF of the results (for use in Jupyter Notebook)\n",
"filename = 'parabolic_implicit_animated.gif';\n",
"for i = 1 : length(F)\n",
" im = frame2im(F(i)); \n",
" [imind,cm] = rgb2ind(im,256); \n",
" % Write to GIF\n",
" if i == 1 \n",
" imwrite(imind,cm,filename,'gif', 'Loopcount',inf, 'DelayTime',1e-3); \n",
" else \n",
" imwrite(imind,cm,filename,'gif','WriteMode','append', 'DelayTime',1e-3); \n",
" end\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<figure>\n",
" <center>\n",
" <img src=\"parabolic_implicit_animated.gif\" alt=\"movie of implicit parabolic PDE solution\" style=\"width: 500px;\"/>\n",
" <figcaption>Figure: Solution to 1D heat equation with implicit method. Fo = 0.75</figcaption>\n",
" </center>\n",
"</figure>"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file added content/pdes/parabolic_implicit_animated.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e863912

Please sign in to comment.