辅导案例-1D
Homework 4: Space-Time Discretization and Stability Due Thursday, November 28th at 1 am. In this problem, we will work with the 1D wave equation ut = κuxx, t ∈ [0, 1], x ∈ [0, 1], κ = 0.1. Use periodic boundary conditions1 u(t, 0) = u(t, 1), and initial heat distribution u(0, x) = sin(2pix). Problem 1: Implement the forward Euler method to solve the problem. We can write this method in shorthand as Dtu n j = κD2xunj and explicitly as un+1j − unj ∆t = κ unj+1 − 2unj + unj−1 ∆2x We suggest you use linear algebra to implement this iteration. That is, define the vector Un = un1 un2 ... unm and implement the forward Euler iteration as Un+1 = Un + κ∆t∆2x AUn where A is a discretized operator. Use dt = 0.05 and dx = 0.1. Save the solution u(1, x), a column vector of size 10, into A1.dat. What happens if you try to take dt = dx = 0.05, or dt = dx = 0.01? Problem 2: Implement the backward Euler method to solve the problem. We can write this method in shorthand as Dtu n j = κD2xun+1j and explicitly as un+1j − unj ∆t = κ un+1j+1 − 2un+1j + un+1j−1 ∆2x Here, as in the previous problem, use linear algebra to set up the iteration. You will need to solve a linear system in this case, since backward Euler is an implicit method. Use dt = 0.05 and dx = 0.1. Save the solution u(1, x), a column vector of size 10, into A2.dat. Use dt = 0.01 and dx = 0.01. Save the solution u(1, x), a column vector of size 100, into A3.dat. 1Periodic boundary conditions force simple modifications to discretized spatial operators. Last weeks’ homework will help you get through the setup pretty quickly! 1 Problem 3: Implement the Crank-Nicolson method to solve the problem: Dtu n j = κ 2 ( D2xu n j +D2xuPj n+ 1 ) and explicitly as un+1j − unj ∆t = κ2∆2x ( unj+1 − 2unj + unj−1 + un+1j+1 − 2un+1j + un+1j−1 ) Here, as in the previous problem, use linear algebra to set up the iteration. Use dt = 0.05 and dx = 0.1. Save the solution u(1, x), a column vector of size 10, into A4.dat. Use dt = 0.01 and dx = 0.01. Save the solution u(1, x), a column vector of size 100, into A5.dat. Make a movie of the time evolution of your heat distributions. Play with how large a step size you can get away with when working with the implicit methods. You don’t have to turn anything in for this problem. 2