Numerical Methods With Excel
Numerical Methods With Excel
Numerical Methods With Excel
Microsoft Excel is a very powerful and widely used spreadsheet. For our Numerical calculations we shall use Scientific Calculators as well as MS Excel.
*ercenta e of error ( )elative error +,, From the definition' if x ( -.&. /to . d.p.0' then
- &+& x < - &.&
.
or
&$ a number is rounded to n decimal places' the maximum absolute error is + +, n ! . Consider two numbers .-&.- and ,.,,-.12 which are rounded to 3 s.f.. The errors can be estimated as follows For .-&.-' the relative error is
+ +, + .
..-&- +,
+ +, .
..-&-
<+ +, .
+ +, .
+ +, 1 .
&$ a number is rounded to n si#ni$icant $i#ures the maximum relati(e error is + +, n ++ ! . )a*lor+s )heorem with %emainder
f / x0 = f /a 0 + / x a 0 f /a 0 + / x a0 . / x a 0 n+ f /a 0 + + f .4 / n +0 4
/n0
-..12 +,
-..12
<+ +, .
/ n +0
/ a 0 + Rn / x 0
where
Rn / x 0 =
/ x a0 n f n4
/c 0 '
9 9
data t*pes examples descriptions 5"6E5 Solution text for caption C7NST"NT -..3& fixed numerical data F7)M85" (.9sin/a.0:. for calculation "ll formulas M8ST be in with an e%ual si n /(0. Most of the common functions are available in MS Excel with usual name. The function name can be typed in either upper or lower case' but Excel displays it in upper case. 5ist of functions can be searched by clic!in f x select a cate ory Select a function.
Curve Sketching Select data range. In the Insert menu, select Chart In the Chart Wizard, select Char type: XY (Scatter) and Chart sub-type. Select Finish t c mplete the diagram.
Example: Calculate f / x 0 = sin + x + e . ; x rounded to 3 d.p. for x ( ,.&' ,.2& and +.,. C 3 x f/x0 & ,.& (round/asin/c&0:exp/$.;c&0'30 1 ,.2& 2 +.,
)epeat the process usin appropriate interval. ,! 2alse Position Method3%e#ula 2alsi Method3Linear Approximation " root of f / x 0 = , in /a' b0 may be approximated by the value of the x$intercept of the line ?oinin the points / a' f / a 00 and /b' f /b00 .
.
x+ = a
/b a 0 f /a0 f /b0 f / a 0
5! Newton6%aphson Method The root of the e%uation f / x 0 = , may be approximated by x$intercept of the tan ent line throu h a uess value x , . The iterative formula for successive iteration is
x n+ + = x n
For a simple root the conver ence of the method is of order two and for a multiple root it is linear. For a multiple root the rate of conver ence can be increased by the modi$ied Newton6 %aphson formula of the form
xn+ + = x n m
7! 2ixed Point &teration 2ormula
<n order to find a root of the e%uation f / x 0 = , by iteration' rearran e the e%uation into a form x = g / x0. The iteration formula is then
<f x, is an approximation close to a root of f / x 0 = , and x n ++ = g / x n 0 is an iterative formula used to find a root of the e%uation near x,' then
/i0
e to the root.
<n particular' /a0 if + < g / x, 0 < , ' then the se%uence will oscillate and conver e to the root. /b0 if , < g / x, 0 < + ' then the se%uence will conver e to the root without oscillation.
/ii0
if g / x, 0 + the se%uence
e.
Example ,!1 @iven that f / x0 = . cos . x + . x . /a0 Find the number of real roots of the e%uation f / x 0 = , . /b0 Show that the e%uation f / x 0 = , has a root in /,.A' +.10 .
-
8se 6isection method twice to find the new smaller interval where the root lies. "pply false position /)e ula Falsi0 method in the interval obtained by the 6isection method to estimate this root correct to 3 decimal places.
8se Secant method twice to estimate the root of f / x0 = , to & decimal places with startin values x, = -.- and x+ = -.& . Show also that the root is correct to & d.p. The e%uation f / x0 = , has a root in the interval /..3' ..10 . 8se Newton$)aphson formula to estimate this root correct to & decimal places with a suitable startin value. "n iterative formula x n ++ = /+ k 0 x n + .k /+ + cos . xn 0 can be used to estimate the root of f / x0 = , . Find the ran e of values of k for which the iterative formula will conver e to the root near -.1 . 8se this iterative formula with a suitable value of k to estimate the root correct to - decimal places.
"olution /a0 The e%uation f / x 0 = , i.e. . cos . x + . x = , can be written as consider the
. cos . x = x . raphs of y = . cos . x
and y = x . .
3 .
-. -. -3
The two curves intersect at three points and hence the number of real roots is -. /b0
f /,.A0 =+.+3. f /+.10 = +.&B1 Cere f /,.A0 f /+.10 < , . Thus a root lies in /,.A' +.10 . "pplyin 6isection method on /,.A' +.10 ' we have ,.A ++.1 x+ = = +.. . f /+..0 = ,.12& and f /,.A0 =+.+3. . Now / , . A ' + . . 0 The root lies in . "pplyin 6isection method on /,.A' +..0 ' we have
x. =
+ +.. /,.+122+ 0 = +.,-BA+ +.,-BA ,.+122+ / ,.1232B 0 f /+.,-BA+ 0 = ,.,+3++ f /+0 = ,.+122+ as the root lies in /+' +.,-120
x. = +
f /+.,-12. 0 = ,.,,,.+ f /+0 = ,.+122+ + +.,-12. x- = + /,.+122+ 0 = +.,-112 +.,-12 ,.+122+ / ,.,,,.+ 0
Thus x. and x- are same to 3 d.p. Cence the root correct to 3 d.p. is +.,-12. /c0 @iven startin values for Secant method is x , = -.- and x+ = -.& f /-.-0 = ,.1,,31& and and f /-.&0 = ,.,,2A,& 8sin Secant formula
x. = -.&
f /-.&,.1-3 0 = ,.,,+22. . Now )epeatin the calculation with x+ = -.& and x. = -.&,.1-3 we have
-.&,.1-3 -.& /,.,,+22. 0 = -.&,.+32 ,.,,+22. ,.,,2A,& "fter .nd iteration' root to & d.p. is -.&,.+& . x- = -.&,.1-3
x3 = -.&,.+32 -.&,.+&
x- and x3 we can conclude that the root is correct to & decimal places.
x. = x-.&,.+& + +, &
.
-.&,.+3& x x -.&,.+&&
1 6ut f /-.&,.+3& 0 =A.2+ +, and f /-.&,.+&& Cence the root is correct to & decimal places. & 0 =A.2 + + , .
f / x, 0 = f /..&0 = ..A-&1B2
f / x, 0 ,.,12-.3 = ..& = ..321.&A ..321.1 f / x, 0 ..A-&1B2 f / x+ 0 ,.,,,1,2 x . = x+ = ..321.&A = ..32131A ..32132 f / x+ 0 ..AA&.-+ x+ = x,
x- = x . f / x. 0 +.-1 +, 2 = ..32131A = ..32131A ..32132 f / x . 0 ..AA3A-+
&
x n ++ = + ,..3 0 x n + ./,..3 0/+ + cos . x n 0 = ,.21 x n + ,.3A /+ + cos . x n 0 Dith x, = -.1 ' the successive iterates are iven below:
n , + . 3
Ta!in first e%uation as the pivotal e%uation we can write the system as .pration Coe$$icient o$ %! 8! E-! 9 Chec: "! "um x y z +1 & 2 .B E%+9 &2 & +. B & E%. -+ A ++ ., -& E%23 E%+;+1 + ,.-+. ,.3-2& +.A+.& E%39 -.&1.& E%.;& + & +.A,,, +.,,,, E%& 1..,,, E%-;A + ..3,, ..&,,, 3.-2&, E%1 B..&,, , +.-2& , ..,A2 +.-1.& E%299 ..1-2& E%& E%3 ,.A+.& & ..,1.& &.1A2& ..&1.& E%A E%1 E%3 +.,1. & E%2;..,A2& + ,.1&.2 E%B99 +..1-& ,.-AB. E%A;+.,1.& + +.B3+. &.-&-, ..3++A E%+, +..AA& ..A,+, E%++ 3.,AB& E%+, E%B E%++;+..1A& + ..+2-A E%+. -.+22A Solution of the system is obtained by the bac! substitution as follows: From /E%+.0 z == ..+2-A y = ,.-AB. ,.1&.2 ..+2-A = +.A,A, From /E%B0 x =+.A+.3 ,.-+.& / +.A,A, 0 ,.3-2& ..+2-A =+.3.13 From /E%30 Note: To chec! the calculations an extra column headed by chec: sum is included which is the sum of the numbers in the row. <t is also wor!ed out in exactly the same way as the other numbers in the line. ,! Matrix 2actori;ation Method
2
<n this method the coefficient matrix A is decomposed into the product of a lower trian ular matrix L and an upper trian ular matrix <. A=L< The system of e%uations becomes L<X=1 De rewrite this system as <X=> L>=1 De first solve for > usin forward substitution and then find X usin the bac! substitution. <n practice we use one of the followin alternatives to et uni%ue factori#ation: /a0 Crout+s formalism: "ll the dia onal elements of 8 is choesen +. /b0 olittle+s formalism: "ll the dia onal elements of 5 is choesen +.
Example 4!,:
@iven that A (
+ . - - 3 + + & + 3+ .
'
1(
& . + + &
'
X(
x y z
/i0 Eetermine a lower trian ular matrix L and an upper trian ular matrix < such that 5 8 ( ". /ii0 8se the above factori#ation to solve the e%uation A X = 1!
"olution:
(i)
5et
A(
+ . - - 3 + + & + 3+ .
(L<(
a ,, + ml db , +, n fec +,,
a al am b bl + d b m + d n c cl + e cm + en + f
a l =.
a m =b l +d = 3 c l + e =+3
or or or
. =. + m =or d = 3 -/ .0 = .
or
l=
e =+3 &/ .0 = 3
b m + d n =++
or
n=
c m + e n + f =+.
f =+. &/-0 3/ +0 =+
+ (++ -/-0 ) = + .
Thus
L(
+ , - . & 3
, , +
<(
+ . - , + + , , +
<X = ?
and
?(
y+ y. y -
or
+ , - . & 3
y+ = &'
, y+ , y. + y-
y . = -'
& . + + &
y- = .
or
+ . - x & , + + y - , , + z .
(
x =+' y = +' z =.
F(
+ + .
4! &terati(e Method <terative method for linear system is similar as the method of fixed$point iteration for an e%uation in one variable. To solve a linear system by iteration' we solve each e%uation for one of the variables' in turn' in terms of the other variables.
+,
"n iterative method conver es' for any choice of the first approximation' if every e%uation satisfies the condition that the ma nitude of the coefficient of solvin variable is reater than the sum of the absolute values of the coefficients of the other variables. " system satisfyin this condition is called dia onally dominant. " linear system can always be reduced to dia onally dominant form by elementary operations. (a) @acobi+s Method Startin with an initial set of values' if not iven' derive a new set of solution. )epeat the calculations till the re%uired accuracy is obtained. (b) 0auss6"eidel Method Start with initial values and update the value of variables in each calculation. Example 4!4 8se three$di it roundin arithmetic to solve the followin system by@auss$Seidel iteration method.
+. x . y + & z = ., ' 3 x + & y +++ z = A' 2 x ++. y ++, z = .2
Dithout chan in the order of the e%uations' we have + . > . +& +. x . y + & z = ., /E+0 & < 3 + + + 3 x + & y +++ z = A /E.0 + , < 2 ++ . 2 x ++. y ++, z = .2 /E-0 and is not dia onally dominant. "rran in the system as /E+0' /E-0 /E.0' /E.0' we have
+ . > . +& 2 > - + + + + > 3 +&
The system reduces to dia onally dominant form. The @auss$Seidel iterative formulas of the above system are xn + + = + ( . , + . y n & z n ) +. y n + + = + ( +B -xn + + + z n ) 2 z n + + = + ( A 3 xn + + & yn + + ) ++ Startin with initial values
x, = ,' y , = ,' z , = ,
we et the solutions as follows: First approximation: x+ = + >., + , + ,= = +.12 +. y+ = + >+B -/+.120 + ,= = ..,, 2 z+ = + >A 3/+.120 &/.0= = ,.2B ++
++
Second approximation: x . = + >., + ./..,,0 &/ ,.2B0= = ..-+. y . = + >+B -/..--0 ,.2B= = +.1, 2 z . = + >A 3/..--0 &/+.1,= = ,.AB ++ Third approximation: x- = + >., + ./+.1,0 &/ ,.A&0= = ...B +. y- = + >+B -/...B0 ,.A&= = +.1+ 2 z- = + >A 3/...B0 &/+.1+= = ,.A3 ++ Fourth approximation: x 3 = + >., + ./+.1+0 &/ ,.A30= = ...B +. y 3 = + >+B -/...B0 ,.A3= = +.1+ 2 z 3 = + >A 3/...B0 &/+.1+= = ,.A3 ++ which ives the results correct to . d.p. <t can be observed that the @auss$Seidel method conver es twice as fast as the Gacobi method.
To fit this polynomial to /n:+0 set of points we have to solve /n:+0 simultaneous e%uations and is very tedious.
ested by Newton is
+.
f > x+ = f > x, = x+ x, f > x+ ' x . = f > x, ' x+ = f > x, ' x+ ' x- = = x . x, AAAAAAAAAAAAAAAAAAAAA!! f > x+ ' x . ' ' x n = f > x, ' x+ ' ' x n + = f > x, ' x+ ' x- ' ' x n = = x n x, Note that divided differences are symmetric about their ar uments. f > x, ' x+ = =
Newton &nterpolation 2ormula <n terms of the divided differences interpolatin polynomial can be written as
p/ x 0 = f > x , = + f > x , ' x+ =/ x x , 0 + f > x , ' x+ ' x . =/ x x , 0/ x x+ 0 + + f > x, ' x+ ' x . ' ' x n =/ x x, 0/ x x+ 0 / x x n + 0
+-
Example 5!1
/i0 Construct a divided$difference table for the above data. /ii0 Find the polynomial of least de ree that incorporates the values in the table and find f /&0 . /iii0 Find by linear interpolation a real root of f / x 0 = , . /iv0 Find the polynomial g / x0 that ta!es the values of the above table and g /&0 = .,- . "olution: /i0 The divided difference table for the iven data is as follows: x f(x) !"# $ !%# $ !&# $ !'# $ -" -( " -" & % ) * % & %* %" + " ' +) &* * " ,
/ii0 The needed differences are enclosed by the double lined box. 6y NewtonHs divided difference formula' we et and
= 2 ++A + 3A + 2. = +-+
f / x0 = 2 +-/ x ++0 +./ x ++0/ x +0 ++/ x ++0/ x +0/ x .0 f /&0 = 2 +-/10 +./10/ 30 ++/10/ 30/ -0
f /+0 f / .0 = / +0/ A0 = A <, /iii0 Cere Thus a root is in /+' .0. From the table' we have x f/x0 +EE + + . A B Thus the root is the solution of f / x 0 = + +B/ x +0 = ,
or
x = ++ + +.+++ B
g / x 0 = f / x 0 +b/ x ++0/ x +0/ x .0/ x -0/ x 30
/iv0 The polynomial g / x0 can be written as where b is a constant. Ta!in x = & ' we have or Cence
The re%uired polynomial is g / x 0 = f / x0 + + / x + +0/x +0/x .0/x -0/x 30 . 2inite i$$erence .perators
+3
"ssume that the tabular points x, ' x+ ' x . ' ' x n are e%uispaced' that is
x r = x, + rh' r = ,'+'.' ' n
with step si#e h. De define f / x r 0 = f / x r + h0 "hi$t .perator: f / x r 0 = f / x r + h0 f / x r 0 2orward i$$erence .perator: 1ac:ward i$$erence .perator: f / x r 0 = f / x r 0 f / x r h0 Central i$$erence .perator: f / xr 0 = f / xr + h 0 f / xr h 0 . . A(era#in# .perator: f / xr 0 = f / xr + h 0 + f / xr h 0 . . )epeated applications of the difference operators ive the followin hi her order differences:
n f / x r 0 = f / x r + nh 0
+ + n f / x r 0 = n f r ++ n fr n n + n + f / xr 0 = f r ++ fr
+ k 4h
k
k f, =
+ k 4h k
k f k
Newton60re#or* 2orward i$$erence &nterpolation )eplacin the divided differences in the Newton interpolation formula by the forward differences' we have
p / x0 = f , +
/ x x, 0 / x x, 0/ x x+ 0 . / x x, 0/ x x+ 0 / x x n+ 0 n f , + f , + + f, . h .4h n 4h n
Substitutin
s=
p / x 0 = f , + s f, +
s / s +0 . s / s +0/ s .0 / s n ++0 n f , + + f, .4 n4
x x, . h Newton60re#or* 1ac:ward
where s =
i$$erence &nterpolation
)eplacin the divided differences in the Newton interpolation formula by the bac!ward differences' we have / x xn 0 / x xn 0/ x xn+ 0 . / x xn 0/ x xn++ 0 / x x+ 0 n p/ x0 = f n + f n + fn + + fn . h .4h n 4h n x xn x xn+ u= = u + + and so on Substitutin ' we have h h The above interpolation formula becomes
p / x 0 = f n + u fn + u /u ++0 . u /u ++0/ u + .0 /u + n +0 n f n + + fn .4 n4
where u = / x xn 0 ; h .
+&
Example 5!, The followin are the number of deaths in five successive ten years a e roups. Find the number of deaths for the a e roup -+ I 3& and exactly at the a e of 1,. " e roup Eeaths /in thousand .+ $ -, +2.3 -+ I 3, .+.& 3+ I &, .1.2 &+ $ 1, -..-
"olution Eata is iven in roups and hence it cannot be fitted with a polynomial directly. Consider the cumulative fre%uency and then construct the difference table. " e less than x /years0 -+ 3+ &+ 1+ No. of deaths f/x0 /in thousands0 1B!5 -A.B 1&.1 B2.B
f
. f f
7!, &.1
C!5
x -+ +,
31 -+ = +.& and +,
where s =
f / 31 0 =+2 .3 + .+ .&/+.&0 +
The number of deaths for the a e roup -+ I 3& ( &+.&1B +2.3 ( -3.+1B thousands. The number of deaths at the a e of 1, can be estimated from f /1+ 0 f /1, 0. For x = 1, ' s =
1, -+ = ..B and +,
5a ran e polynomial of de ree three passin throu h four points / x, ' y , 0 ' / x+ ' y+ 0 ' / x . ' y . 0 and / x- ' y - 0 is written as / x x+ 0/ x x. 0/ x x- 0 / x x, 0/ x x. 0/ x x- 0 L- / x 0 = y, + y+ / x, x+ 0/ x, x. 0/ x, x- 0 / x+ x, 0/ x+ x. 0/ x+ x- 0 / x x, 0/ x x+ 0/ x x- 0 / x x, 0/ x x+ 0/ x x. 0 + y. + y/ x. x, 0/ x. x+ 0/ x. x- 0 / x- x, 0/ x- x+ 0/ x- x. 0 Similar for hi her de ree polynomials. Example 5!4 The followin table ives the values of an empirical function f/x0 for certain values of x. x , + . f/x0 3 + A .B 8se the 5a ran e interpolation formula to estimate /i0 the value of f / ..&0 /ii0 the root of the e%uation f/x0 ( , to - decimal places. /i0 "pplyin 5a ran eHs formula' we have
f / x0 = 3 / x +0/ x .0/ x -0 / x ,0/ x .0/ x -0 + /, +0/ , .0/ , -0 /+ ,0/+ .0/+ -0 / x ,0/ x +0/ x -0 / x ,0/ x +0/ x .0 +A + .B / . ,0/ . +0/ . -0 /- ,0/ - +0/ - .0
/+.&0/ ,.&0/ ,.&0 / ..&0/ ,.&0/ ,.&0 + / +0/ .0/ -0 /+0/ +0/ .0
and
f / ..&0 = 3
/ ..&0/+.&0/ ,.&0 / ..&0/+.&0/ ,.&0 +.B / .0/+0/ +0 /-0/ .0/+0 = ,..& + ,.-+.& + 2.& + B.,1.& +A
/ii0 5et y = f / x0 . Then the root of f / x 0 = , corresponds to y =, . To find the root let us use the 5a ran e formula in reverse order i.e. consider the polynomial in terms of y. y 3 + A .B x , + . Then
x = , ++
=+1 .1.&
/ y + 30/ y A0/ y .B 0 / y + 30/ y ++0/ y .B 0 / y + 30/ y ++0/ y A0 +. +/ + + 30/ + A0/ + .B 0 /A + 30/ A ++0/ A .B 0 / .B + 30/ .B ++0/ .B A0 x = , ++ / 30/ A0/ .B 0 / 30/+0/ .B 0 / 30/+0/ A0 +. +/-0/ B0/ -, 0 /+. 0/ B0/ .+ 0 /-- 0/ -, 0/ .+ 0
+2