This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
vpde_lecture24 [2020/03/28 12:43] trinh created |
vpde_lecture24 [2020/04/04 22:00] (current) trinh |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Computation of the heat equation III ====== | + | ====== |
| < | < | ||
| Line 5: | Line 5: | ||
| </ | </ | ||
| - | //Need to write this.// | + | ====== Example 15.4: Solution of the inhomogeneous Dirichlet problem ====== |
| + | |||
| + | This lecture starts off with Example 15.4 from the notes, where we look to solve | ||
| + | $$ | ||
| + | \begin{gathered} | ||
| + | u_t = u_{xx} \\ | ||
| + | u(0, t) = 2, \qquad u(\pi, t) = 1 \\ | ||
| + | u(x, 0) = 0. | ||
| + | \end{gathered} | ||
| + | $$ | ||
| + | |||
| + | We show that the solution is given by | ||
| + | $$ | ||
| + | u(x, t) = U(x) + \sum_{n=1}^\infty B_n \sin(nx) \mathrm{e}^{-n^2 t} | ||
| + | $$ | ||
| + | where we have found the steady-state solution | ||
| + | $$ | ||
| + | U(x) = 2 - \frac{x}{\pi}, | ||
| + | $$ | ||
| + | as well as the coefficients | ||
| + | $$ | ||
| + | B_n = \frac{2}{n\pi}[(-1)^n - 2]. | ||
| + | $$ | ||
| + | |||
| + | We also illustrated the solution using the code: | ||
| + | |||
| + | < | ||
| + | %% Plot the Fourier series for Example 15.4 | ||
| + | % Written for MA20223 Vectors & PDEs 2019-20 | ||
| + | |||
| + | clear % Clear all variables | ||
| + | close all % Close all windows | ||
| + | N = 100; % How many Fourier modes to include? | ||
| + | |||
| + | R = @(n, t, x) 2/(n*pi)*((-1)^n - 2)*exp(-n^2*t)*sin(n*x); | ||
| + | |||
| + | % Create a mesh of points between two limits | ||
| + | x0 = pi; x = linspace(0, x0, 1000); | ||
| + | |||
| + | % Create a mesh of points in time | ||
| + | t = linspace(0, 5, 200); | ||
| + | |||
| + | figure(1); | ||
| + | plot(x, 2 - x/pi, ' | ||
| + | ylim([-0.2, | ||
| + | xlim([0, x0]); % Set the x limits | ||
| + | xlabel(' | ||
| + | hold on | ||
| + | |||
| + | for j = 1: | ||
| + | tj = t(j); | ||
| + | |||
| + | u = (2 - x/pi); | ||
| + | for n = 1:N | ||
| + | u = u + R(n, tj, x); | ||
| + | end | ||
| + | if j == 1 | ||
| + | p = plot(x, u, ' | ||
| + | else | ||
| + | set(p, ' | ||
| + | end | ||
| + | drawnow | ||
| + | title([' | ||
| + | pause(0.1); | ||
| + | |||
| + | if j == 1 | ||
| + | pause | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | ===== Problem set 8 Q1 ===== | ||
| + | |||
| + | The next thing we studied was PS8, Q1, which is the solution of the homogeneous Neumann problem for the heat equation. | ||
| + | |||
| + | < | ||
| + | %% Plot the Fourier series for a made-up modification of PS8 Q1. | ||
| + | % Written for MA20223 Vectors & PDEs | ||
| + | |||
| + | clear % Clear all variables | ||
| + | close all % Close all windows | ||
| + | N = 20; % How many Fourier modes to include? | ||
| + | |||
| + | % Define an in-line function that takes in three inputs: | ||
| + | R = @(n, t, x) 4*(-1)^n/ | ||
| + | |||
| + | % Create a mesh of points between two limits | ||
| + | x0 = pi; | ||
| + | x = linspace(0, x0, 1000); | ||
| + | |||
| + | % Create a mesh of points in time | ||
| + | t = linspace(0, 5, 200); | ||
| + | |||
| + | figure(1); | ||
| + | plot(x, x.^2, ' | ||
| + | ylim([-0.2, | ||
| + | xlim([0, x0]); % Set the x limits | ||
| + | xlabel(' | ||
| + | hold on | ||
| + | |||
| + | for j = 1: | ||
| + | tj = t(j); | ||
| + | |||
| + | u = 1/2*(2*pi^2/ | ||
| + | for n = 1:N | ||
| + | u = u + R(n, tj, x); | ||
| + | end | ||
| + | if j == 1 | ||
| + | p = plot(x, x.^2, ' | ||
| + | else | ||
| + | set(p, ' | ||
| + | end | ||
| + | drawnow | ||
| + | title([' | ||
| + | pause(0.1); | ||
| + | |||
| + | if j == 1 | ||
| + | pause | ||
| + | end | ||
| + | end | ||
| + | </Code> | ||