You are on page 1of 43

Quiz

 
 
1)  What  is  the  formula  to  calculate  the  
percentage  rela7ve  of  numerical  error?  
2)  Con7nue  the  following  Taylor  series  formula:    
 f(x+h)  =  f(x)  +  …    
 

 
Roots  of  Polynomials  
Revision  on  Basic  Laws  of  Indices  
(i) (iv)

(ii) (v)

(iii) (vi)
Examples:
The general form of polynomial equations
(2.1)

•  Linear equation (or polynomial of order 1)

•  Quadratic equation (or polynomial of order 2)

•  Cubic equation (or polynomial of order 3)


Simple  Linear  Equa<ons  
(1) Solve

(i) By cross-multiplying

(ii) Removing brackets

(iii) Rearranging

(2) Solve
Quadra<c  Equa<ons  
Quadratic Formula 1
Roots of a general quadratic eqn. (2.2)
are p
b± b2 4ac
x1,2 = (2.3)
2a
The expression is called the discriminant.
two unequal real roots
two unequal complex roots
the roots are real and equal
Quadra<c  Equa<ons  
Quadratic Formula 2 (from Lagrange resolvents)
Roots of a general quadratic eqn. (2.4)

are

(2.5)

How do we get these roots?


Assume that the equation factors as
x2 + px + q = (x ↵)(x )
Continue!
Quadra<c  Equa<ons  
Factorization

(1)

Then, either

or

(2)
MATLAB  Implementa<ons  
Create a solver by writing functions, for example:
function x = quadraticSolver(a,b,c)

x = zeros(2,1);

d = sqrt(b^2 - 4*a*c);
x(1) = ( -b + d ) / (2*a);
x(2) = ( -b - d ) / (2*a);

This solver accepts 3 input numbers to find roots of a


quadratic function

and returns a vector output (answers).


MATLAB  Implementa<ons  
Call the function from the command line (or Command
Window):
>> quadraticSolver(3,-4,2)

ans

0.6667 + 0.4714i
0.6667 - 0.4714i

This solver can be downloaded at:


http://people.bu.edu/andasari/courses/Fall2015/quadraticSolver.m
Tschirnhaus  Transforma<on  

Let be a polynomial of order n

Then the substitution

converts Pn into a depressed polynomial

where
Cubic  Equa<on  (Cardano’s  Formula)  

The cubic equation (2.6)

is by the substitution reduced to

Letting

we obtain (2.7)
Cubic  Equa<on  (Cardano’s  Formula)  

Now let and


and substituting into the depressed cubic eqn. (2.7):
Cubic  Equa<on  (Cardano’s  Formula)  

The 6th order polynomial can be solved by using the


quadratic formula, by taking and the equation
reduces to

Solving using the quadratic formula, we get


Cubic  Equa<on  (Cardano’s  Formula)  
or

Substituting k back to u

If we take the positive root


and substitute to
we get the expression for
It goes the same way if we take the negative root for u3.
Cubic  Equa<on  (Cardano’s  Formula)  
is called the discriminant.
Putting and
the roots can be interpreted as follows:
(i) if D > 0, then one root is real and two are complex
conjugates
(ii) if D = 0, then all roots are real, and at least two are
equal
(iii) if D < 0, then all roots are real and unequal
Cubic  Equa<on  (Cardano’s  Formula)  
The roots of are (prove it???)

If are roots of the equation

then
MATLAB  Implementa<on  
Write a Matlab solver to calculate roots of cubic
equations.
MATLAB  Implementa<on  
function [x,y] = CardanoFormula(a,b,c,d)
% Returns roots and discriminant of cubic equations
% ax^3 + bx^2 + cx + d = 0

x = zeros(3,1);

Q = ((3*a*c)-(b^2))/(9*a^2);
R = ((9*a*b*c)-(27*a^2*d)-(2*b^3))/(54*a^3);

y = sqrt(Q^3 + R^2);

u = (R+y)^(1/3);
v = (R-y)^(1/3);

Bb = u + v;
zz1 = -(1/2)*Bb + (1/2)*sqrt(-1)*sqrt(3)*sqrt(Bb^2+4*Q);
zz2 = -(1/2)*Bb - (1/2)*sqrt(-1)*sqrt(3)*sqrt(Bb^2+4*Q);

% Roots of the cubic equation


x(1) = BB - b/(3*a);
x(2) = -b/(3*a) + zz1;
x(3) = -b/(3*a) + zz2;
MATLAB  Implementa<on  
The solver can be downloaded at:

http://people.bu.edu/andasari/courses/Fall2015/CardanoFormula.m
Polynomial  Division  
Divide by

. .
The  Factor  Theorem  
If is a root of the equation then
is a factor of
Example:
Factorize and use it to solve the cubic
equation
Let
If

Since then is a factor.


Next, we divide by the factor

Use  factoriza7on  or  


   quadra7c  formula  

. .
Hence

From which we get


The  Remainder  Theorem  
For quadratic equations, the remainder theorem states

If is divided by
the remainder will be

For cubic equations, the remainder theorem states

If is divided by
the remainder will be
Bairstow’s  Method  
Bairstow’s method is an algorithm used to find the roots
of a polynomial of arbitrary degree (usually order 3 and
higher). The method divides a polynomial
(2.8)

by a quadratic function , where r and s


are guessed. The division gives us a new polynomial
(2.9)

and the remainder (2.10)


Bairstow’s  Method  
The quotient and the remainder are
obtained by the standard polynomial division.

The coefficients can be calculated by the following


recurrence relationship
(2.11a)

(2.11b)
(2.11c)
Bairstow’s  Method  
If is an exact factor of then the
remainder is zero and the roots of
are the roots of . The Bairstow’s method reduces
to determining the value of r and s such that ,
hence, Because b0 and b1 are functions of
r and s, they can be expanded using Taylor series, as:

(2.12a)

(2.12b)
Bairstow’s  Method  
By setting both equations equal to zero

(2.13a)

(2.13b)

To solve the system of equations above, we need partial


derivatives of b0 and b1 with respect to r and s. Bairstow
showed that these partial derivatives can be obtained by
a synthetic division of the b’s in a fashion similar to the
Bairstow’s  Method  
way in which the b’s themselves were derived, that is
by replacing ai’s with bi’s, and bi’s with ci’s, such that,

(2.14a)
(2.14b)
(2.14c)
where
Bairstow’s  Method  
Then substituting into equations (2.13a) and (2.13b)
gives

These equations can be solved for Δr and Δs, which can


be used to improved the initial guess of r and s.

At each step, an approximate error in r and s estimated as

and (2.15)
Bairstow’s  Method  
If and where is a stopping
criterion, the values of the roots can be determined by

(2.16)

At this point, there exist three possibilities


(1) If the quotient polynomial fn-2 is a third (or higher)
order polynomial, the Bairstow’s method can be
applied to the quotient to evaluate new values for
r and s. The previous values of r and s can serve as
the starting guesses.
Bairstow’s  Method  
(2) If the quotient polynomial fn-2 is a quadratic function,
then use eqn. (2.16) to obtain the remaining two
roots of fn(x).
(3) If the quotient polynomial fn-2 is a linear function,
then the single remaining root is given by
(2.17)
Newton-­‐Raphson  Method  
The Newton-Raphson, or simply Newton’s method is
one of the most useful and best known algorithms that
relies on the continuity of derivatives of a function. The
method is usually used to to find the solution of
nonlinear equations f(x) = 0 whose derivatives, f′(x) and
f′′(x), are continuous near a root.

We can derive the formula for Newton’s method from


Taylor series of 1st order:
(2.18)
Newton-­‐Raphson  Method  
Setting the left hand side, f(xi+1) to zero and solving for
xi+1, we get
(2.19)

which is the Newton’s iteration function for finding root


of the equation f(x) = 0.
Newton-­‐Raphson  Method  
Order of a Root

Assume that f(x) and its derivatives f′(x), f′′(x), … f(M)(x)


are defined and continuous on an interval about x = p.
We say that f(x) = 0 has a root of order M at x = p if and
only if
f(p) = 0,
f′(p) = 0, …,
f(M-1)(p) = 0 (2.20)
and
f(M)(p) ≠ 0
Newton-­‐Raphson  Method  
For:
- root of order M = 1, it is called a simple root
- M > 1 it is called a multiple root
- M = 2, it is called a double root
- etc
Newton-­‐Raphson  Method  
If p is a root of a function

then the function f(x) has a simple root at p = −2 and a


double root at p = 1. This can be verified by considering
the derivatives and .
At the value p = −2, we have:
f(−2) = 0 and f′(-2) = 9, so M = 1, hence p = −2 is a
simple root.
At the value p = 1, we have:
f(1) = 0, f′(1) = 0, and f′′(1) = 6, so M = 2 and p = 1 is
a double root.
MATLAB  Implementa<on  
function x0 = newtonRaphson()

x0 = 1.2;
iter = 0;

while abs(f(x0)) > 1e-4


iter = iter + 1;
x1 = x0 - f(x0)/fprime(x0)
x0 = x1;
end

disp(['roots found after ', num2str(iter), ' iterations']);

function y = f(x)
y = x^3 - 3*x + 2;

function y = fprime(x)
y = 3*x^2 – 3;
MATLAB  Implementa<on  
Using MATLAB’s built-in functions

The polynomial is evaluated


at

>> p = [1 0 -7 -6];
>> polyval(p, [1 2 3])

ans

-12 -12 0
MATLAB  Implementa<on  
Using MATLAB’s built-in functions

Evaluate the derivative by

>> polyder(p)

ans

3 0 -7
MATLAB  Implementa<on  
Using MATLAB’s built-in functions
To find roots of

>> a = [1 -3.5 2.75 2.125 -3.875 1.25];


>> r = roots(a)

r =

2.0000
-1.0000
1.0000 + 0.5000i
1.0000 – 0.5000i
0.5000
MATLAB  Implementa<on  
All computations in MATLAB are done in double precision.
To switch between different output, use the command
“format” (type “help format” for more info).
>> format long
>> r = roots(a)

r =

2.000000000000005
-1.000000000000000
0.999999999999998 + 0.500000000000001i
0.999999999999998 - 0.500000000000001i
0.500000000000000
References  

•  Numerical  Methods  for  Engineers,  S.C.  Chapra  


and  R.P.  Canale.  
•  Numerical  Methods  Using  MATLAB,  John  H.  
Mathews  and  Kur7s  D.  Fink.  

You might also like