Fundamentals of Numerical Mathematics for Physicists and Engineers. Alvaro Meseguer

Fundamentals of Numerical Mathematics for Physicists and Engineers - Alvaro Meseguer


Скачать книгу
href="#fb3_img_img_302de88e-aea1-5c0f-be85-ded3acb3a1c1.png" alt="images"/>, usually called the residuals. Since this quantity should approach zero when images converges to a root, the reader may wonder why images should not be used as a measure for stopping the iterations. The reason is that the residual is not always a reliable measure (although it is often used in practice to decide convergence). We will address this question later in this chapter, when we introduce the concept of condition number of a root.

Graph depicts a curve intersecting at a point at the x-axis and the root is between x1 and x0.

      (1.6)equation

      (1.7)equation

      The resulting abscissa images where images intercepts the images‐axis is the new (hopefully more accurate) estimation of the root. The process can be repeated approximating images by its Taylor expansion images at images (straight gray line below the curve) in order to obtain an even better estimation images satisfying

      (1.8)equation

      and so on, leading to the iterative formula:

      Newton's Iteration:

      (1.9)equation

      A simple implementation of Newton's method can be found in the next code, whose structure essentially differs from the one seen in the bisection in two main aspects. First, the code needs an initial guess images as starting point, instead of an interval. Second, in addition to the string name corresponding to the M‐file function fun, the code also needs the one associated with images in the argument dfun. Providing the M‐file for the exact derivative entails both analytical differentiation and its subsequent programming, both being error‐prone tasks. While this is the correct procedure, it is sometimes advisable to let the computer do the job by approximating the value of images by the ratio

      % Code 2: Newton's method for solving f(x) = 0 % Input: 1. a: initial guess % 2. tol: tolerance so that abs(x_k+1 - x_k) < tol % 3. itmax: maximum number of iterations allowed % 4. fun: function's name % 5. dfun: derivative's name % (If dfun = ‘0’, then f'(x) is approximated) % Output: 1. xk: resulting sequence % 2. res: resulting residuals % 3. it: number of required iterations function [xk,res,it] = newton(a,tol,itmax,fun,dfun) xk = [a]; fk = feval(fun,xk); res = abs(fk); it = 0; tolk = res(1); dx = 1e-8 ; while it < itmax & tolk > tol if dfun == ‘0’ dfk = (feval(fun,xk(end)+dx)-fk)/dx; else dfk = feval(dfun,xk(end)); end xk = [xk, xk(end) - fk/dfk]; fk = feval(fun,xk(end)); res = [res abs(fk)]; tolk = abs(xk(end)-xk(end-1)); it = it + 1; end


Скачать книгу