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) + …
The general form of polynomial equations
• Linear equation (or polynomial of order 1) • Quadratic equation (or polynomial of order 2) • Cubic equation (or polynomial of order 3)
(2.1)
Simple Linear Equa<ons
(1) Solve
(i) By cross-multiplying
(ii) Removing brackets
(iii) Rearranging
(2) Solve
Quadra<c Equa<ons
two unequal real roots
The expression is called the discriminant.
Roots of a general quadratic eqn.
two unequal complex roots the roots are real and equal
Quadratic Formula 1
(2.2)
are (2.3) x1,2 =
�b±pb
2 � 4ac
2a
Quadra<c Equa<ons
How do we get these roots? Assume that the equation factors as
Roots of a general quadratic eqn.
Quadratic Formula 2 (from Lagrange resolvents)
are
(2.4)
(2.5)
x
2 + px+ q = (x� ↵)(x� �)
Continue!
MATLAB Implementa<ons
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);
Create a solver by writing functions, for example:
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): This solver can be downloaded at: http://people.bu.edu/andasari/courses/Fall2015/quadraticSolver.m
>> quadraticSolver(3,-4,2)
ans
0.6667 + 0.4714i 0.6667 - 0.4714i
Tschirnhaus Transforma<on
be a polynomial of order n Let
where
Then the substitution
converts Pn into a depressed polynomial
Cubic Equa<on (Cardano’s Formula)
is by the substitution
The cubic equation
reduced to
Letting
(2.6)
(2.7) we obtain
Cubic Equa<on (Cardano’s Formula)
Solving using the quadratic formula, we get
The 6th order polynomial can be solved by using the quadratic formula, by taking and the equation reduces to
Cubic Equa<on (Cardano’s Formula)
Substituting k back to u
or
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)
Putting
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
and
is called the discriminant.
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 equationx(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
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.
The Remainder Theorem For quadratic equations, the remainder theorem states
For cubic equations, the remainder theorem states
is divided by If the remainder will be
is divided by If 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
are guessed. The division gives us a new polynomial by a quadratic function
and the remainder
, where r and s
(2.8)
(2.9)
(2.10)
Bairstow’s Method
recurrence relationship
obtained by the standard polynomial division. The quotient and the remainder are
The coefficients can be calculated by the following
(2.11c)
(2.11b)
(2.11a)
Bairstow’s Method
to determining the value of r and s such that ,
remainder If is an exact factor of then the
are the roots of . is zero and the roots of
hence, Because b0 and b1 are functions of
The Bairstow’s method reduces
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
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
(2.13b)
(2.13a)
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,
where
(2.14a)
(2.14b)
(2.14c)
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 criterion, the values of the roots can be determined by
At this point, there exist three possibilities (1) If the quotient polynomial fn-2 is a third (or higher)
where is a stopping
(2.16)
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 which is the Newton’s iteration function for finding root of the equation f(x) = 0.
(2.19)
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 and f(M)(p) ≠ 0
(2.20)
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
>> p = [1 0 -7 -6];>> polyval(p, [1 2 3])
ans
-12 -12 0
at
The polynomial is evaluated
Using MATLAB’s built-in functions
MATLAB Implementa<on
>> polyder(p)
ans
3 0 -7
by Evaluate the derivative
Using MATLAB’s built-in functions
MATLAB Implementa<on
>> a = [1 -3.5 2.75 2.125 -3.875 1.25];>> r = roots(a)
r =
2.0000 -1.0000
1.0000 + 0.5000i1.0000 – 0.5000i0.5000
To find roots of Using MATLAB’s built-in functions
MATLAB Implementa<on
>> format long>> r = roots(a)
r =
2.000000000000005 -1.000000000000000 0.999999999999998 + 0.500000000000001i 0.999999999999998 - 0.500000000000001i 0.500000000000000
All computations in MATLAB are done in double precision. To switch between different output, use the command “format” (type “help format” for more info).