This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vpde_lecture24 [2020/04/04 21:55] trinh |
vpde_lecture24 [2020/04/04 22:00] (current) trinh |
||
---|---|---|---|
Line 27: | Line 27: | ||
$$ | $$ | ||
B_n = \frac{2}{n\pi}[(-1)^n - 2]. | 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/ | ||
+ | |||
+ | % 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:length(t) | ||
+ | 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:length(t) | ||
+ | tj = t(j); | ||
+ | | ||
+ | u = 1/ | ||
+ | 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 | ||
+ | </ |