Department of Mathematical Sciences. Numerical Analysis

Department of Mathematical Sciences. Numerical Analysis

Department of Mathematical Sciences. Numerical Analysis MATLAB Projects August 8, 2020 Authors Dr. Xu Numerical Analysis MATLAB Projects Department of Mathematical Sciences Lincoln University Student's Name : Student ID : Instructor : In this brief tutorial we will study basic MATLAB. The main goals of this tutorial are to introduce basic operations, basic plotting, linear algebra functions and basic MATLAB programming. We give a word of caution that this only an introduction and as the student works with this software the student will have the need to learn much of MATLAB on his own. To this we recommend the extensive documentation that can be found online and within the software. Further, if the documentation is not clear there is a vast amount of literature about MATLAB in the form of books, tutorials, webpage etc. Wish you enjoy it! Contents 1 Scientific Computing 6 1.1 Approximations in Scientific Computation . .6 1.1.1 Tutorial . .6 1.1.2 Examples . 10 1.1.3 Homework . 14 1.2 Computer Arithmetic . 15 1.2.1 Tutorial . 15 1.2.2 Examples . 19 1.2.3 Homework . 21 2 Systems of Linear Equations 22 2.1 Linear Systems . 22 2.1.1 Tutorial . 22 2.1.2 Examples . 24 2.1.3 Homework . 26 2.2 Norms and Condition Numbers . 27 2.2.1 Tutorial . 27 2.2.2 Examples . 32 2.2.3 Homework . 34 2.3 Solving Linear Systems . 35 2.3.1 Tutorial . 35 2.3.2 Examples . 39 2.3.3 Homework . 43 2.4 Iterative Method for Linear Systems . 44 2.4.1 Tutorial . 44 2.4.2 Homework . 45 3 Nonlinear Equations 46 3.1 Nonlinear Equations . 46 3.1.1 Tutorial . 46 3.1.2 Examples . 48 3.2 Nonlinear Equations in One Dimension . 50 3.2.1 Tutorial . 50 3.2.2 Examples . 53 3.2.3 Homework . 56 4 Interpolation 58 4.1 Interpolation . 58 4.1.1 Tutorial . 58 4.2 Polynomial Interpolation . 60 4.2.1 Tutorial . 60 4.2.2 Examples . 67 4.2.3 Homework . 70 4.3 Piecewise Interpolation . 71 4.3.1 Tutorial . 71 4.3.2 Examples . 73 4.3.3 Homework . 75 Preface MATLAB (matrix laboratory) is a multi-paradigm numerical computing environ- ment and proprietary programming language developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. 1 Scientific Computing 1.1 Approximations in Scientific Computation 1.1.1 Tutorial 1. Introduction Numerical analysis is concerned with the design and analysis of algorithms for solving mathematical problems that arise in computational science and engineering. For this reason, numerical analysis has more recently become known as scientific computing. Nu- merical analysis is distinguished from most other parts of computer science in that it deals with quantities that are continuous, as opposed to discrete. It is concerned with functions and equations whose underlying variables-time, distance, velocity, temperature, density, pressure, stress, and the like-are continuous in nature. Most of the problems of continuous mathematics (for example, almost any problem involv- ing derivatives, integrals, or nonlinearities) cannot be solved, even in principle, in a finite number of steps and thus must be solved by a (theoretically infinite) iterative process that ultimately converges to a solution. In practice, of course, one does not iterate forever, but only until the answer is approximately correct, \close enough" to the desired result for practical purposes. Thus, one of the most important aspects of scientific computing is finding rapidly convergent iterative algorithms and assessing the accuracy of the resulting approximation. Consequently, a second factor that distinguishes numerical analysis is its concern with approximations and their effects. Many solution techniques involve a whole series of approximations of various types. Even the arithmetic used is only approximate, for digital computers cannot represent all real numbers exactly. 2. Sources of Approximation There are many sources of approximation or inexactness in computational science. Some of these occur even before computation begins: • Modeling: Some physical features of the problem or system under study may be simplified or omitted. • Empirical measurements: Laboratory instruments have finite precision. Their accuracy may be further limited by small sample size, or readings obtained may be subject to random noise or systematic bias • Previous computations: Input data may have been produced by a previous step whose results were only approximate. These systematic approximations that occur during computation include: • Truncation or discretization: Some features of a mathematical model may be omitted or simplified (e.g., replacing a derivative by a difference quotient or using only a finite number of terms in an infinite series). • Rounding: The computer representation of real numbers and arithmetic operations upon them is generally inexact. The accuracy of the final results of a computation may reflect a combination of any or all of these approximations, and the resulting perturbations may be amplified or magnified by the nature of the problem being solved or the algorithm being used, or both. The study of the effects of such approximations on the accuracy and stability of numerical algorithms is traditionally called error analysis. 3. Truncation Error and Rounding Error Computational error (that is, error made during the computation) can be subdivided into truncation (or discretization) error and rounding error: • Truncation error (produced by truncating a series, approximations using polyno- mial) is the difference between the true result (for the actual input) and the result that would be produced by a given algorithm using exact arithmetic. • Rounding error (inexact representation of real numbers)is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. By definition, computational error is simply the sum of truncation error and rounding error. 4. Absolute Error and Relative Error The significance of an error is obviously related to the magnitude of the quantity being measured or computed. The concepts of absolute error and relative error, which are defined as follows: Absolute error = approximate value − true value approximate value − true value Relative error = × 100% true value Absolute error = × 100% true value We do not usually know the true value; if we did, we would not need to bother with approximating it. Thus, we will usually merely estimate or bound the error rather than compute it exactly, because the true value is unknown. For this same reason, relative error is often taken to be relative to the approximate value rather than to the true value, as in the definition. A typical problem can be viewed as the computation of the value of a function, say f : R ! R. Denote the true value of the input data by x, so that the desired true result is f(x). Suppose that we must work with inexact input, sayx ^, and we can compute only an approximation to the function, say f^. Then T otal error of computation = f^(^x) − f(x) = approximate value − true value 5. Forward Error and Backward Error Suppose we want to compute y = f(x), where f : R ! R. But obtain an approximation valuey ^, wherey ^ = f(^x) andx ^ is an approximation of input value x. Then, Forward Error and Backward Error are defined by • Forward Error (output error): ∆y =y ^ − y = f(^x) − f(x) • Backward Error (input error): ∆x =x ^ − x These relationships are illustrated schematically (and not to scale) in Fig.1, where x and f denote the exact input and function, respectively, f^ denotes the approximate function actually computed, andx ^ denotes an input value for which the exact function would give this computed result. Note that the equality f(^x) = f^(x) is due to the choice ofx ^; indeed, this requirement definesx ^. Figure 1: Schematic diagram of forward error and backward error 6. Sensitivity and Conditioning A problem is said to be insensitive, or well-conditioned, if a given relative change in the input data causes a reasonably commensurate relative change in the solution. A problem is said to be sensitive, or ill-conditioned, if the relative change in the solution can be much larger than that in the input data. More formally, we define the condition number of a problem f at x as f(^x)−f(x) ∆y jrelative change in solutionj j j j j Cond = = f(x) = y jrelative change in input dataj x^−x ∆x j x j j x j Where x and y are true values,x ^ is a point near x. A problem is sensitive, or ill-conditioned, if its condition number is much larger than 1. The condition number is also called ampli- fication factor. 1.1.2 Examples 1. The surface area of the Earth might be computed using the formula: A = 4πr2 for the surface area of a sphere of radius r. What are the sources of the approximations (errors)? ! Solution: (a) The Earth is modeled as a sphere, which is an idealization of its true shape. (b) The value for the radius is an approximations, r ≈ 6370km. (c) The value for π is given by an infinite limiting process, which must be truncated at some point (e.g. π ≈ 3:14). (d) The numerical values for the input data, as well as the results of the arithmetic operations performed on them, are rounded in a computer The accuracy of the computed result depends on all of these approximations. (a) and (b) are modeling and empirical measurements; (c) and (d) are numerical computations. 2. Given: 1 X 1 n2 n=1 a computer approximates. ! Solution: 1 X 1 n2 n=1 is infinite series and truncated to a finite series: 1 N X 1 X 1 ≈ n2 n2 n=1 n=1 x2 3.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    75 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us