Programming assignment #1. Solutions and Discussion

Slides:



Advertisements
Similar presentations
Partial Differential Equations
Advertisements

Computational Modeling for Engineering MECN 6040
P. Venkataraman Mechanical Engineering P. Venkataraman Rochester Institute of Technology DETC2013 – 12269: Continuous Solution for Boundary Value Problems.
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 19 Solution of Linear System of Equations - Iterative Methods.
NAE C_S2001 FINAL PROJECT PRESENTATION LASIC ISMAR 04/12/01 INSTRUCTOR: PROF. GUTIERREZ.
Partial differential equations Function depends on two or more independent variables This is a very simple one - there are many more complicated ones.
© 2011 Autodesk Freely licensed for use by educational institutions. Reuse and changes require a note indicating that content has been modified from the.
Scientific Computing Matrix Norms, Convergence, and Matrix Condition Numbers.
Dr. Hala Moushir Ebied Faculty of Computers & Information Sciences
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 31.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
Solving Scalar Linear Systems Iterative approach Lecture 15 MA/CS 471 Fall 2003.
Unit 4: Modeling Topic 6: Least Squares Method April 1, 2003.
Scientific Computing Partial Differential Equations Poisson Equation.
Boundary Value Problems and Least Squares Minimization
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.
Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
1 Markov Decision Processes Infinite Horizon Problems Alan Fern * * Based in part on slides by Craig Boutilier and Daniel Weld.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Elliptic PDEs and Solvers
Part 3 Chapter 12 Iterative Methods
The Power Method for Finding
Finite Element Method. History Application Consider the two point boundary value problem.
1 Spring 2003 Prof. Tim Warburton MA557/MA578/CS557 Lecture 32.
Programming assignment # 3 Numerical Methods for PDEs Spring 2007 Jim E. Jones.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
Copyright © 2009 Pearson Education, Inc. Chapter 16 Random Variables.
List manipulation;curve fitting
Algorithms and Programming
ECE 476 POWER SYSTEM ANALYSIS
EEE 431 Computational Methods in Electrodynamics
Chapter 7. Classification and Prediction
ECE 476 Power System Analysis
بسم الله الرحمن الرحيم.
Solving Linear Systems Ax=b
Gauss-Siedel Method.
Numerical Analysis Lecture12.
The Maximum Likelihood Method
Haim Kaplan and Uri Zwick
Announcements HW4 due today (11:59pm) HW5 out today (due 11/17 11:59pm)
Iterative Methods Good for sparse matrices Jacobi Iteration
Lecture 19 MA471 Fall 2003.
Autar Kaw Benjamin Rigsby
Craig Schroeder October 26, 2004
Hidden Markov Models Part 2: Algorithms
ENGG 1801 Engineering Computing
Fundamentals of Programming
Scientific Computing Partial Differential Equations Implicit Solution of Heat Equation.
Numerical Analysis Lecture13.
6.5 Taylor Series Linearization
MATH-321 In One Slide MATH-321 & MATLAB Command.
دانشگاه صنعتي اميركبير
CSE 373: Data Structures & Algorithms
topic4: Implicit method, Stability, ADI method
Ch. 2: Getting Started.
Numerical Methods on Partial Differential Equation
Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson Oct 14, 2014 slides6b.ppt 1.
Programming assignment # 3 Numerical Methods for PDEs Spring 2007
topic4: Implicit method, Stability, ADI method
Stencil Pattern ITCS 4/5145 Parallel computing, UNC-Charlotte, B. Wilkinson StencilPattern.ppt Oct 14,
Fixed- Point Iteration
Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
Numerical Analysis Lecture11.
Linear Algebra Lecture 16.
Home assignment #3 (1) (Total 3 problems) Due: 12 November 2018
Presentation transcript:

Programming assignment #1. Solutions and Discussion Programming assignment #1 Solutions and Discussion Numerical Methods for PDEs Spring 2007 Jim E. Jones

The Problem PDE solution

Coding issues: storing the approximate solution u Its easiest to store u in a two-dimensional array big enough to hold the known boundary values as well. This will allow the same update formulas to work at all grid points. There is no need for special code to deal with boundary cases. We need to work out the indexing of this array and how it relates to the physical space We can chose to have an input parameter related to the mesh size (h) or grid size (n) Let’s chose n = the number of intervals in x direction. Since we just dealt with square grids, this is also the number of intervals in y.

Example: n=8 Index Space Physical Space (x=2.0,y=2.0) (i=9,j=9)

Example: n=8 Index Space Physical Space (x=2.0,y=2.0) (i=9,j=9) Physical Space Index Space This differs from what we had in previous lecture because we now have indexing from 1 (FORTRAN, MATLAB) rather than 0 (C). (x=1.0,y=1.0) (i=1,j=1)

Example: n=8 h=1/n, n=8 (x=2.0,y=2.0) (i=9,j=9) (x=1.0+(i-1)*h,y=1.0+(j-1)*h) (i,j) h=1/n, n=8 (x=1.0,y=1.0) (i=1,j=1)

Code Outline HW1(n,tol,max_its) Load Boundary Values and RHS Gauss-Seidel Loop Loop over interior (2<j<n,2<i<n) Update u(i,j) Loop over interior Calculate max residual Convergence Check Calculate max error

Code Outline HW1(n,tol,max_its) Load Boundary Values and RHS Gauss-Seidel Loop Loop over interior (2<j<n,2<i<n) Update u(i,j) Loop over interior Calculate max residual Convergence Check Calculate max error

MATLAB code Code posted on class web site: http://my.fit.edu/~jim/classes/MTH5315S07/ Note the debugging examples. Questions on coding?

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.

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.

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?

Investigations begin … OK, so we’ve got input parameters to play with: n, controls how fine the mesh is, and tol, controls how well we solve the discrete system Au=b. We want to see the effect of these on the two outputs: gs_its, the number of Gauss-Seidel iterations required, and e_max, the infinity norm of the final, total error.

Data, data, data… GS its E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110   E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110 432 1713 3.909E-02 4.829E-02 5.004E-02 5.049E-02 1.00E-01 43 169 670 2668 4.097E-03 4.851E-03 5.019E-03 5.049E-03 1.00E-02 58 229 909 3623 2.156E-04 4.301E-04 4.889E-04 5.025E-04 1.00E-03 72 288 1147 4578 1.433E-04 8.414E-06 3.847E-05 4.761E-05 1.00E-04 87 347 1386 5534 1.826E-04 4.313E-05 7.179E-06 2.094E-06 1.00E-05 101 407 1625 6489 1.862E-04 4.756E-05 1.156E-05 2.524E-06 1.00E-06 116 466 1863 7444 1.866E-04 4.799E-05 1.200E-05 2.968E-06 1.00E-07 130 525 2102 8399 1.867E-04 4.803E-05 1.204E-05 3.012E-06 1.00E-08 145 585 2340 9355 1.205E-05 3.017E-06 1.00E-09 159 644 2579 10311

Slicing and dicing data: its vs. tol GS its   E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110 432 1713 3.909E-02 4.829E-02 5.004E-02 5.049E-02 1.00E-01 43 169 670 2668 4.097E-03 4.851E-03 5.019E-03 5.049E-03 1.00E-02 58 229 909 3623 2.156E-04 4.301E-04 4.889E-04 5.025E-04 1.00E-03 72 288 1147 4578 1.433E-04 8.414E-06 3.847E-05 4.761E-05 1.00E-04 87 347 1386 5534 1.826E-04 4.313E-05 7.179E-06 2.094E-06 1.00E-05 101 407 1625 6489 1.862E-04 4.756E-05 1.156E-05 2.524E-06 1.00E-06 116 466 1863 7444 1.866E-04 4.799E-05 1.200E-05 2.968E-06 1.00E-07 130 525 2102 8399 1.867E-04 4.803E-05 1.204E-05 3.012E-06 1.00E-08 145 585 2340 9355 1.205E-05 3.017E-06 1.00E-09 159 644 2579 10311

Number of iterations vs. tolerance

Number of iterations vs. tolerance For fixed n, each time we reduce the tolerance by an order of magnitude, the required iterations goes up by a constant amount. N=8 15 more iterations to get one more order reduction N=16 60 N=32 240 N=64 960 Looks like halving h makes the number of iterations to get an order reduction go up by 4.

Slicing and dicing data: its vs. n GS its   E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110 432 1713 3.909E-02 4.829E-02 5.004E-02 5.049E-02 1.00E-01 43 169 670 2668 4.097E-03 4.851E-03 5.019E-03 5.049E-03 1.00E-02 58 229 909 3623 2.156E-04 4.301E-04 4.889E-04 5.025E-04 1.00E-03 72 288 1147 4578 1.433E-04 8.414E-06 3.847E-05 4.761E-05 1.00E-04 87 347 1386 5534 1.826E-04 4.313E-05 7.179E-06 2.094E-06 1.00E-05 101 407 1625 6489 1.862E-04 4.756E-05 1.156E-05 2.524E-06 1.00E-06 116 466 1863 7444 1.866E-04 4.799E-05 1.200E-05 2.968E-06 1.00E-07 130 525 2102 8399 1.867E-04 4.803E-05 1.204E-05 3.012E-06 1.00E-08 145 585 2340 9355 1.205E-05 3.017E-06 1.00E-09 159 644 2579 10311

Number of iterations vs. problem size

Number of iterations vs. problem size For fixed tolerance, looks like halving h makes the number of iterations go up by 4.

A dart tossing interlude before looking at data for errors Suppose that a dart tosser has faulty vision. His failure to hit the target is due to two factors: Vision error ev: he “sees” the target shifted some distance from its actual position, so his aim is off. Skill error es: his darts can deviate from where he aims by some distance.

Vision Error He “sees” the target somewhere on a circle of radius ||ev|| centered about the true target T. T

Vision Error He aims at the seen target t*. The vision error is the distance between T and t*. T t*

Skill Error He throws at t*, but due to limited skill, he hits at t, somewhere on a circle of radius ||es|| centered at t*. T t* t

Skill Error The total error, the amount by which his toss misses the target, is bounded by the sum of the two errors. Note: he may get lucky and errors cancel. T t* t

How to improve

How to improve Get new glasses Practice tossing darts

Back to the problem We care about is the solution to the PDE, upde. We approximately solve a discrete problem Au=b. 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.

Slicing and dicing data: error vs. tol GS its   E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110 432 1713 3.909E-02 4.829E-02 5.004E-02 5.049E-02 1.00E-01 43 169 670 2668 4.097E-03 4.851E-03 5.019E-03 5.049E-03 1.00E-02 58 229 909 3623 2.156E-04 4.301E-04 4.889E-04 5.025E-04 1.00E-03 72 288 1147 4578 1.433E-04 8.414E-06 3.847E-05 4.761E-05 1.00E-04 87 347 1386 5534 1.826E-04 4.313E-05 7.179E-06 2.094E-06 1.00E-05 101 407 1625 6489 1.862E-04 4.756E-05 1.156E-05 2.524E-06 1.00E-06 116 466 1863 7444 1.866E-04 4.799E-05 1.200E-05 2.968E-06 1.00E-07 130 525 2102 8399 1.867E-04 4.803E-05 1.204E-05 3.012E-06 1.00E-08 145 585 2340 9355 1.205E-05 3.017E-06 1.00E-09 159 644 2579 10311

Number of error vs. tolerance

Number of error vs. tolerance In this region the algebraic error dominates. Reducing tolerance reduces error by similar factor.

Relationship between tolerance and algebraic error We’re looking for the solution u* so that After completing a Gauss-Seidel iteration, we have an approximate solution ugs. One computable measure of the quality of the approximation is its residual. The residual is not the algebraic error, but is related to it by the matrix A.

Number of error vs. tolerance In this region the discretization error dominates. Reducing tolerance further doesn’t help.

Slicing and dicing data: error vs. n GS its   E max Tol n=8 n=16 n=32 n=64 1.00E+00 29 110 432 1713 3.909E-02 4.829E-02 5.004E-02 5.049E-02 1.00E-01 43 169 670 2668 4.097E-03 4.851E-03 5.019E-03 5.049E-03 1.00E-02 58 229 909 3623 2.156E-04 4.301E-04 4.889E-04 5.025E-04 1.00E-03 72 288 1147 4578 1.433E-04 8.414E-06 3.847E-05 4.761E-05 1.00E-04 87 347 1386 5534 1.826E-04 4.313E-05 7.179E-06 2.094E-06 1.00E-05 101 407 1625 6489 1.862E-04 4.756E-05 1.156E-05 2.524E-06 1.00E-06 116 466 1863 7444 1.866E-04 4.799E-05 1.200E-05 2.968E-06 1.00E-07 130 525 2102 8399 1.867E-04 4.803E-05 1.204E-05 3.012E-06 1.00E-08 145 585 2340 9355 1.205E-05 3.017E-06 1.00E-09 159 644 2579 10311

Number of error vs. problem size

Number of error vs. problem size For small tolerance, where error is dominated by discretization error, looks like halving h makes the total error number do down 4.

Investigations conclude: general things we saw An order of magnitude reduction in tolerance requires a fixed number of additional iterations. As h gets smaller, iterations increase like h-2 As we decrease the tolerance, the total error is reduced by a similar factor until error is dominated by discretization error. Further reductions in the tolerance are pointless. As h gets smaller, the discretization error decreases like h2