[go: up one dir, main page]

0% found this document useful (0 votes)
313 views90 pages

مادة التحليل العددي كاملة

Uploaded by

anes anes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
313 views90 pages

مادة التحليل العددي كاملة

Uploaded by

anes anes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 90
Lecture Notes in Numerical Analysis Education College of Pure Sciences Department of Mathematics Third Year DR, Mustafa Abbas Fadhel Al-Shemary SENIOR LECTURER. Lecture1 dota: - 2022 ‘Numerical Analysis, 1, Concept of Numerical Analysis 1.1Preliminary Discussion See TU Numerical Analysis (generally) is a way to do higher Mathematics to solve their probi computer, a technique widely used by sciey advantage of Numerical Analysis is that a Numerical answer is obtain problem has no “analytical” solution. The following are some examples Analysis can solve it. (Root finding) pF Vitae ‘The value of xin ax? + bx +e =0 is ea but how about the solving of cosx = x? but it still has a numerical answer which makes the graphical technique (intersection of two curves). (integration) fal-3 1 Its easy to calculate f dx a 1 but how to calculate fe dx? ° ‘Again still has a numerical answer which uses a graphical technique (at ee eae ee cc aay a[Page Lecturer: Br. Mustofa Abbes| Lecture1 dota: - 2022 (Differential Equation) The solution ot MoE 4c 4 kx is Feoswt solution of Mops + eget kx is Feoswe, However, we don’t know how to solve ue & + kx ax? = Fi Also it still has a numerical answer (Justified later in our lectures). ‘The following are some of the operations that Numerical Analysis can do: 1. Find the roots of nonlinear equations. 2. Solve a large system of linear equations. feet eee eet 3. Get the solution of a set of nonlinear equations. 4, Interpolate to find missing values in a table of data, 5. Find derivatives of any order for functions even when we have only 6. Integration of any function even when we know only a dataset. 7 . Solve ordinary differential equations when giving initial values fo ‘These can be of any order and complexity. 8, Solve boundary values problems and determine eigenvalues and eig 9. Obtain numerical solutions to all types of partial differential equatio 10.Fit curves to data by a variety of methods. {LL Find efficient and effective approximation of functions. i A Fy 5 5 E & S é i s Note ‘The procedures used to find the numerical solution are known by algorit Arabic scientist Algorithmi. et ae gaa 2IPage Lecturer: Br. Mustofa Abbes| Lecture1 dota: - 2022 Definition Numerical algorithms are the combination of 1. Input variables. 2. A set of steps that manipulate the input variables as well as 0 variables. 3. Output variables. Definition: Floating point The term floating p is derived from the fact that there is no fixed before and after the decimal point. There are also representations in whict digits before and after the decimal point is set, called fixed-point represent For example 0.33333333 .. 1.2 Numbers System is not exact value it has more of floating p Given that digital logic and memory devices are based on two electri off), it is natural to use a number system, the binary number system coi symbols, namely 0 and 1. A number system defines how a number can using distinct symbols and determines the value it represents. There are four number systems famous we will address in this section: 1.2.1 The Decimal System When we write decimal (base 10) numbers, we use @ positional notatior e, = 0.1 x 10-* pil 1x 107+ eat = F5= [esa aor = 00883 = 0333 x 1074 3. €q = Ip ~p'| = 10.3000 x 10* ~ 0.3100 x 10*| = [3000 ~ 3100] 1 =100 =e =10? — A & Fd rs z A E 5 3 : é 4 H a Fa 1 3 es 3 > e 3 |- § g ry TlPage Lecturer: Br. Mustofa Abbes| Lecture1 dota: - 2022 p-P'l 10 100 Tel Trl 10.3000 10% 3000 = e,01%10? & Clearly, this example shows that the same relative error can occur fo absolute errors. Accordingly, as a measure of accuracy, the absolute Re eeT LG misleading and the relative error is more meaningful because the relative: consideration the size of the true value. Note: If the value of p is so small (i.e very close to zero) then we use absol than the relative error. 1.4 Sources of error There are several possible sources of error. The most common sources are: 1. Truncation Error. The notion of truncation error usually refers to errors introduced complicated mathematical expression is “replaced” with a more elements formula itself may only be approximated to the exact values, thus wo accurate answers fe 3 § ba G 8 H Exampl ‘Truncation of an infinite series to a finite se to a finite number of ter ‘truncation error. For example, the Taylor series of the exponential function ed x legge ty If only four terms (cubic polynomial) of the series are used, then 2 x3 x x pe =1tk+ me ue eats Brace Lecturer: Br. Mustofa Abbes| Lecture1 dota: - 2022 12 2 ai Ps) ¥ 1+) 4+-3 + ay = 2.66667 ‘The truncation error would be the unused terms of the Taylor series. Wher 3 is 2.718281, the absolute truncation error is. ‘The following table shows the results of finding Taylor series approximat andn = 2,3,and 4: 0516152 Check!t To find Taylor series approximations for x = and n = 2,3,and4 the the below table: Order of n | Approximation value | Absolute error | Relative er 2 2.500000 0.218281 | 803.0111 3 2.666667 Oosi614 | 189.8774 4 2.708333, 0.00995 (036.5967 2. Round ~ off Error. Round-off error is the digital difference between the calculated app number and its exact mathematical value due to the rounding usin numbers. ‘There are two major facets of round-off errors involved in numerical calcul Lecturer: Br. Mustofa Abbes| fee coe rae ee ress Lecture1 dota: - 2022 ~ Rounding Error Rounding error in floating point x= +(.d; dz dy. dy dust IB 2,8,10,16 is: Hd de dye dy B® OS dys < fl) = 7 2 Edi dydyn dy +1)8° if FS dmv < = Chopping Error Chopping error in floating point x =+(.dy dz dy. dy dns =) 2,8,10,16 is: Bet ence eta FUG) = £60, dy dy dy )B 3. Error in Original Date. Almost all reablife problems can be formulated mathematical usit ‘models, which are represented by mathematical equations. In this case, ‘may not reflect the behavior of the situation perfectly and this caused original data itself. 4, Blunders error. Since humans are involved in programming, operation, input preparati interpolation, blunders or gross error do occur more frequently than we ll Me eae ease art 5. Propagated Error. We mean an error in the succeer steps of the process due to an occurré earlier error. erty wlPace Lecturer: Dr. Mustaf Abbas Fo Lecture1 dota: - 2022 15 Rounded Floating Point Operations Let x and y be floating point numbers, let +,—,x,/ denotes the arithmetic operations, and let ,0,@,0 denote the corresponding operat are implemented on the computer. Thus, x + y may not be a floating point n x @ ys the floating point number which is the computed approximation of x the result of a floating point operation is nota floating point number, the rile and y are floating point numbers, then = = g Hi x@y=flxt+y) a xOy= f(xy) fle xy) xOy=fl@/y) Example (1.5.1) Let f(x) = vx=1+% 1. rounding error for f(x) and g(x) at. 2. chopping error for g(2), using five digits. 3. (2) ® g(A), using eight digits. find the following: 4yusing seven digits. Solution: 1. Plouna(FD) = Flowna (VE=T +4) = Fly ouna(1-7320508075688; = Flrouna (2.732050807568877) = flyouna(0.2732050807: = 02732051 = te i eto [Page Lecturer: Dr. Mustaf Abbas Fo x 10") Lecture1 dota: - 2022 # 16 16 Flooune( 94) = Flrowna ( 7) = Fun (2) = Prone = flrouna (5.333333333333333) = flyouna(0.5333333333: = 05333333 2 flenop(9(2)) = Flenop )= tal ) = flenop(1.788854381999 4 = lene (ameraraare = flenop(0.1788854381999832) = 0.17888 3. (2) @9(1) = (1+) 0(—5=) 1 =(05)@ @ 05) a = (0.5) ® (0.577350269189626) =x@y=flet+y) > (0.5) © (0.577350269189626) = fU(OS + 0.577350269189626) = f1(1.0773502691896: = f1(0.1077350269189626 x 10) = 0.1073503 Example (1.5.2) Z 9) = FA 1. rounding error for f(5) , using five digits. 2. chopping error for g(4), using four digits. 3. f(1) ® g(3), using six digits. Let f(x) = V¥- 27, find the following: tee it en [Page Lecturer: Dr. Mustaf Abbas Fo re cece Ree UP Rte ct mene Lecturer: Dr. Mustaf Abbas Fo dota: - 2022 Lecture 2 apace Jeypeg seqqy eersnyy :sasn927 ‘sonewayreW Jo jueUNIedag - seqUaIDs ing yo Aynde4 UoReONpy Lecture 2 dota: - 2022 2. Numerical Solution of non-linear equations introduction Equations that can be cast in the form of a polynomial are referred to-as algebraic equations. Equations involving more complicated terms, such as trigonometric, hyperbolic, Ins are referred to as transcendental equations. The exponential, or logarithmic fun methods presented in this section are numerical methods that can be applied to the solution of such equations, to which we will refer, in general, as non-linear equations. In general, we will we searching for one, or more, solutions to the non-linear equation, Many problems that arise in different areas of numerical nonlinear equations solution form f(x) solutions, the collection of numerical methods for finding the roots of non inéar functions ), nonlinear equations can have none, one, two, or an infinite number of present are Bisection, Secant, Newton-Raphson and Fixed point iteration method, The first step of many numerical methods for solving nonlinear equations is to identify a starting point on an interval where to search a single zero: this is called “Separation of zeros”. If no other information is available, this can be done by evaluating the function f at several values x; and plotting the results/(x;). BB] Pace Lecturer Dr. Mustafa Abbos Fodhel Lecture 2 dota: - 2022 Pee Solving the problem f(x) = 0 is equivalent to find the solutions of the oon 2. ie, graphically, to determine, in a Cartesian plane, the intersections of the. graph of the function y = f(x) with the x — axis. as example x? — 2 = 0 that is shown in the neighboring Figure — iH cs = rs i E 5 Hy Fy & i 4 c4 i g A 3 Fs iH B B Ps Lecture 2 dota: - 2022 In the case of fixed point formulation x = g(x) its graphical formulations related tote sytem {> 90. ive. the solutions are given by the intersections of the function y = g(x) with the bisector y = Pee as example y = 3(x +2) that is shown in the neighboring Figure 2 Example (2.2.1) By using graphical separation of zeros, determine the area of roots of f(x) on interval [-3,3]. Solution: Let f(@) = f(-3) = 3? = (2x -3)-1 =14 x/3 2410 1 2 S(-2) =-2 = (2x-2)-1 7 fC=-2-@x-1-1 9 Sinal + + + + + =2 #0) =-0?-2x0 f(@)=1?-2x1-1=-2 f(Q)=2?-2x2-1=5-1 fQ)=8-2x3-1=2 Thenr, €[-1,0] andr, € [2,3]. sthen x? —2x— — A 2 = rs z A 3 = Hy 8 é F H cS 3 § é 3 2 Fy rs iy g ry 15 [Page Lecturer Dr. Mustafa Abbas Fo Lecture 2 dota: - 2022 2.3iterative Methods 2.3.1 The Bisection method Supposing we are looking for a zero of a continuous function, this met an interval (a, b] containing the solution and then evaluates the function 1m = (a +b)/2. Then, according to the sign of the function, it moves to) [a,1] oF [r, 5] containing the solution and it repeats the procedure until co We can compute the midpoint 1, of the interval a 0. This indicates that the interval (a, r,) does not conte root, crossing as show in figure(a). In this case, we replace a with ty. F(a) and f(r) are F(@) and f(%) are both positive and thus oth negative and thus ‘their product is positive their product ts positive ee ee fd Figure(a) . Sketches to illustrate the bisection method when f(a) and_f(r,) have sam eae 16 |P age Lecturer Dr. Mustafa Abbas. Lecture 2 dota: - 2022 2. If fm) and f(a) have opposite sign, their product will be na F(x). (a) < 0. This indicates that the interval [a, 7] is contain th that is, 1d root, ‘crossing as show in figure(b). In this case, we replace b with 7. F(a) and f(r) have F(a) and F(,) have opposite signs and thus opposite signs and thus their product is posttive thelr product is negative Lecturer: Mustafa Abbas Face Figureb). Sketches tolustrat the bisection method when f(a) and_f(,) have sa After making the appropriate substitution, the above process is repeated are seeking has a specified tolerance. To terminate the iterations, we either a. Specify a number of iterations. . Specify a tolerance on the error of f(x). The figure(c) refers to the first 4 iterations of the bisection meth function f(x) = x*—4 in the interval [1,2]. The method starts from th eee aC [a,b] = [1,2] and evaluates the function at the midpoint 1 function in r; = 1.5 is equal to the sign of the function in b interval [a,7;] = [1,1.5], which contains the zero. At the second step, it interval (a, 6] = [1,1.5], it evaluates the function at the midpoint r= 1. to the interval [1.25, 1.5]. And so on. ret nt get Page Lecturer Dr. Mustafa Abbas Fo Figure(c). Example ofthe first four iterations ofthe bisection method "Note: Specify a tolerance on the error may be one of the following: 1 Gdl 0 is guaranteed for n + co. lenl = ben — "1S Observe that at each iteration the interval is halved, ie. (by — dy relation does not guarantee that lén¢il x, = 44770 feet eet yxy =44770 = fx) = (4.4770) = (4.4770) - tan(4.4770) = 0 + fq) is a posative sing then we make x, asa £O)b= x). _ (0.1373)(4.5 = 4.4770) _ 32 = ba) =0.1373—03075 ~ “4929 vox, = 4.4929 = f(x) = 0.0103 ~ f @%) is a posative sing then we make x, as x, _ fOYb= 2) _ FO) -Tea) 0.1373)(45 0.1373 — 01 xy=b 45 .9095 x 10-* x= 44934 = f(y) = » Gs) = 100019095 = [Ff (xs)! < 0.0005 then x3 = 4.4934 is a requirement root. Example (2.3.2.2) By using false position method, find the roots of f(x) = x? — 2x - 3, 0 005 al [0.2], Education Faculty of Pure Sciences - Department of Mathem: stopped when the condition |f(x,)| <€ is satisfied ,€ 26|Pace Lecturer Dr. Mustafa Abbas Fo Lecture 2 dota: - 2022 @(x) ( —) & please inter your function a= (04 BEC); e=( )s © please inter your values for i= 0: inf fa=func(a) ; fb=func (b) ; ~ ((fb.* (b-a)) «/ (fb=£a)) frefune (2); Af abs (fr) x3 = x, , 08 A 8508 => ys = f(x3) = f(-1.8508) = -(—1.8508)? — cos 508) = 6.6165 oe aera _ (6.6165)(-1.8508 ET ay = 185086 6165) = (15408) ~ 4017 a4 =04617 = y, = -0.9937 ay, Gan (-0.937)(0.4617 + 1.8508) apy = 04617 - hag) — Gates) = 015 xy = 0.1597 © las — x4] = 10.1597 — 0.4617] = 0.3019 = |x5— x41 < 0.5 then xs = 0.1597 is a requirement root. Example (2.3.3.2) By using secant method, find the roots of f(x) = ped at 5 -* — x, on interval (0, iteration. — A & Fd 5 z A E 5 Hy 8 8 Fy H a Fa 2 rs 3 Fs Fy rs iy g ry 32[Page Lecturer Dr. Mustafa Abbas Fo Lecture 2 dota: - 2022 MATLAB Programing ’ - secant Iteration clear ele func= @(x) ( ) & please inter your function ar (17 be) en()s please inter your values for i= 0: inf fasfunc(a) ; b= func (b) + reb-((fb.* (b-a)) «/ (fb=£a)) frefunc(r) 7 if abs (fr) f(x) = f(3.1425) = sin(3.1425) = -9.3260 x 11 = f' (4) = f'B.1428) = cos(3.1425) = -1 5 Fla) 0.0009326) cs =x oh = 3.1425 = 8.1816 eB FG) oo) 5 yxy = 31416 => f(x.) = -7.3464 x 10° = 0.0000073464 = A = fa)=-1 iH fa) 0.0000073464 EL =xm- 1416 -——__—— = 3.1416 B=" Fey st = 1 Ey xy = 31416 = f(e,) = 7.3464 x 10-* = 0.0000073464 Fy + [f()| = 10.0000073464| = 0.0000073464 < 0.0003 => If(xs)I <= then x = 3.1416 is arequirement root. Gy = ra ac) Example (2.3.4.2) = By using Newton Raphson method, find the roots of f(x) = V initial guess xq = 1, stopped at iteration. 5 i 3 (Hw) a71Page Lecturer Dr Mustafa Abbas Fo (7 8 please inter your function Be diff(Ays line (A)? inline (B) ; ee for i=0:iné xL=xO~ (£ (x0) /£1 (x0)) Ext=£ (x0); Af abs (fx1) 1 in the whole interval /, the seq converge to the solution (even if we start very close to the zero x,). The following result is a consequence of the mean value theorem. Theorem (2.3.5.1) Let g:[a,b] > [a,b] be differentiable function such that |g'(x)| gp'(x) = 2x Substitute x with x9, then 9s! (Xo) = 2x = 2(2.5) = 5, which means |g1"(xo)| > 1. + g(x) is divergent; it does not converge to the approximate root. Furthermore, in order to find the roots of g3(x), we must first ensure that converging. 9x— x? +3 1 gil) = 3 ae) = 50-29) Substitute x with Xo, then 93! (0) = £(9 = 2x9) = (9 — 2(2.5)) = 0.5000, which means |g3'C%o)| The bellow are the roots observed: 1 1 x1 = j Oxo — M0? +3) = 5 (O(2.5) — (2.5)? + 3) = 2.40625 1 1 m= gOn — x2 +3)= g (90240625) — (2.40625)? + 3) = 2.35828 1 3 (9x2 — x2? +3) = g (2.35828) — (2.35828)? + 3) = 2.33288 i (9x, — x3? +3) = 5 (9(2.33288) — (2.33288)? + 3) = 2.31920 1 3 (9(2.33288) - (2.33288)? + 3) = 231176 1 5 = 3 (9% x37 +3) 1 .] 2 cs Fe 4 A Fs Fs 4 £ ve A = 2 A + u i 8 i s id i 3 z A IS . 1 H Fi a A 3 A H Ei 3 Fe a A é 3 FE Fy Fd A 3 8g EH Fi (9x5 — x5? +3 al 3 (9(231176) ~ (2.31176)? + 3) = 2.30770 aM [Page Lecturer: Dr. Mustafa Abbas Fa lecture 5 data: - -2022 ‘Also, we must first ensure that the results are converging before attemp roots of g(x). 243 2x = 1)(2: 243. vat)eZt? agree! be) ic +3) _ x? = 2x) ~ (8 + 38x) _ 4x? - 2x — _ (2x — 1)? (2x— x8 + 4x? — Sx ~~ (x=)? ‘Substitute x with Xo, gives fi x98 + 4x97 — 5X9 _ —(2.5)8 + 4(2.5)* — 5(2.5) a4'o) (2x9 — 1)? @@5)-1P = 0.1953, which means |g4'(xo)| < 1. The following are the presented roots: Xo? +3_ (2.5)? +3 42-1 225)-1~ 3125, 27 Fe 1” Balas) 1 2302802 x2 +3 _ (2.302802)? +3 2x,—1 2(2.302802)—1 x3? +3 _ (2.302776)? +3 2x3—1 2(2.302776)—1 X3= 302776 2.302776 _ x43 _ (2.302776) +3 2x,—1 2(2.302776) —1 2.302776 xs2+3 _ (2302776)? +3 *6 = 2y,—1 2(2.302776)—1 2.302776 2 a cs Fe 4 A Fs Fs cd Ei ig 4 = 2 A + u i Fd & A £ id i 3 z A IS 5 EH Fi a 3 A H 4 3 Fe a A é 3 FE Fy Fd A 3 8g EH Fi 45 |Page Lecturer: Dr. Mustafa Abbas Fa lecture 5 data: - -2022 Asa result, the following table lists the roots for each form: M | Xner = Gin) | Maer = en) | Xnsr = Gan) | Xner = Pan) 0 [25 as) 2.5 2.5 1 [22 3.25 2.40625, 2.3125 2 [2.36364 7.5625 2.35828 2.302802 3 | 2.26923 54.1914 2.33288 2.302776 4 [2.32203 2933.71 2.31920 2.302776 5__|2.29197 8606642 2.31176 2.302776 6 | 2.30892 741 x10" 2.30770 2.302776 Note that g2 (xn) is divergent. Example (2.3.4.2) Find the root of f(2c) = e~* by using fixed point iteration. Starting with al Xo = and an approximated relative error is less than 1.2%. (H.W) g=8ix) (oF % please inter your function % please inter your values % please inter your stopped condition .] 2 cs Fe A Fs Fs 4 a g A = 2 A + § 8 ini & § £ id i 3 z A if 29 H & Fi a 3 A H 4 3 Fe a A é 3 FE Fy Fd A 3 8g EH FA Fi 46 |Page Lecturer: Dr. Mustafa Abbas Fa lecture 5 data: - -2022 Example (2.3.4.3) ‘Write MATLAB program to find iteration roots of g, (x) form for Example (2 point method. clear cle =2.57 (x) 1+ (3/x) for i=1:6 (x) end eT en aa aT) Notes: The code below is another way to locate the roots with the stopped clear cle )¢ % please inter your values } please inter your function xl=g (x0) while ( ) § please inter your stopped condi 8 i FS 5 oni @ = a) iz Fy é 29 5 & Fy a ef Fa Hy & Po a FH é a] cy Fi < © co i EH & a7 |Page Lecturer: Dr. Mustafa Abbas Fa lecture dato: - -2022 3. Interpolation Interpolation is a method of fitting data points to represent a function for known data points. It has many applications in engineering and science, such as estimating new data points within the range of known data points by determining the formula for the function that will pass through the given dataset of points (x, y). In this lecture, we will go over the definition of interpolation in numerical analysis, as well as its formulas and applications. 3.1 Linear interpolation Linear interpolation is useful while searching for a value between given two. data points. ‘The strategy for linear interpolation is to use a straight line to connect the given data points. x0 x at Figure(3.1) . graphical of linear interpolation method Often, Linear interpolation is not accurate for non-linear data. If the points in the data set to change by a large set of data, then linear interpolation may not give a good estimate. Also, it involves estimating a new value by connecting two adjacent known data points with a straight line. 48 | Page Lecturer: Dr. Mustafa Abbas Fadhel Lecture 6 data: - -2022 Formula of Linear Interpolation Suppose we have two nodes (xo,Yo), (x1, ¥:), the two linear polynomials P1(%o) = Yo = Go + 1X0, (3.1), and Pr(%q) = V4 = Mg + 4X. (3.2) SCE a Bul) Then the linear interpolation formula will derive by solving the two equatiot (3.2) as follow: Yo = Aq + 4X0) Va = My + 4m, hence, PuC2) = ay +x > pyCe) = (yo (28) ) + A) « > r(x) =m- 2) + @ =) = Pils) = yo + (28) x) x1 = Xo = = *1)O1 = Yo) = Pix) = Yo + ———7t Since p,(x) = f(x), then Example (3.1) Find the value of x = 4 for the data points (2,0.76) and (2. = a A a RY u i (4 A Fs id F 3 z A if t A A A a A 3 H Lo Rs cE A A 3 FS A Fy F A a 8g A FA Fi 49|Page Lecturer: Dr. Mustafa Abbas Fa Lecture 6 data: - -2022 Solution: Let (Xo, ¥o) = (2,0.76) and (x, ys) = (2.9,1.923). + FO) = +e) Se oe 2sycses = 076) 3.2 Polynomial Interpolation For the data points in the table below x] x0] % || 2m Y|¥o | Ya fo | Ym If f is a polynomial of degree n, FO) = Pr) = ao + yx + ot ay”, then we only need to store the n + 1 coefficients do, -~:, ay. Operations st derivative or integrating f are also convenient. The idea in this chapt polynomial that approximates a general function f. The classical problem of polynomial interpolation is to find a polynor interpolates our function f at a finite set of nodes (x9, 1)", Xm}. In othe f (%) at each of the nodes x;. Since the polynomial has n + 1 unknown expect to need n + 1 distinct nodes, so let us assume that m = n, then th conditions require Yo = Aq + AyXq +--+ AnXo” Ma = Ao + yxy to ane" Yn = Mg + Xm +2 + AX pn” so we have to solve 50|Page Lecturer: Dr. Mustafa Abbas Fa .] 2 Fs Fi 8 Bs Fs 4 S 3 B = a A + cy FS i & A 2 ha 2 is Fs A i Comedie ace sre x0” xp? oT] [Yo xo xt {ial _ | mn? X_t XML On. In. This is called a Vandermonde matrix. fe) 0 * 2 eo Figure(3.2) . graphical of polynomial interpolation method Example (3.2) Given the following table for the function f(x), obtain the lowest d polynomial, and find f(3). x|-1/ 2/4 y|-1/=4]4 Solution: Since the number of nodes = 3 = n + 1, thereforen = 2. Let Pa(2) = do + ax + ax? That satisfies the following conditions at the points xp = 1.x, = 2, x2 = 4: .] 2 cs Fe A Fs Fs 4 a g A = 2 A + § i Fd & Fi £ id i 3 z A if 29 H & Fi [J 3 A H 3 Fs a A é 3 FE Fy Fe A 3 8g EH FA Fi P2(-1) = —1; pa(2) = —4; pa(4) = 4 s1|Page Lecturer: Dr. Mustafa Abbas Fa Lecture 6 data: - -2022 [ a 1 ‘llel-F [ i as 4 ‘Using Gaussian elimination with partial pivoting, we compute the solution Ag) 4 BIA 1 ‘Therefore, the interpolating polynomial is given by Pa(x) = -4- 2x + x?, £(3) = p2(3) = -4 - 28) + GB)? = - y 2 cs 2 A Fs Fs < By g A P= 2 a § re & & Fi £ id P 3 z A if 29 i & Fi a 3 A H 3 Fs fa A é 3 FE Fy Fy A 3 8g EH Fi s2|Page Lecturer: Dr. Mustafa Abbas Fa lecture? data: - -2023 MATLAB Programing (linear Interpolation) - linear interpolation method -- as Fadhel % here the x values of data points % here the y values of data points & inter the point which we need to find the v4 sway (1) + CCL (1) )* Cy (2) -¥ (1) 1) / (8 (2) 0) Tee Example (3.3) ‘Write MATLAB code to find f (4) in Example (3.1) using linear interpolating, clear cle xe[2 2.9]; y=(0.76 1.923]; sway (1) + CC Lex (1) Cy (2) -y (1) 1) / (2 (2) 00) < 2 & = 6 e a 6 Ss = (4 A Fs id Pd % z A if 29 A A A a A 3 H c Ks A A A rs FS : Fd A a i Hl Fi 53] Page Lecturer: Dr. Mustafa Abbas Education Faculty of Pure Sciences - Department of Mathematics; Lecturer: Mustafa Abbas Fadhel % here the x values of data points % here the y values of data points 4 inter the point which we need to find the v: (Qe G-De Becat (1,B, UB); end ca=Linv(B) *y"]; al=flipud(ca) > aca’ vx = polyval (al", ix) S4] Page Lecturer: Dr. Mustafa Abbas Teeter CATT) is A Fs id FS % z A id 29 A A A Ey A 3 2 c Ks A A A rs A 5 Fd < a i Hl Fi lecture? data: - -2023 Example (3.4) = clear ele x=[-1 2 41; ye[-1 -4 415 ixs3; nlength (x) ¢ B= (17 for for UB (5) = («491 (G-2)5 end Becat (1,B, UB) + vx = polyval(al', ix) a= ~4,0000 1.0000 2.0000 55|Page ‘Write MATLAB code to find f (3) in Example (3.2) using interpolating pol 1.0000 Lecturer: Dr. Mustafa Abbas aL} et CCPC re & & Fi £ id P 3 z A if 29 i & Fi a 3 A H Fe fa A é 3 FE Fy Fa A 3 8g EH Fi lecture? data: - -2023 3.3 Newton Divided Differences Interpolation 3 Lute us given the following data table 3 x x x - 3 rt ‘0 1 Xn 3 % |» | | ~ | Ed Bo g g Ps inear then we have *! Let us assume that the function f(x) oe where x1+1 and x; are any two tabular points. This ratio is called the first di of f(x) relative to x:4 and x and is denoted by f [x1 xis}. which is FH a Moa) = Pe AY=M—-Yo = Ay =AdYo =404- Yo) =Ay-Ay =¥-N-N+Yo =y2- 21 +¥0 Y2=2yi + yo _ fev x2] - fox 2% ®2—% = flXoe x x2) = ayy mom! flex.) = Oyn=%—-Mm > Ay =Bay =A 02 ys) Shy AM =%- he e = yy ty i & & Fi £ id i 3 z A if 29 H & Fi a 3 A H c 3 Fe a A é 3 FE Fy Fd A 3 8g EH FA Fi fle xa] = 56 [Page Yaa 2ys + Yo _ fla x4) ~ flax Xe %2 Xe a Merl = AN=Yu-M > Ay =ady =40i- 9) =A Yin —4% = Yuu2 Yor — Ye + Maa Weer +H Yea ~ Byun +¥4 _ flan tial Xen Xi . Kine = feo xiv x2] In the same way we define recursively k*" divided difference by the relatio ft ® Pe, $10 X40 XK] = 57 [Page Lecturer: Dr. Mustafa Abbas Fa y 2 F RS 8 8 3 < ri s A FS 2 a § Deu ary Tees amet lecture? data: - -2023 The next table shown the difference between two values in the column F1Xe X41 X42/Xesa FU%o%1%2) flea, %2.%3) | Fld = ¥1 | Flex | Flee xen 0a) Xo Yo -—. | ml oy | Seer ml | (eee JT, %2,%3) ‘Table 3.1 Shown the difference between two values in the column The k*" degree polynomial approximation to f (x) can be written as FQ) = F Xo) + CO — xo)f Fox) + @ ~ Xo) — MDF Foxx] Hest (= 0) = xy) oe — te) f Botte tile Example (3.5) Compute (0.3) for the data xfol1| 3 m/1]3) 49 129 | 813 using Newton's divided difference formula. Solution: seme. 0 1 2 1] 3 7 23 3 | 49 19 80 4 | 29 37 228 7_| 813 S81 Page Lecturer: Dr. Mustafa Abbas Fa .] a Fs fa 8 3 Fs ¢ a Bo 4 = 2 A + § i Fd & Fi £ id i 3 z A if 29 H & Fi a 3 A H 4 3 Fe a A é 3 FE Fy Fd A 3 8g EH FA Fi lecture? data: - -2023 _ fled = flea) _ 3-1 cae! Fo. %1] yy = fled fled _ 49-3 _ fy ee eee 23 — flea] ~ fixe] _ 129-49 rs =3 F253) ‘flx4] = fxs] _ 813 ~ 129 4% 74 = 228 Files, x4) = fon _ Fo. %1-%2] = flit) = flag) _ 90-23 _ Fle kay) = Bat Peel A a 19 fle xaxd = flea, x4] = fla xal = 228 — 80 a 4% 7-3 Fleux2.x3) = Flo x x2) tor t-82 8] = Hlooxptp%) —- fleas, %4) = fleie¥2.¥a] _ 37-19 _ Fle X22, %4) = ee 7 Now Newton's divided difference formula is FO) = feo) + Ce xo) [xox] + Ge — xo) — HDF [X02] + = MO) — MO — 2)F Poe ¥2 Xs) = 1+ (x = 0)2+( = OH = 74 - O - NE - 393 = 1+ 2x4 7x? — 7x + 3x(a? - 3x x +3) S14 2x $ 7x? — 7x + Bx? — 128? + 9x = 3x9 Sx? tax tL. s9|Page Lecturer: Dr. Mustafa Abbas Fa .] a cs Fe A Fs Fs 4 Bo g A = 2 A + § i & & Fi £ id i 3 z A if = H & Fi a 3 A H c 3 Fe a A é 3 FE Fy Fd A 3 8g EH FA Fi lecture? data: - -2023 3x3 — 5x? + 4x +1 the an Since the given data is for the polynomi £(0.3) = 1.831. Example (3.6) Find f (1.5) for the data xo] 0s 1 2 ‘y: [1] 1.8987 | 3.7183 | 11.3891 using Newton's divided difference formula. Teno (H.W) - Newton form for 5 data points only- % here the x values of data points % here the y values of data points & inter the point which we need to find the va’ nelength (x)-17 bo=y (2) b1=D1 (1) b2=D2 (1) b3=D3 (1) vx=bO+b1* (ix-x (1) }+b2* (1x-x (1) ) * (xx (2) ) +34 (Lx-x (1) ) * (Le x(3)) i & & Fi £ id P 3 z A e 4 i & Fi a 3 A H c Fe fa A é 3 FE Fy Fd A 3 8g F ol Page Lecturer: Dr. Mustafa Abbas Fa lecture? data: - -2023 Example (3.7) ‘Write a Matlab code for Example (3.5) using Newton's interpolating polynot £(03). clear all cle x=(0134 717 y=[1 3 49 129 813]; ix= 0.3; nelength (x) “17 for i=lin DL (4)=(y (41) ~y (i) ) / (2¢ 42) CL) end for -1 D2(j)= (D1 (J +1) -D1.(5)) / (5 +2)-* 9) F end for keLin-2 D3 (Ke) = (D2 (+1) -D2 () ) / (x (+3) x (1) ) end omy (1) (1) 2 (1) 3 (1) vx=bO+b1* (ix=x (1) )4b2* (ix-x (1) ) * (ix-x (2)) 4.0 b3* (ix-x (1) * (ix-x (2)) * (ix-x (3)) sll Poge Lecturer: Dr. Mustafa Abbas PT eco re & & Fi £ id P 3 z A if 29 i & Fi a 3 A H c Fe fa A é 3 FE Fy Fa A 3 8g EH Fi Lecture data: - -2023 3.4 Lagrange interpolation As you might have guessed, for any n + 1 set of data, there is an n —de; that interpolates it. We present a constructive proof of this fact by polynomials. Definition (Lagrange Polynomials) For agiven set of n + 1 nodes x; , the Lagrange polynomials are the polynomials # define by oeo-(o FO Then we define the interpolating polynomial as n PX) = Y x6 7 where yj are yth direction of the dat = If each Lagrange polynomial is of degree at most n, then P, also has this pi Lagrange polynomials can be characterized as follows: xox o@= |] j=0,jzt By calculating this product for each xj, we can see that this is indeed a of the Lagrange polynomials as follow: 62|Page Ro eum ee tare nL Ba eee eee tet Lecture 8 data: - -2023 (x = Xo) (% = Xp) = Xn) #0) = Gee) = aa) wo C= Hd) A by (os) = AZO = AEH = X5) wo (H=y) ra 2 ea = 0) 2 = 41) 2 = 3) 2 = Xn). = ? (= x0)(X = x2) (X= Xn) ry fn(@) = E—AVG = 99) = (Frey) Fs = Geax) 4) Ca Keen) 2 which leads to s f A (8 = x)Gt = 24) (= 45-4) =H) ) » eee = YO Dy alg) y= 8 Jo =a) — =) = 2) = tn) Go = ¥) Go — 2) Ho — He)? (= x)= m2) ay) Gy ¥) G4 2) HH)? = Xo) (= M(H = 3) = Xn), Ga = ¥0) 2 =) 02 = Xa) = C= Hq)? = Xo) =%) «(X= ¥n-) Cn = %0) On — 2) n= Xin)" Example (3.8) Find f (1.5) for the data via a 29 using Lagrange formula. a 3 & = A Fs & 2 a} & @ = t G a by a 3 $ = ey rd ro 2 = 4 i} 7 E 3 i < = é rs s = ct i 63|Page Lecturer: Dr. Mustafa Abbas Fa Lecture 8 data: - -2023 Solution: P(x) = Fol) ¥0 + Cy + Fax) ¥2 @=x)@—%) (x = xo) = x2) PoC) = Geo) 7? * Gy HOV =H) (x= xo) =) *G=m)@2—m) _@=D@-2) “0-0-2 (x= 0)(«-2) + G=9a=2) () (-O(r-0) *@-0@-) (29) (29) 10x? + 29x? —3x + 20x — 29x 2 a P,(x) = 16x + 10x? = P,(1.5) = 1—6(1.5) + 10(1.5)? = 14.5 Example (3.9) Find f (3) for the data using Lagrange formula. Zz 2 FA i & A s Fs 4 rs Bs B = a 5 a) 4 = eo 3 = Ei cs id = 8 z Bi = . Hy Hf A a 3 EY H 3 5 a A 5 FE i F B F fd by A 2 3 Ey Ey Fe Fy (H.W) e4|Page Lecturer: Dr. Mustafa Abbas Fa Lecture8 data: - -2023 MATLAB Programing = clear all cle syms X p=07 - Lagrange’s Interpolation = x= li 8 please inter your x values y=l lk % please inter your y values ims (0G % inter the point which we need to find the n=length (x) + for i=L:n if (i~sj) (Rm (D7 OL) (1) Le end end p=L.*y(i)4p7 end pecollect (p): pretty(p) feinline (p)7 vaet (ix) ment of Mathematics; Lecturer: Mustafa Abbas Fadhel Example (3.10) 2 3 Hy i 8 Bs Fs < & Bs B Fe A Es a) E 2 3 = A FS 3 = rs Fs A = . 5 ES Fi a A Write MATLAB program to find f (1.5) for Example (3.8) By Lagrange interp method. Education Faculty of Pure Sciences - Depa Mn ead} 65|Page Lecturer: Dr. Mustafa Abbas Fa Lecture8 data: - -2023 Solution clear all cle syms X p=0; 2 10K -6X+1 x=[O 1 2]3 yel1 5 29]¢ ix=1.57 n=Length (x) 14.5000 for i=! L=l; for i) (Rox (GI) / (4) G1) he end end peL.*y(i) +p; end pecollect (p}i pretty(p) feinline (p): vase (ix) ment of Mathematics; Lecturer: Mustafa Abbas Fadhel 2 Fs i & A s Fs < & Bs B = a EB a) 4 g 3 = Ei cs id = ro z Bi = . Hy Hf Fi a 3 EY H 3 5 Fa A 5 Ey i z B F fd by A Education Faculty of Pure Sciences - Depa! 66|Page Lecturer: Dr. Mustafa Abbas Lecture9 data: - -2023 4. Numerical Integration Integration can sometimes be accomplished using standard formulae, possibly after some manipulation to express the integral in a specific form. However, often standard formulae cannot be used (for example, the function:may be known at a discrete set of points only). So it is necessary to resort to numerical techniques. Numerical integration is a primary tool to obtain approximate answers for definite integrals that cannot be solved analytically. The points at which the integrand is to be evaluated are known as grid points or mesh points, although the terms data points or just points may also be used. For G = f° F(x)dx 703 Figure 4.1 Integration function — The independent variable x in the integral of the function f(x) evaluates between the limitsx = aandx = b. — Gis the total value, or summation, of f(x) over the range x = atox = b — the area under the curve of f(x) between x = aandb * quadrature = numerical definite integration, an old term meaning the construction of a square having the same area as some curvilinear figure. 67|Page Lecturer: Dr. Mustafa Abbas Fadhel Lecture9 data: - -2023 Some examples for Integration in engineering and science in figure 4.2. o ry @ Figure 4.2 Examples of how integration is used to evaluate areas in engineering and Scientific applications. (a) A surveyor might need to know the area of a field bounded by a meandering stream and two roads. (b) A hydrologist might need to know the cross-sectional area of a river. (¢) A structural engineer might need to determine the net force due to a nonuniform wind: blowing ‘against the side of a skyscraper. 4.1 Newton-Cotes Formulae The most frequent numerical integration strategies are Newton-Cotes formulae. They are based on the concept of substituting a complex function or tabular data with a simple polynomial, as seen below. > p 6=frondrs [pear Where p,,(x) is a polynomial with order n and of the form Pn(x) Yast Ag + a,x + ayx? + ay3x3 + +++ Gx” For example, in Figure 3.4a, a first order polynomial (a straight line) is used as an approximation. In Figure 3.4b, a parabola is employed for the same purpose, 68|Page Lecturer: Dr. Mustafa Abbas Fadhel

You might also like