diff --git a/content/pdes/parabolic.ipynb b/content/pdes/parabolic.ipynb index 003c827..3a04a62 100644 --- a/content/pdes/parabolic.ipynb +++ b/content/pdes/parabolic.ipynb @@ -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", @@ -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": [ + "
\n", + "
\n", + " \"movie\n", + "
Figure: Solution to 1D heat equation with implicit method. Fo = 0.75
\n", + "
\n", + "
" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/content/pdes/parabolic_implicit_animated.gif b/content/pdes/parabolic_implicit_animated.gif new file mode 100644 index 0000000..f3070c6 Binary files /dev/null and b/content/pdes/parabolic_implicit_animated.gif differ