530 likes | 1.63k Views
Numerical Analysis. Intro to Scientific Computing. Numerical Methods. Numerical Methods: Algorithms that are used to obtain numerical solutions of a mathematical problem. Why do we need them? 1. No analytical solution exists, 2. An analytical solution is difficult to obtain
E N D
Numerical Analysis Intro to Scientific Computing
Numerical Methods Numerical Methods: Algorithms that are used to obtain numerical solutions of a mathematical problem. Why do we need them? 1. No analytical solution exists, 2. An analytical solution is difficult to obtain or not practical.
Why use Numerical Methods? • To solve problems that cannot be solved exactly
Introduction 1. Introduction to numerical methods for engineering as a general and fundamental tool for all engineering disciplines. We plan to cover (almost) the main topics of numerical analysis. 2. We will use commercial software widely used in science and engineering: MATLAB and Excel. 3. We will illustrate and discuss how numerical methods are used in practice. We will consider examples from Engineering.
Our choice for this course: Matlab • Matlab: numerical development environment. • Easy and fast programming • data types (vectors, matrices, complex numbers) • Complete functionality • Powerful toolkits • Campus license (from home: need Internet conn.) • But: €xpensive! • Alternatives: • Matlab student license (without toolkits) • Octave (free, Windows, Linux): www.octave.org • SciLab (free, Windows, Linux): www.scilab.org
Matlab basics • Variables are just assigned (no typedef needed) a=42 s= 'test' • basic operators ( + - * / \ ^) 5/2 ans = 2.5000ans is a system variable • functions (help elfun) sqrt(3), sin(pi), cos(0) pi is a system variable • display & clear variables disp(a), disp('hello') display value of a , “hello” who, whosshow all defined variables clear aclear variable a clearclear all variablesarrow up/down keys recall your last commands
Matlab examples • Variables & Operatorsa=5*(2/3)+3^2 result is showna=2/4 + 4\2 ; result is not showna value of a is shown • Elementary functions overview: doc elfunabs(-1), sqrt(2) tan(0), cos(0), acos(1) … exp(2), log(1), log10(1) … • Roundinground(2.3), round(2.5) 2 3 • floor(5.7), floor(-1.2) 5 -2 towards smallerceil (1.1), ceil(-2.7) 2 -2 towards largerfix(1.7), fix (-2,7) 1 -2 towards 0 • Complex numbers(2+3i) * (1i) -3+2inorm(1+1i) 1.4142
Example of Solving an Engineering Problem http://numericalmethods.eng.usf.edu
Course overview • Finding roots of functions of one variable • Approximation, errors, and precision. • System of linear equations • Numerical integration and differentiation.
Introduction Why are Numerical Methods so widely used in Engineering? • Engineers use mathematical modeling (equations and data) to describe and predict the behavior of systems. • Closed-form (analytical) solutions are only possible and complete for simple problems (geometry, properties, etc.). • Computers are widely available, powerful, and (relatively) cheap. • Powerful software packages are available (special or general purpose).
Applications of Numerical Methods in Engineering • Communication/power • Network simulation • Train and traffic networks • Computational Fluid Dynamics (CFD): • Weather prediction • Groundwater & pollutant movement
Electronic Communication by e-mail • Computer assignments will be submitted as attachments via e-mail: • y.fouad@alexu.edu.eg • Text files, Excel & MATLAB documents as attachments. • documents will be distributed via the AAST web page.
Useful info • Course website: • MATLAB instructions: http://math.gmu.edu/introtomatlab.htm • Mathworks, the creator of MATLAB: http://www.mathworks.com • OCTAVE = free MATLAB clone Available for download at http://octave.sourceforge.net/
Mathematical modeling Computational problems:attack strategy • Develop mathematical model (usually requires a combination of math skills and some a priori knowledge of the system) • Come up with numerical algorithm (numerical analysis skills) • Implement the algorithm (software skills) • Run, debug, test the software • Visualize the results • Interpret and validate the results
Computational problems:well-posedness • The problem is well-posed, if (a) solution exists (b) it is unique (c) it depends continuously on problem data Simplification strategies: Infinite finite Nonlinear linear High-order low-order Only approximate solution can be obtained this way!
Sources of numerical errors • Before computation • modeling approximations • empirical measurements, human errors • previous computations • During computation • truncation or discretization • Rounding errors • Perturbations during computation may be amplified by algorithm Abs_error = approx_value – true_value Rel_error = abs_error/true_value Approx_value = (true_value)x(1+rel_error) Cannot be controlled Can be controlled through error analysis
Representing Real Numbers • You are familiar with the decimal system: • Decimal System: Base = 10 , Digits (0,1,…,9) • Standard Representations:
Normalized Floating Point Representation • Normalized Floating Point Representation: • Scientific Notation: Exactly one non-zero digit appears before decimal point. • Advantage:Efficient in representing very small or very large numbers.
Binary System • Binary System: Base = 2, Digits {0,1}
S Exponent8 Fraction23 S Exponent11 Fraction52 (continued) IEEE 754 Floating-Point Standard • Single Precision (32-bit representation) • 1-bit Sign + 8-bit Exponent + 23-bit Fraction • Double Precision (64-bit representation) • 1-bit Sign + 11-bit Exponent + 52-bit Fraction
Calculator Example • Suppose you want to compute: 3.578 * 2.139 using a calculator with two-digit fractions 3.57 * 2.13 = 7.60 7.653342 True answer:
Stability • Algorithm is stable if result produced is relatively insensitive to perturbations during computation • Stability of algorithms is analogous to conditioning of problems • For stable algorithm, effect of computational error is no worse than effect of small data error in input
Accuracy • Accuracy : closeness of computed solution to true solution of problem • Accuracy depends on conditioning of problem as well as stability of algorithm
48.9 Significant Digits - Example
Rounding and Chopping • Rounding: Replace the number by the nearest machine number. • Chopping: Throw all extra digits.
Error Definitions – True Error Can be computed if the true value is known:
Notation We say that the estimate is correct to n decimal digits if: We say that the estimate is correct to n decimal digits rounded if:
Solution of Nonlinear Equations • Some simple equations can be solved analytically: • Many other equations have no analytical solution:
Methods for Solving Nonlinear Equations • Bisection Method • Newton-Raphson Method • Secant Method
Methods for Solving Systems of Linear Equations • Gaussian Elimination • Gaussian Elimination with Scaled Partial Pivoting • Gauss- Jordan
Integration • Some functions can be integrated analytically:
Methods for Numerical Integration • Trapezoid Method • Simpson Method • Mid-point method