Numerical Solutions to Civil Engineering Problems PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides an introduction to numerical solutions for civil engineering problems, focusing on the first semester of the academic year 2023-2024. It covers topics including mathematical modeling, conservation laws, numerical methods, programming, and different types of errors, preparing the reader for further study.
Full Transcript
INTRODUCTION Numerical Solutions to Civil Engineering Problems 1st Semester AY 2023-2024 OUTLINE Ø Mathematical Model -- Conservation Laws Ø Numerical Methods Ø Programming Ø Errors -- Significant Figures -- Accuracy and Precision -- Error Definitions -- Error Types A...
INTRODUCTION Numerical Solutions to Civil Engineering Problems 1st Semester AY 2023-2024 OUTLINE Ø Mathematical Model -- Conservation Laws Ø Numerical Methods Ø Programming Ø Errors -- Significant Figures -- Accuracy and Precision -- Error Definitions -- Error Types A large egg (M ≈ 67 g) at room temperature (Tegg = 21 °C) in boiling water (Twater = 100 °C) will take 3.6 minutes to reach a temperature Tyolk = 63 °C when soft-boiled, and 8.2 minutes to reach a temperature Tyolk = 80 °C when hard-boiled. Source: https://newton.ex.ac.uk/teaching/CDHW/egg/ A large egg (M ≈ 67 g) at room temperature (Tegg = 21 °C) in boiling water (Twater = 100 °C) will take 3.6 minutes to reach a temperature Tyolk = 63 °C when soft-boiled, and 8.1 minutes to reach a temperature Tyolk = 80 °C when hard-boiled. Source: https://newton.ex.ac.uk/teaching/CDHW/egg/ egg image: Horst Frank (CC BY-SA 3.0) MATHEMATICAL MODEL Dependent æ independent forcing ö = fç , parameters, ÷ variable è variables functions ø Dependent variable – Reflects the behavior or state of the system Independent variables – Dimensions along which the system’s behavior is being determined MATHEMATICAL MODEL Dependent æ independent forcing ö = fç , parameters, ÷ variable è variables functions ø Parameters – Reflects the system’s properties and composition Forcing functions – External influences acting upon the system MATHEMATICAL MODEL Ø The actual mathematical expression can range from a single algebraic relationship to large complicated sets of differential equations. EXAMPLE: Newton’s 2nd Law of Motion F F = ma Þ a= -- Describes a natural process in m mathematical terms What if we wanted to -- Represents an idealization and predict the velocity of a simplification of reality free-falling body near -- Yields reproducible results and the Earth’s surface as a can be used for predictive function of time? purposes MATHEMATICAL MODEL *The mathematical model becomes: F dv F a= Þ = m dt m Ø The net force is expressed in terms of measurable variables and parameters. FD = mg ( gravity ) F = FD + FU FU = -cd v 2 ( air resistance ) MATHEMATICAL MODEL *The mathematical model becomes: dv cd 2 =g- v dt m Ø Solution (if jumper is initially at rest): gm æ gcd ö v (t ) = tanhç t÷ Analytical or cd ç m ÷ closed-form solution è ø *However, most mathematical models cannot be solved exactly… MATHEMATICAL MODEL CONSERVATION LAWS Change = Increases - Decreases MATHEMATICAL MODEL CONSERVATION LAWS NUMERICAL METHODS Why study Numerical Methods? Ø These are techniques by which Math problems are formulated in order to be solved using arithmetic and logical operations -- Reduces higher Math to basic arithmetic operations; reinforces understanding of Math Ø Greatly expands the types of problems to be solved -- Large system of equations, nonlinear systems’ complicated geometries, etc. NUMERICAL METHODS Why study Numerical Methods? Ø Efficient way to learn how to use computers -- Numerical methods are designed for computer implementation -- Allows the designing of programs/scripts to solve problems involving Math models NUMERICAL METHODS PREVIEW OF TOPICS Ø Root-finding (Nonlinear systems) -- Solve for x so that f(x) = 0. NUMERICAL METHODS PREVIEW OF TOPICS Ø Linear Algebraic Equations -- Given the a’s and the b’s, solve for the x’s. a11 x 1 + a12 x2 = b1 a21 x 1 + a22 x2 = b2 NUMERICAL METHODS PREVIEW OF TOPICS Ø Curve fitting Ø Integration Ø Differentiation NUMERICAL METHODS PREVIEW OF TOPICS Ø Differential Equations -- Given dy Dy = = f (t , y ) dt Dt Solve for y as a function of t. y i + 1 = y i + f ( ti , y i ) Dt PROGRAMMING Ø Process of creating a set of instructions that tell a computer how to perform a task Ø Done for automation purposes Ø “Garbage in, garbage out” / GIGO PROGRAMMING LANGUAGES/SOFTWARES Ø C/C++, Java, SQL, VBA, Python Ø Mathcad, MATLAB, Octave, Maple, Mathematica Source: https://www.boredpanda.co m/14-year-old-draws-comics- on-whiteboard-jakes-door/ PROGRAMMING TERMINOLOGIES Ø Algorithm -- Sequence of logical steps required to perform a specific task Ø Pseudocode -- English description of a program Ø Flowchart -- Visual/graphical representation of a program PROGRAMMING EXAMPLE: Write a computer program to calculate sin(x) using the following Taylor series expansion: ( ) 2n+1 n ¥ -1 x 3 x 5 x 7 x sin( x ) = å = x - + - + n=0 (2n + 1 )! 3! 5! 7! PROGRAMMING Algorithm Ø Enter x and the number of terms to use, N. Ø Calculate sin(x) using the Taylor series. Ø Print the result. PROGRAMMING Pseudocode Flowchart PROGRAMMING PROGRAMMING ERRORS (BUGS) Ø Syntax error -- Will not compile. Compiler will help you to find it. -- (e.g. Writing primtf instead of printf) Ø Run-time error -- Will compile but may stop running at some point. -- (e.g. Division by zero) PROGRAMMING PROGRAMMING ERRORS (BUGS) Ø Logical error -- Will compile and run, but the result is wrong. -- (e.g. From the previous example, all terms of sin(x) are positive) *Run-time and logical error need careful debugging of the program. PROGRAMMING NOTES: Ø For clarity: -- Put comments to explain variables, purpose of code segments, etc. Ø For testing: -- Run with typical data. -- Run with unusual but valid data. -- Run with invalid data to check error handling. PROGRAMMING NOTES: Ø Refresh your programming knowledge. Ø Find an introductory level programming book in the library/internet; check for tutorials. Ø Approach the problem through the algorithm-pseudocode-computer code link. Ø Practice at home (or during your free time). Ø Do not be afraid of programming; try to feel the power of it. =) ERRORS SIGNIFICANT FIGURES Ø Digits of the number which are known to be correct Ø Designate the reliability of a number *The number of significant figures to be used in a number depends on the origin of the number. EXAMPLE: Calculation of the area of a circle A = p D2 / 4 ERRORS ACCURACY and PRECISION Ø Computers used to obtain numerical solution are imperfect tools; limited to represent the magnitudes and precision of numbers. Ø Errors from calculations (and measurements) can be characterized with regard to their accuracy AND precision. ERRORS Ø Precision -- How closely a computed (individual) or measured values agree with each other Ø Accuracy -- How closely a computed or measured value agrees with the true value ERRORS Imprecision Ø Also called uncertainty Ø Magnitude of the scatter Inaccuracy Ø Also called bias Ø Systematic deviation from the truth *ERROR = Imprecision + Inaccuracy ERRORS NOTES: Ø Precision is governed by the number of digits being carried in the numerical calculations. Ø Accuracy is governed by the errors in the numerical approximation. ERROR DEFINITIONS TRUE ERROR (Et) Ø Exact/absolute value of the error Ø Doesn’t consider order of magnitude of the value under examination Et = True Value - Approximation ERROR DEFINITIONS TRUE ERROR (Et) Ø The error can be normalized to the true value -- Fractional Relative True Error True Value - Approximation et = True Value -- Percentage Relative True Error True Value - Approximation et = ´ 100% True Value ERROR DEFINITIONS APPROXIMATE ERROR (Ea) Ø In actual situations, true value is rarely available Ø Error estimates (or approximations) are determined in absence of knowledge regarding the true value Approximate Error ( E A ) ea = Approximation ERROR DEFINITIONS APPROXIMATE ERROR (Ea) Ø Utilize the best available estimate of the true value, then normalize -- Fractional Relative Approximate Error Present Approx. - Previous Approx. ea = Present Approx. -- Percentage Relative Approximate Error Present Approx. - Previous Approx. ea = ´ 100% Present Approx. ERROR DEFINITIONS NOTES: Ø Many numerical methods work in an iterative* fashion, thus there should be a stopping criterion for these methods. Ø The process stops when the error level drops below a certain specified tolerance value (εs). ea < es *A procedure in which repetition of a sequence of operations yields results successively closer to a desired result. ERROR DEFINITIONS SCARBOROUGH CRITERION (1966) Ø If the tolerance is selected to be e s = 0.5 ´ 10 % 2-n then the approximation is guaranteed to be correct to at least n significant figures. ERROR TYPES ROUND-OFF ERROR Ø Computers cannot -- Represent some quantities exactly * Conversion from base-10 to base-2 number system may create problems * Numbers like π or 1/3 -- Use infinitely many digits to store numbers * Single precision (7-8 digits) vs. Double precision (15-16 digits) ERROR TYPES ROUND-OFF ERROR Ø Sources of Round-off Errors -- Subtractive cancellation * Subtracting two nearly equal numbers -- Large (arithmetic) computations * Computations are often interdependent; consider cumulative effect -- Adding a large and a small number * Usually occur in infinite series calculation * Sum the series in reverse order ERROR TYPES ROUND-OFF ERROR Ø Sources of Round-off Errors -- Smearing * Individual terms in a summation are larger than the summation itself * Example: Series of mixed signs -- Calculation of inner products n åx y i =1 i i =x 1 y 1 + x 2 y 2 + + x n y n ERROR TYPES ROUND-OFF ERROR Ø These errors cannot be totally eliminated, but clever algorithms may help to minimize them. TRY AT HOME: Add 0.1 thousand times. Use both single and double precision. Compare the results. =) ERROR TYPES TRUNCATION ERROR Ø Result from using an approximation in place of an exact mathematical procedure EXAMPLE: Calculating the sine of a number using finite number of terms from the infinite series will result in truncation error. ERROR TYPES TRUNCATION ERROR ( ) 2n+1 n ¥ -1 x 3 5 x x7 x sin( x ) = å = x - + - + n=0 (2n + 1 )! 3! 5! 7! At x = π/2: ERROR TYPES OVERVIEW OF TAYLOR SERIES Ø Taylor Series is used to evaluate a function at one point, using the value of the function and its derivatives at another point. Known: f ( x i ) , f ' ( x i ) , f '' ( x i ) , etc. Unknown: f ( x i +1 ) 0 Order Approx.: f ( x i + 1 ) » f ( x i ) th ERROR TYPES OVERVIEW OF TAYLOR SERIES Known: f ( x i ) , f ' ( x i ) , f '' ( x i ) , etc. Unknown: f ( x i +1 ) st 1 Order Approx.: df Df f ( x i + 1 ) - f ( x i ) h = x i +1 - x i f '( x i ) = » = dx Dx h \ f ( x i + 1 ) » f ( x i ) + hf ' ( x i ) ERROR TYPES OVERVIEW OF TAYLOR SERIES Ø More derivatives can be added to capture more of the function’s curvature. f '' ( x i ) f ( n) ( x i ) hn + R f ( x i +1 ) = f ( x i ) + f '( x i ) h + h + + 2 n 2! n! -- nth order Taylor series approximation of f(xi+1) -- Being an infinite series, an equal sign replaces the approximate sign -- The approximation improves as h decreases ERROR TYPES OVERVIEW OF TAYLOR SERIES Ø More derivatives can be added to capture more of the function’s curvature. f '' ( x i ) f ( n) ( x i ) hn + R f ( x i +1 ) = f ( x i ) + f '( x i ) h + h + + 2 n 2! n! -- Rn is the remainder (truncation error) term n+1 h Rn = f ( n+1 ) (x ) where x i < x < x i + 1 ( n + 1 )! ERROR TYPES OVERVIEW OF TAYLOR SERIES Ø nth order Taylor series expansion will be exact if f(x) is an nth order polynomial Ø For practical purposes, inclusion of only a few terms will result in an approximation that is close enough to the true value -- Truncation error can be controlled (h) -- Choice on how far away from x to evaluate f(x) ERROR TYPES OVERVIEW OF TAYLOR SERIES n+1 h Rn = f ( n+1 ) (x ) ( n + 1 )! \ Rn = O ( h n+1 ) Ø Truncation error is of the order of hn+1 Ø Useful in judging the comparative error of numerical methods based on Taylor series expansions ERROR TYPES TOTAL NUMERICAL ERROR Ø Summation of the truncation and round-off errors Choose a large step size to decrease the amount of calculations and round off errors without incurring the penalty of a large truncation error. ERROR TYPES OTHER SOURCES OF ERRORS Ø Gross Errors/Blunders Ø Model Errors Ø Data Uncertainty