question
Consider the heat equation
Ou 02u
x=0,t=0on{x=0}0,T
ne x=1,t+x=1,t=0on{x=1}0,T] =gon0,1{t=0}
for some initial condition function g : (0, 1) R and source function f : (0, 1) (0, T] R. Note that a Robin boundary condition is imposed on the right boundary.
We will implement a finite difference heat equation solver in MATLAB. We will use n + 1 grid points 0 = o < 1 < <n=1 to discretize the spatial domain, and J +1 time points 0 = t < t1.. < t = T to discretize the time interval. We assume both spatial and temporal points are equispaced. Our goal is to approximate the solution u(xi,t) for i = 1,...,n and j=1,...,J.
We first consider the semi-discrete form of the equation associated with the second-order accurate finite difference approximation in space.
(a) (10%) Find the semi-discrete equations for (i) the first unknown node i = 1, (ii the last unknown node i = n, and (iii) all other unknown nodes i [2,n - 1]. Also identify the equation for (iv) the initial condition. Express the answer in terms of , u(t), fi(t) = f(i,t), and gi=g(i).
(b) (6% The semi-discrete equations found in (a) can be expressed as
dt t=0=gin R
where (t) R, A Rnn, f(t) R, and g R. Find the expressions for the matrix A and vectors f(t) and g.
We now consider the fully discrete form of the equation associated with the Crank-Nicolson ap- proximation in time. (c) (6%) The fully discrete equation associated with the semi-discrete equation found in (b) can be expressed as C=Du-1+Ft,tf-1j=1,..J. where C Rnn, D Rnn, and F(ti, ti-1) R. Find the expressions for the matrices and vectors. We now implement the finite difference solver in MATLAB. (d) (15%) Starting with the template heat.fd.temp.m, implement the finite difference solver. Note. Please include (i) a copy of the code in the PDF file and (ii) the source code in the zip file to facilitate the grading process. Note 2. You do not have to use the template if you would rather code everything from scratch.
e5%Let
fx,t=exp-3x)exp(t, gx=x2-x+ 9
Invoke the solver for T = 1, n = 16, J = 16. Plot, in a single figure, the solution at the final time t =0,t =1/16,t =1/8,t =1/4,1/2, and t=1.
(f) (8%) We wish to verify the convergence of the solver. To this end, for the functions f and g given in (e), compute the solution for (n, J) = (8, 8), (16, 16), (32,32), and (64,64), and then evaluate (the approximation of) the output s = ( = 1,t = 1) for each of the four discretizations. Also evaluate the reference output sref associated with (n, J) = (512,512). Report, in a table, the error associated with the four different levels of discretizations. Report also the value of sref to at least six significant digits. Does the observed error behavior match your expectation? Note. The table should have three columns with headings n, J, and |sref s|. Please provide both the table and the value of sref in the hard copy of the assignment to facilitate the grading process.