Trinh @ Bath

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
vpde_lecture22 [2020/03/24 14:37]
trinh
vpde_lecture22 [2020/03/26 13:29]
trinh
Line 2: Line 2:
  
 //This lecture is about terminology but it is important not to be bogged down by terminology. You will practice by doing!//  //This lecture is about terminology but it is important not to be bogged down by terminology. You will practice by doing!// 
 +
 +<html>
 +<iframe width="560" height="315" src="https://www.youtube.com/embed/30UzA62y_XE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
 +</html>
  
 ===== An example ===== ===== An example =====
Line 32: Line 36:
  
 ==== The 1D heat equation with zero Dirichlet conditions ====  ==== The 1D heat equation with zero Dirichlet conditions ==== 
 +
 +Now let's return to the study of the heat equation with zero Dirichlet conditions stated at the top of this note. In the video, we will go through the procedure from start to end in solving the BVP. In the end, the solution will be given by a Fourier sine series,
 +
 +$$
 +u(x, t) \sim \sum_1^\infty \left[b_n \sin\left(\frac{n\pi x}{L}\right)\right]. 
 +$$
 +
 +where $b_n$ will be the Fourier sine coefficients of the odd $2\pi$ extension of $f(x)$ on $[0, \pi]$. 
 +
 +<Code:Matlab linenums:1 |Solution of 1D heat equation with zero Dirichlet>
 +% 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: 
 +%   Input 1: n value [scalar]
 +%   Input 2: x value [vector]
 +%   Input 3: t value [scalar]
 +R = @(n, t, x) -2/(n*pi)*((-1)^n - 1)*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);                                  % Open the figure
 +plot([0, pi], [1, 1], 'b', 'LineWidth', 2); % Plot the base function
 +ylim([-0.2,1.2]);                           % Set the y limits
 +xlim([0, x0]);                              % Set the x limits
 +xlabel('x'); ylabel('u(x,t)');
 +hold on
 +for j = 1:length(t)
 +    tj = t(j);
 +    
 +    u = 0;
 +    for n = 1:N
 +        u = u + R(n, tj, x);
 +    end
 +    
 +    % Plotting commands
 +    if j == 1
 +        p = plot(x, u, 'r');
 +    else
 +        set(p, 'YData', u);
 +    end
 +    drawnow
 +    title(['t = ', num2str(tj)]);
 +    pause(0.1);
 +   
 +    if j == 1
 +        pause
 +    end
 +end
 +</Code>