







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
• Exposition and Program Design for; - Methods of Interpolation - Halving the Square Method - Newton Raphson’s Method - Regular Falsi Mathod - Gaussian Elimination Method - Trapezoid Rule, Simpson’s Rule
Typology: Essays (university)
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Page | 1
Computer Math’s IORLAHA^ BY MR. MCOEG. S.K. ComputerMath’s
L 2 = (x-x (^) o)(x-x (^) 1)/(x2-x (^) o)(x (^) 2-x (^) 1) = (x-1) (x-1.5)/(3-1)(3-1.5) = (x 2 -2.5x+1.5)/ Therefore: P2(x)= 5 (x 2 -4.5x+4.5) + ( -3 )[-4/3(x^2 -4x+3)] + 0 [(x 2 -2.5x+1.5)/3]
5 (x 2 -4.5x+4.5) – 3 [-4/3(x 2 -4x+3)] + 0 Example 3 Interpolate for f(2.3) from the table below. X 1.1 1.7 3. F(x) 10.6 15.2 20. Solution: P2(x) = ni=0 Li(x).f(x (^) i) = L (^) o(x).f(x (^) o) + L1(x).f(x (^) 1) +L2(x).f (x (^) 2) where f(2.3)=x=2.3; xo = 1.1, x (^) 1=1.7, x2=3.0; y (^) o=10.6, y1=15.2, y (^) 2=20. Lo = (x-x (^) 1)(x-x (^) 2)/(xo-x (^) 1)(x (^) o-x (^) 2)= (2.3-1.7)(2.3-3.0)/ (1.1-1.7)(1.1-3.0) = -0. L 1 = (x-x (^) o)(x-x (^) 2)/(x1-x (^) o)(x (^) 1-x (^) 2) = (2.3-1.1)(2.3- O3.0)/(1.7-1.1)(1.7-3.0) = 1. L 2 = (x-x (^) o)(x-x (^) 1)/(x2-x (^) o)(x (^) 2-x (^) 1) = (2.3-1.1) (2.3-1.7)/(3.0-1.1)(3.0-1.7) = 0. P2(2.3) = 10.6(-0.37) + 15.2(1.08) + 20.3(0.29) =
a. Interpolate for f(0.65) from the table below using Lagrange polynomial. x 0.40 0.50 0.70 0. y -0.916 -0.693 -0.357 -0. b. (^) Given the following points: (0,0), (1, -1), (8, 2); write down the interpolating polynomial. NEWTON’S DIVIDED DIFFERENCE INTERPOLATION FORMULA (NDIF) Let y=f(x) take the values of f(xo), f(x (^) 1), …, f(x (^) n) where the arguments x (^) o, x1, … , xn corresponds to them. By definition, f(x, x (^) o) = f(x)-f(x (^) o)/( x- xo) f(x)=f(x)+(x- x (^) o)f(x, x (^) o) -----------(1) Similarly, f(x, x (^) o, x1 ) = f(x, x (^) o, x1)= f(x, x (^) o)-f(x (^) o, x1)/ x- x (^1) Therefore; f(x, x (^) o) =f(x (^) o, x1)+ (x-x1)F(x, x (^) o,x1) Using the value of f(x, x (^) o) in eqn(1) above; F(x)= f(x (^) o)+( x-xo)f(x (^) o, x1)+(x-x (^) 1)f(x, x (^) o, x1) ---------------- (2) Again, f(x, x (^) o, x1, x2) =[ f(x, xo, x1)-f(x (^) o, x1, x1)]/ (x-x 2 )
Then f(x, x (^) o, x1) = f(xo, x1, x2)+(x-x (^) 2)f(x, x (^) o, x1, x2) Using the value in eqn. (2); we have F(x)=f(xo)+(x-x (^) o)f(x,x (^) o)+(x-x (^) 1)[f(x (^) o, x1, x2)+(x- x (^) 2)f(x, x (^) o, x1, x2)] F(x)=f(xo)+(x-x (^) o)f(x (^) o,x1)+ (x-x (^) o)(x-x (^) 1) f(x (^) o, x1, x2)
Using Newton’s divided difference formula, find the values of f(2), f(8), and f(15) given the table below.
Given the table below, form the forward difference table xi 0 1 2 3 4 yi -2 1 4 13 34 Solution:
xi yi yo 2 yo 3 yo 4 yo 0 -2 Leading term 3 1 1 0 3 6 2 4 6 0 9 6 3 13 12 21 4 34 Coefficients of forward difference. Thus we have in the above table; yi = -2, y (^) o =3; 2 yo =0; 3 yo = 6 and 4 yo = 0. Exercise Obtain the forward difference table for the following relations: a)
x 1 2 3 4 5 6 y 4 15 40 85 156 259 b)
x 0 1 2 3 4 5 6 y -1 3 19 53 111 199 323
To Find any Term in Terms of y (^) o, 2 yo, e.t.c. we have the relation yk = E k^ yo; where E k^ is known as Inverse Operator. = (1+ )y (^) ok = (1+ kC 1 yo + kC 2 2 + … k^ )y (^) o. = y (^) o + kC 1 yo + kC 2 2 yo + …+ k^ yo; Where k is the nth term (position) to be found. Example 2 From the forward difference table in example 1, find the value of y5. Solution 3 y5^ = y(x=5) = -2+^5 C^1 yo^ +^5 C^2 2 yo^ +^5 C^3 yo
SOLUTIONS OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS (NON- LINEAR EQUATIONS) The equations with the form: f(x) = x 3 -5x+4=0 are said to be Algebraic; while those with the form: f (x) = cos x + 3sin2x + e x^ are said to be transcendental. The following methods can be used to solve Algebraic and Transcendental equations:
thus: x1 = 1+2^ / 2 = 1. Now test for f(x1) … if the result equals 0, satisfied(as according to the rule); i.e. f(1.5) = (1.5) 3 – 1.5 – 1 = 0.875 …… >0; a=1, b=1.5. since f(x1)>0: x2∈[1, 1.5]. thus: x (^) 2= 1+1.5/ 2 = 2.5/ 2 = 1.25. Repeat from the action test , until f(x) = 0, then stop. i.e. F(1.25) = (1.25) 3 – 1.25 – 1 = -0.296875 ……… <0. x3∈[1.25, 1.5] Thus; x 3 = 1.25+1.5^ / 2 = 1.375.
f(1.375) = (1.375) 3 – 1.375 – 1 = 0.224……
x 4 ∈ [1.25, 1.375] x 4 = 1.25+1.375/ 2 =1.
f(1.3125) = 1.3125 3 -1.3125-1 = -0.0515…..< Thus a=1.3125; b=1. x5∈[1.3125, 1.375] ξ 5 = 1.3175+1.375^ / 2 = 1.
φ
(1.34375)=1.34375 3 −1.34375−1= 0.08261 ……………> Τηυσ α=3.3125; β=3. ξ 6 ∈[1.3125, 1.34375] Χοντινυε υντιλ E is met or the required no of iterations is reached. ALGORITHM FOR BISECTION METHOD Purpose: Algorithm for finding the solution of f (x)=0 given that f(x) is continuous in [a, b] and f (a) and f(b) are of opposite signs. Input: End points a, b; tolerance, tol; max number of iterations. Output: Approximate soln. P or a message of failure. Steps; 1: Set i=1; fA=f(a);
Solution: f(0) = 0^3 -4(0) + 1 = 1 and f(1) = 1^3 – 4(1) + 1 = 1-4+1 = - This clearly shows that x∈[0, 1] hence a (^) o = 0, bo=1. xo = bof(ao)-aof (b (^) o) f(ao)
Step III: x = (bPo – aP (^) 1)/P (^) o-P (^1) Step IV: If x-b <h THEN Output x. {Procedure completed} Step V: Set I = i+1, P = f(x) Step VI: If P * P (^) 1<0 THEN set a=x, Po=P (^1) Step VII: b=x, P1=P Step VIII: Output message of failure after N iterations. Step IX: End. Assignment 3 Draw the flowchart for the R.F. method and state four features of R-F method. NEWTON RAPHSON METHOD The Newton Raphson method for the numerical solution of an equation f(x)=0 is of great importance. Suppose f(x) is continuous in the interval [a, b], let x (^) o∈[a, b] be an approximate in P such that f’(x)0 and x (^) o-P
Since P – x (^) o is small, P – xo^2 and higher order is smaller. Hence we may write: f(x (^) o) + f’(xo)(P-x (^) o) = 0 f(x (^) o) +f’(xo)P – f’(x (^) o)x (^) o =0 (Open brackets) f’(xo)P = f’(x (^) o)x (^) o – f(x (^) o) (Make P the subject…) f’(xo) f’(x (^) o) f’(x (^) o) P = x (^) o – [f(x (^) o)/f’(x (^) o)] ----------------------- (1.0) Thus the Newton’s method begins with an initial guess Po to generate a sequence of {P (^) n} defined by: Pn = P (^) n-1 – [f(Pn-1 )/f’(Pn-1 )] ------------------(1.1) Substitute Pn with xn and x (^) n≃x (^) n+1, eqn. (1.1) becomes: Xn+1 = x (^) n+1-1 – f(x (^) n+1-1) f’(xn+1-1 ) Xn+1 = x (^) n – f(x (^) n) ----------------------(1.2) f’(xn) Now, equation (1.2) becomes the N-R scheme for solving equation f(x) = 0. Example Solve by the N-R method the equation: f (x)=x 4 -x-10. Let our P (^) o (guess value) be 1.5 (or x (^) o in this case)
f(x) = x^4 – x – 10 f’(x) = 4x^3 – 1. Therefore test the value of Xo in f(x) and f’(x) f(1.5) = 1.5^4 – 1.5 – 10 = -6. f’(1.5) = 4(1.5)^3 – 1 = 12.
x 1 = 1.5 –(-6.4375)/12 = 2.
f(x (^) 1) = (2.015)^4 -2.015 – 10 = 4. f’(2.015) = 4(2.015)^3 – 1 = 31.
x 2 = 2.015 – (4.4704)/31.725 = 1.
… Continue for eight iterations. Excersice: Solve the following equations using N-R method.
Input: initial approximate Po, tolerance tol., n- iterations N Output: approximate solution P or message of failure. Step 1: set i=1 {initial counter} Step 2: WHILE iN Do steps 3-
a 11 x1 + a12x2 + a12x3 + … + a (^) 1nxn = b (^1)
a21x1 + a22x2 + a23x3 + … + a (^) 2nxn =b (^2) .
. ----(1) . an1x1 + an2x2 + an3x3 + … + a (^) nnxn = b (^) n This can be written in a matrix form as: a 11 a 12 a 13 … a1n x1 b a 21 a 21 a 23 … a2n x2 b .. =. ---------- (2) ... ... an1 a (^) n2 an3 … ann xn bn This is equivalent to the matrix AX = B Where
a 11 a 12 … a (^) 1n x1 b 1 A = a 21 a 21 … a (^) 2n x2 b 2
. X =. and B=.
c. 8x – 3y + 2z = 20 4x + 11y – z = 33 6x + 3y + 12z = 35 d. 2x + 3y – z = 12 6x – 3z = 6 3x – 3y + 2z = 8
x f(x) f(x) 2 f(x) 3 f(x) 4 48 52 5 100 15 97 1 7 294 21 202 1 10 900 27 310 1 11 1210 33 409 13 2028
By NDIF: F(x) = f(x (^) o)+(x-xo)f(x (^) o,x1)+ (x-x (^) o)(x-x (^) 1) f(x (^) o, x1, x (^) 2)+ (x-x (^) o)(x-x (^) 1) (x-x (^) 2) f(x (^) o, x1, x2, x3)+… Given that x (^) o=4, x1=5, x (^) 2=7, x (^) 3=10, x (^) 4=11, x5=13; and f(xo)= 48, f(xo ,x1)=52, f(x (^) o, x1, x2)=15, f(x (^) o, x1, x2, x3)=1 … F(x)= 48+(x-4)(52)+(x-4)(x-5)(15)+(x-4)(x-5) (x-7)(1)+ F(x)= 48+52x-208+(x 2 -9x+20)(15)+[x 3 -16x 2 +83-140] F(2)= 48+52(2)-208+(4-18+20)(15)+8-16(4)+ (2)-