Chapter1 Solution of Equation of One Variable
Chapter1 Solution of Equation of One Variable
𝑏1 − 𝑎1
𝑝1 = 𝑎1 +
2
If 𝑓(𝑝1 ) = 0, then the root 𝑝 is given by 𝑝 = 𝑝1 ; if 𝑓(𝑝1 ) ≠ 0, then 𝑓(𝑝1 ) has the
same sign as either 𝑓(𝑎1 ) or 𝑓(𝑏1 ).
If 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have the same sign, then 𝑝 is in the interval (𝑝1 , 𝑏1 ), and we
set
𝑎2 = 𝑝1 and 𝑏2 = 𝑏1
If, on the other hand, 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have opposite signs, then 𝑝 is in the
interval (𝑎1 , 𝑝1 ), and we set
𝑎2 = 𝑎1 and 𝑏2 = 𝑝1
We reapply the process to the interval [𝑎2 , 𝑏2 ], and continue forming [𝑎3 , 𝑏3 ],
[𝑎4 , 𝑏4 ],… Each new interval will contain 𝑝 and have length one half of the
length of the preceding interval.
and the test sgn(𝑓(𝑎𝑛 ))sgn(𝑓(𝑝𝑛 )) < 0 is used instead of 𝑓(𝑎𝑛 )𝑓(𝑝𝑛 ) < 0.
The, following Algorithm can be used to solve equation 𝑓(𝑥) = 0 using the
bisection method:
Algorithm
INPUT: endpoints 𝑎, 𝑏; tolerance TOL; Maximum number of iterations 𝑁0
Set 𝑖 = 1
𝐹𝐴 = 𝑓(𝑎)
𝐖𝐡𝐢𝐥𝐞 (𝑖 ≤ 𝑁0 ) do
𝑝 = 𝑎 + (𝑏 − 𝑎)/2; (compute 𝑝𝑖 )
𝐹𝑃 = 𝑓(𝑝)
If (𝐹𝑃 = 0 or (𝑏 − 𝑎)/2 < 𝑇𝑂𝐿 ) Then
𝐎𝐮𝐭𝐩𝐮𝐭 (𝑝); (Procedure completed successfully)
STOP
𝑖 = 𝑖 + 1.
IF ( sign(𝐹𝐴) × sign(𝐹𝑃) > 0 ) Then
𝑎 = 𝑝; (Compute 𝑎𝑖 and 𝑏𝑖 )
𝐹𝐴 = 𝐹𝑃
else
𝑏=𝑝
endif
end do
Problem: 1) Translate the above algorithm in PASCAL, and run the programs
to find the roots of the function 𝑓(𝑥) = 𝑥(𝑥 + 2)(𝑥 + 1)2 (𝑥 − 1)3 (𝑥 − 2) in
the intervals (i) [−1.5, 2.5], (ii) [−0.5, 2.4], (iii) [−0.5, 3.0], and (iv) [−3, −0.5].
Page 3 of 13
Solution of Equations of One Variable
Page 4 of 13
Solution of Equations of One Variable
𝑓(𝑥0 ) + (𝑥 − 𝑥0 )𝑓 ′ (𝑥0 ) ≅ 0
And solving for 𝑥 gives
𝑓(𝑥0 )
𝑥 = 𝑥0 − ≡ 𝑥1
𝑓 ′ (𝑥0 )
This sets the stage for Newton’s method, which starts with an initial
approximation 𝑥0 and generates the sequence {𝑥𝑛 }∞
𝑛=0 , by
𝑓(𝑥𝑛−1 )
𝑥𝑛 = 𝑥𝑛−1 − , 𝑛≥1
𝑓 ′ (𝑥𝑛−1 )
Graphically, the successive approximation for 𝑥1 , 𝑥2 , 𝑥3 , … are obtained using
successive tangents (as illustrated). Starting with the initial approximation 𝑥0 , the
approximation 𝑥1 is the x-intercept of the tangent line to the graph of 𝑓 at
(𝑥0 , 𝑓(𝑥0 )). The approximation 𝑥2 is the x-intercept of the tangent line to the
graph of 𝑓 at (𝑥1 , 𝑓(𝑥1 )) and so on.
The stopping-technique inequalities given with the Bisection method are
applicable to Newton’s method. That is, select a tolerance 𝜀 > 0, and construct 𝑥1 ,
𝑥2 , …, 𝑥𝑁 until
|𝑥𝑛 − 𝑥𝑛−1 | < 𝜀,
|𝑥𝑛 − 𝑥𝑛−1 |
< 𝜀, 𝑜𝑟
|𝑥𝑛 |
|𝑓(𝑥𝑛 )| < 𝜀
Problem: (i) Propose an algorithm to compute the root of a function 𝑓
following the Newton-Raphson procedure. (ii) Give the translation of this
algorithm into TURBO PASCAL. (iii) Run the above program taking as the
trial function 𝑓(𝑥) = 4𝑥 cos(2𝑥) − (𝑥 − 2)2 in the interval [0, 8] with
an accuracy of 10−5 .
1.2.2 Secant Method
Newton’s method is an extremely powerful technique, but it has a major
weakness: the need to know the value of the derivative of 𝑓 at each
approximation. Frequently, 𝑓′(𝑥) is far more difficult and needs more arithmetic
operations to calculate than 𝑓(𝑥). To circumvent the problem of the derivative
evaluation in Newton’s method, we introduce a slight variation. By definition
Page 5 of 13
Solution of Equations of One Variable
𝑓(𝑥) − 𝑓(𝑥𝑛−1 )
𝑓′(𝑥𝑛−1 ) = lim
𝑥→𝑥𝑛−1 𝑥 − 𝑥𝑛−1
If 𝑥𝑛−2 is closed to 𝑥𝑛−1 , then
𝑓(𝑥𝑛−2 ) − 𝑓(𝑥𝑛−1 ) 𝑓(𝑥𝑛−1 ) − 𝑓(𝑥𝑛−2 )
𝑓 ′ (𝑥𝑛−1 ) ≈ =
𝑥𝑛−2 − 𝑥𝑛−1 𝑥𝑛−1 − 𝑥𝑛−2
Using this approximation for 𝑓 ′ (𝑥𝑛−1 ) in Newton’s formula gives
𝑓(𝑥𝑛−1 )(𝑥𝑛−1 − 𝑥𝑛−2 )
𝑥𝑛 = 𝑥𝑛−1 − , 𝑛≥2
𝑓(𝑥𝑛−1 ) − 𝑓(𝑥𝑛−2 )
This technique is called the Secant method. Graphically, the technique consists in
choosing two initial approximations 𝑥0 and 𝑥1 and determine 𝑥2 as the x-
intercept of the secant line to the curve, the line through (𝑥0 , 𝑓(𝑥0 )) and
(𝑥1 , 𝑓(𝑥1 )). This places the approximation 𝑥2 of the root 𝑥 closer to the endpoint
of the interval for which 𝑓 has smaller absolute value. The approximation 𝑥3 is
obtained as the x-intercept of the line joining (𝑥1 , 𝑓(𝑥1 )) and (𝑥2 , 𝑓(𝑥2 )), and so
on.
Because the Secant method does not have the root-bracketing property of the
Bisection method, the method does not always converge, but when it does
converge, it generally does so much faster than the Bisection method.
Page 6 of 13
Solution of Equations of One Variable
Although the method of False Position may appear superior to the Secant
method, it generally converges more slowly. It converges even more slowly than
the Bisection method.
Page 7 of 13
Solution of Equations of One Variable
𝑃(𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + ⋯ + 𝑎𝑛 𝑥 𝑛
where the 𝑎𝑖 , 𝑖 = 0,1, … , 𝑛 are the coefficients of 𝑃.
Page 8 of 13
Solution of Equations of One Variable
Problem:
1. Propose an algorithm to compute the value of a polynomial 𝑃(𝑥) and
its derivative 𝑃′(𝑥) at a given point 𝑥0 using the Horner method.
2. Propose an algorithm that uses the synthetic division procedure of
part 1 to find a root of the polynomial 𝑃(𝑥).
3. Give the translation of the above algorithm into PASCAL.
Method
Suppose that three initial approximations, 𝑝0 , 𝑝1 , and 𝑝2 , are given for a solution
of f(x) = 0. The derivation of Müller’s method for determining the next
approximation 𝑝3 begins by considering the quadratic polynomial
𝑃(𝑥) = 𝑎(𝑥 − 𝑝2 )2 + 𝑏(𝑥 − 𝑝2 ) + 𝑐
that passes through (𝑝0 , 𝑓(𝑝0 )), (𝑝1 , 𝑓(𝑝1 )), and (𝑝2 , 𝑓(𝑝2 )). The constants 𝑎, 𝑏,
and 𝑐 can be determined from the conditions
Giving
Page 9 of 13
Solution of Equations of One Variable
𝑐 = 𝑓(𝑝2 )
(𝑝0 − 𝑝2 )2 [𝑓(𝑝1 ) − 𝑓(𝑝2 )] − (𝑝1 − 𝑝2 )2 [𝑓(𝑝0 ) − 𝑓(𝑝2 )]
𝑏=
(𝑝0 − 𝑝2 )(𝑝1 − 𝑝2 )(𝑝0 − 𝑝1 )
(𝑝1 − 𝑝2 ) [𝑓(𝑝0 ) − 𝑓(𝑝2 )] − (𝑝0 − 𝑝2 ) [𝑓(𝑝1 ) − 𝑓(𝑝2 )]
𝑎=
{ (𝑝0 − 𝑝2 )(𝑝1 − 𝑝2 )(𝑝0 − 𝑝1 )
The next approximate root 𝑝3 is given by solving 𝑃(𝑥) = 0, hence
−𝑏 ± √𝑏 2 − 4𝑎𝑐
𝑝3 − 𝑝2 =
2𝑎
To obtain a more accurate four-digit rounding approximation, we can change the
form of the quadratic formula by rationalizing the numerator and the above relation
transforms to
−2𝑐
𝑝3 − 𝑝2 =
𝑏 ± √𝑏 2 − 4𝑎𝑐
Among the two solutions above given, Müller’s method considers the solution for
which the sign in front of the radical agree with the sign of b.
2𝑐
𝑝3 = 𝑝2 −
𝑏 + sgn(𝑏)√𝑏 2 − 4𝑎𝑐
Chosen in this manner, the denominator will be the largest in magnitude, which
avoids the possibility of subtracting nearly equal numbers and results in 𝑝3 being
selected as the closest root of 𝑃(𝑥) = 0 to 𝑝2 .
The same routine applies if the approximate solution 𝑝3 is not within the desired
accuracy, and 𝑝4 is determined upon replacing, 𝑝0 , 𝑝1 and 𝑝2 by 𝑝1 , 𝑝2 and 𝑝3
respectively.
The method continues until a satisfactory approximation is obtained. Since the
method involves the radical √𝑏 2 − 4𝑎𝑐 at each step, the method approximates
complex roots when 𝑏 2 − 4𝑎𝑐 < 0, provided, of course, that complex arithmetic
is used. The following algorithm implements this procedure
Algorithm
INPUT: initial approximations 𝑝0 , 𝑝1 and 𝑝2 ; tolerance TOL; Maximum number
of iterations 𝑁0
Step1: Set ℎ1 = 𝑝1 − 𝑝0 ;
ℎ2 = 𝑝2 − 𝑝1 ;
𝛿1 = (𝑓(𝑝1 ) − 𝑓(𝑝0 ))/ℎ1 ;
𝛿2 = (𝑓(𝑝2 ) − 𝑓(𝑝1 ))/ℎ2 ;
Page 10 of 13
Solution of Equations of One Variable
𝑑 = (𝛿2 − 𝛿1 )/(ℎ1 + ℎ2 );
𝑖 = 3;
Step 2: 𝐖𝐡𝐢𝐥𝐞 (𝑖 ≤ 𝑁0 ) do Steps 3-7
Step 3: 𝑏 = 𝛿2 + ℎ2 𝑑;
𝐷 = √𝑏 2 − 4𝑓(𝑝2 )𝑑; (May require complex arithmetic)
Step 4: if |𝑏 − 𝐷| < |𝑏 + 𝐷| then ;
set 𝐸 = 𝑏 + 𝐷;
else
set 𝐸 = 𝑏 − 𝐷
end if
Step 5: set ℎ = −2𝑓(𝑝2 )/𝐸;
𝑝 = 𝑝2 + ℎ;
Step 6: if ℎ < 𝑇𝑂𝐿 then ;
OUTPUT(p); (“the procedure is successful”)
STOP
end if
Step 7: set 𝑝0 = 𝑝1 ; (“preparing for the next iteration”)
𝑝1 = 𝑝2 ;
𝑝2 = 𝑝;
ℎ1 = 𝑝1 − 𝑝0 ;
ℎ2 = 𝑝2 − 𝑝1 ;
𝛿1 = (𝑓(𝑝1 ) − 𝑓(𝑝0 ))/ℎ1 ;
𝛿2 = (𝑓(𝑝2 ) − 𝑓(𝑝1 ))/ℎ2 ;
𝑑 = (𝛿2 − 𝛿1 )/(ℎ1 + ℎ2 );
𝑖 = 𝑖 + 1.
Step 8: OUTPUT(“Method failed after 𝑁0 iterations”)
END.
Problem: (i) Propose an algorithm to compute the rote of a function 𝑓 using
the Müller method. (ii) Give the translation of this algorithm into PASCAL.
(iii) Run the above program and find all the taking as the trial function
𝑓(𝑥) = 𝑥 5 − 𝑥 4 + 2𝑥 3 − 3𝑥 2 + 𝑥 − 4 in the interval [0, 8] with an accuracy of
10−5 .
Page 11 of 13
Solution of Equations of One Variable
𝑓1 (𝑥1 , 𝑥2 , … , 𝑥𝑛 ) = 0
𝑓 (𝑥 , 𝑥 , … , 𝑥𝑛 ) = 0
{ 2 1 2
⋮
𝑓𝑛 (𝑥1 , 𝑥2 , … , 𝑥𝑛 ) = 0
Page 12 of 13
Solution of Equations of One Variable
Page 13 of 13