In this course, we conduct computer experiments with numerical methods to solve ordinary differential equations (ODEs) and partial differential equations (PDEs). The numerical algorithms and theoretical results in MATH 107 are examined with practical examples, and the possibilities and challenges of different numerical methods are discussed in detail. We start to learn the basics of computer programming with the programming language MATLAB. We write codes for numerical methods, test them with practical examples, and discuss why they need to be considered. (Course Syllabus)
Code 2: Scalar, Vector, and Matrix Computations in MATLAB
Code 3: Graphs of Functions
Code 4: Finite Differences (Convergence Rates)
Code 5: Forward Euler's Method (Its Stability)
Code 6: Backward Euler's Method (Function Files in MATLAB)
Code 7: The Errors in Forward Euler's Method / High-Order Taylor Methods
Code 8: The 2nd-Order Runge-Kutta Method / Modified Euler Method
Code 9: The 3rd-Order Runge-Kutta Method (Heun's Method)
Code 10: Error Control
Code 11: Multistep Methods for linear ODEs (Adams-Bashforth and Adams-Moulton Methods)
Code 12: Simpson's Method for IVPs
Code 13: Adams-Moulton Two-Step Implicit Method with Newton's Method for Nonlinear ODEs
Code 14: Forward Euler's Method for Systems of Differential Equations
Code 15: The 2nd Order Runge-Kutta Method for Systems of Differential Equations Using Vector Forms
Code 16: Stability Region
Code 17: The Linear Shooting Method
Code 18: The Shooting Method for Nonlinear Problems
Code 19: Finite-Difference Methods for Linear Problems with the Zero Boundary Condition
Code 20: The Unwind Finite-Difference Method for Convection-Dominated Problems
Code 21: Finite-Difference Methods for Nonlinear ODEs
Code 22: Finite-Difference Methods for Linear ODEs with Nonzero Boundary Conditions
Code 23: The Rayleigh-Ritz Method
Code 24: Finite-Difference Methods for Elliptic Partial Differential Equations
Code 25: Homework Solution (Finite-Difference Methods for Nonlinear Problems)
Code 26: Finite-Difference Methods for Parabolic Partial Differential Equations
Code 27: Finite-Difference Methods for Hyperbolic Partial Differential Equations
Homework 1: Finite Differences and Convergence Rates
Let us consider a function f(x)=e^x+x+1. Then, we will approximate f′(2) using finite differences.
Use the Forward difference, (f(2+h)−f(2))/h with a sufficiently small h to approximate it.
Compare your approximations with the exact, f′(2)=e^2+1, that is, compute errors.
Show the convergence rate.
Consider the same function.
Use the Centered difference, (f(2+h)−f(2−h))/2h with a sufficiently small h to approximate it.
Compute errors.
Show the convergence rate.
Discuss on the following questions. (Your argument should be included in M-files as comments.)
Are their convergence rates different?
Why do they have different convergence rates (or the same rate)?
Homework 2: Forward and Backward Euler Methods
Consider the initial value problem, y′=−100y, y(0)=1 on the given interval 0≤t≤2.
Use Forward Euler method with h=0.5 to find a discrete solution to the problem.
Use Forward Euler method with h=0.001 to find a discrete solution to the problem.
Use Backward Euler method with h=0.5 to find a discrete solution to the problem.
Plot graphs to compare your discrete solutions with the exact solution, y(t)=e^(−100t).
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the above problem. Your argument should be included in M-files as comments.)
What is the difference between explicit methods and implicit methods?
What are the advantage and disadvantage of Forward Euler method?
What are the advantage and disadvantage of Backward Euler method?
Homework 3: Runge-Kutta Methods
Consider the initial value problem, y′=1+y/t, y(1)=2 on the given interval 1≤t≤2.
With different mesh size, use the 2nd order Runge-Kutta method to show convergence rates of the truncation error and global error.
With different mesh size, use the 4th order Runge-Kutta method to show convergence rates of the truncation error and global error.
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problem 1. Your argument should be included in M-files as comments.)
How do we obtain the truncation errors? Why did you use such a way?
What advantages do the Runge-Kutta methods have compared to Forward Euler method?
If you apply the Runge-Kutta methods to another ODE y′=−100y, can you get a good approximation?
Homework 4: Multistep Methods for Nonlinear ODEs
Consider the initial value problem, y′=1+(t−y)^2, y(2)=1 on the given interval 2≤t≤3 with h=0.2.
Use Adams-Bashforth three-step method to approximate the solution to the initial value problem.
Use Adams-Moulton three-step method to approximate the solution to the initial value problem. (Hint: Use Newton's method to find the root of the equation at each iteration.)
Plot graphs to compare your discrete solutions with the exact solution y(t)=t+1/(1−t).
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problem 1. Your argument should be included in M-files as comments.)
Why should we use Newton's method in Adams-Moulton methods? Are there alternative ways that you have learned?
For both Adams-Bashforth and Adams Moulton three-step methods, do their truncation errors have the same convergence rates? Explain why they are the same or why they are different.
Homework 5: Systems of Differential Equations
Consider the system of first-order differential equations u1′=u1−u2+2, u1(0)=−1; u2′=−u1+u2+4t, u2(0)=0; 0≤t≤1; h=0.1.
Use the 4th order Runge-Kutta method to approximate the solutions to the system of differential equations.
Plot graphs to compare your discrete solutions with the actual solutions u1(t)=−e^(2t)/2+t^2+2t−1/2, u2(t)=e^(2t)/2+t^2−1/2.
Consider the higher-order differential equation, y″−2y′+y=t*e^t−t, y(0)=y′(0)=0 on the given interval 0≤t≤1 with h=0.1.
Use the same method to approximate the solution to the higher-order differential equation.
Plot graphs to compare your discrete solution with the exact solution y(t)=t^3*e^t/6−t*e^t+2e^t−t−2.
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problem 1 and 2. Your argument should be included in M-files as comments.)
How many lines does your code have? How long does your code take to run (computational time)?
Is there any way to reduce the lines in your code? Does the way reduce computational time?
Homework 6: Stability Region
Complete following steps to draw the region R of absolute stability for the second-order Runge-Kutta (RK2) method.
Find the characteristic polynomial P(z,η) with η=hλ corresponding the RK2 method with f(t,y)=λy.
Solve the equation P(z,η)=0 for η. There will be two solutions.
Draw the region R of absolute stability using the results and the day16 code.
Using the same steps, draw the region R of absolute stability for the implicit trapezoidal method, w_{j+1}=w_j+(h/2)*[f(t_{j+1},w_{j+1})+f(t_j,w_j)].
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problem 1 and 2. Your argument should be included in M-files as comments.)
If a value of η is in the region R for given λ and h, what does this mean? If not, what would happen?
When λ=−100, how small must the step size h be to get a good approximation using the RK2 method?
How about the trapezoidal method?
Homework 7: The Linear Shooting Method and Finite Difference Methods
Consider the boundary-value problem y″=4(y−x), 0≤x≤1, y(0)=0, y(1)=2 with h=0.1.
Use the Linear Shooting method with the 4th order Runge-Kutta method to approximate the solution.
Use the Linear Finite-Difference method to approximate the solution.
Plot graphs to compare your approximate solutions with the exact solution y(x)=e^2*(e^(2x)−e^(−2x))/(e^4−1)+x.
Check the computational time of each method.
Discuss on the following question. (Your argument should be consistent with the results that you obtained from the problem 1. Your argument should be included in M-files as comments.)
What are the advantage and disadvantage of the Linear Shooting method?
What are the advantage and disadvantage of the Linear Finite-Difference method?
Which method would you prefer to use when you solve linear boundary-value problems? Explain why.
What happens if h=0.0001?
Homework 8: Finite Difference Methods for Nonlinear ODEs
Consider the nonlinear boundary-value problem y″=−(y′)^2−y+ln(x), 1≤x≤2, y(1)=0, y(2)=ln(2) with h=0.25.
Use the Nonlinear Finite-Difference method with the Newton's method to approximate the solution.
Plot graphs to compare your approximate solutions to the exact solution y=ln(x).
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problem 1. Your argument should be included in M-files as comments.)
Write down the nonlinear equation from applying the Finite-Difference method to the problem when h=0.5. Is the Newton's method necessary?
What is the size of the Jacobian matrix when h=0.1?
Why is the Jacobian matrix a tridiagonal matrix?
Final Project (A Note for Final Project): Finite Difference Methods for Parabolic Partial Differential Equations
Consider the heat equation with boundary and initial conditions given by
u_t=(1.5)u_{xx}+x^3*e^t−9x*e^t, (x,t)∈(0,1)x(0,T),
u(x,0)=x^3, x∈[0,1],
u(0,t)=0, u_x(1,t)=3e^t, t∈[0,T],
whose exact solution is u(x,t)=x^3*e^t.
Use Forward Euler's method in time and Finite Difference method in space to approximate the solution to the problem where the Neumann boundary condition is approximated using the first order approximation, u_x(1,t)≈(v_m(t)−v_{m−1}(t))/h. Obtain approximations at T=Nk=0.5 and determine max_{i}|u(i*h,N*k)−w_i^N| for h=1/10,1/20,1/40,1/80,1/160. Choose k so that k/h^2=1/3. Determine the order of accuracy in space.
Repeat Problem 1 using the second order approximation u_x(1,t)≈(v_{m+1}(t)−v_{m−1}(t))/(2h) with a ghost point x_{m+1}. Determine the order of accuracy in space.
Use Crank-Nicolson method in time and Finite difference method in space to repeat Problem 1. Choose k=h. Determine the order of accuracy in space.
Discuss on the following questions. (Your argument should be consistent with the results that you obtained from the problems. Your argument should be included in M-files as comments.)
What is the order of accuracy in Problem 1? Why do you think that you obtain the order of accuracy?
What is the order of accuracy in Problem 2? Why do you think that you obtain the order of accuracy?
What is the order of accuracy in Problem 3? Why do you think that you obtain the order of accuracy?