Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Similar presentations


Presentation on theme: "Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones."— Presentation transcript:

1 Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones

2 The Problem Taken from Burden and Faires, Numerical Analysis, Ch12

3 The Problem PDE Boundary Conditions

4 Finite difference discretization based on Taylor’s approximation.
(2,2) Equation for each grid point (x,y) Error in approximation is determined by the mesh size h. Difference between differential solution and algebraic solution goes to zero as h does. (1,1)

5 Solving the linear system
Last lecture we did a simple example, solving the linear system in MATLAB This involved a one-dimensional ordering the nine interior unknowns. If the system is large, an iterative solver may be faster than the direct methods in MATLAB

6 Two dimensional ordering of the grid points
(x=2.0,y=2.0) (i=8,j=8) Physical Space Index Space (x=1.0,y=1.0) (i=0,j=0)

7 Two dimensional ordering of the grid points
(x=2.0,y=2.0) (i=8,j=8) (x=1.25,y=1.375) (i=2,j=3) (x=1.0,y=1.0) (i=0,j=0)

8 Two dimensional ordering of the grid points
(x=2.0,y=2.0) (i=8,j=8) (x=1.0+i*h,y=1.0+j*h) (i,j) h=1/n, n=8 (x=1.0,y=1.0) (i=0,j=0)

9 Finite difference discretization based on Taylor’s approximation.
Equation for each grid point (x,y)

10 Solving the linear system using Gauss-Seidel method
Begin with an initial guess for the unknown u’s. If you don’t have anything better, guess u=0 at all unknown grid points. Do Gauss-Seidel iterations Loop over unknown grid points Change the u value at the current grid point to satisfy the equation in A for this grid point Check to see if the u-values are close enough to the true solution of the linear system. If they are STOP; otherwise, do another Gauss-Seidel iteration.

11 Loop over grid points: Lexicalgraphic ordering
1

12 Loop over grid points 1 2

13 Loop over grid points 1 2 3

14 Loop over grid points for j=1,n-1 for i=1,n-1 8 1 2 3 4 5 6 7

15 Gauss-Seidel update at point (I,J)
Change u at i,j to satisfy its equation

16 Gauss-Seidel update at point (I,J)
Change u at i,j to satisfy its equation Note: With this simple equation, there is no need to store A. Its mostly zeros anyway.

17 When to stop? We’re looking for the solution u* so that
After completing a Gauss-Seidel iteration, we have an approximate solution u. One computable measure of the quality of the approximation is its residual.

18 When to stop? Stop when the residual is small enough, i.e.
Think of r as a vector with (n-1)x(n-1) entries, one for each interior point. You can choose the norm, one choice is the infinity norm. For an vector with m components, the infinity norm is:

19 How good is the answer? After we iterate far enough to meet the stopping criterion, we have our approximate solution ugs. The difference between the true algebraic solution and our approximate solution is called the algebraic error.

20 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The difference between the true PDE solution and the true algebraic solution is called the discretization error.

21 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The difference between the true PDE solution and the true algebraic solution is called the discretization error. Interpret upde as a vector. The true PDE solution evaluated at each grid point.

22 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The total error is the difference between the true PDE solution and our approximate solution.

23 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The error is the difference between the true PDE solution and our approximate solution. The total error is the sum of the discretization error and the algebraic error.

24 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The error is the difference between the true PDE solution and our approximate solution. We can make ed smaller by making h smaller, and thus using a finer mesh with more grid points.

25 How good is the answer? What we presumably really care about is the solution to the PDE, upde. The error is the difference between the true PDE solution and our approximate solution. We can make ea smaller by making tol smaller, and thus doing more Gauss Seidel iterations.

26 The Problem PDE solution

27 Assignment #1 Due Jan. 29 Code up the finite difference method using Gauss-Seidel to solve the linear system as discussed in these slides. You need to be able to run different problem sizes, so write your code with h (or n) as an input argument. You should also include the Gauss-Seidel stopping criterion tol as an input argument. You can write it for general right hand side and boundary conditions, or hard code the specific example. Do not store the A matrix. Verify that your code is working – do a small problem for which you know the answer.

28 Assignment #1 Due Jan. 29 Run your code for the example problem.
Experiment by varying h and tol to see how they effect the number of iterations required and the infinity norm of the final, total error. Pick at least 3 values of h and 3 values of tol. I suggest h=.1,.05,.025 and tol=10e-2,10e-3,10e-4 this makes 9 runs total. Make table that includes the number of Gauss-Seidel iterations required for each run. Make table that includes the infinity norm of the final, total error for each run.

29 Assignment #1 Due Jan. 29 From your table of results, answer these questions: For fixed tolerance, how does the number of iterations depend on h? If h is halved does the number of iterations go up or down? By what factor? How does the error depend on h? If h is halved does the error go up or down? By what factor?


Download ppt "Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones."

Similar presentations


Ads by Google