Iterative Methods
Iterative Methods
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)
(i) By cross-multiplying
(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)
(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);
ans
0.6667 + 0.4714i
0.6667 - 0.4714i
where
Cubic
Equa<on
(Cardano’s
Formula)
Letting
we obtain (2.7)
Cubic
Equa<on
(Cardano’s
Formula)
Substituting k back to u
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);
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
. .
Hence
If is divided by
the remainder will be
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)
(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)
(2.14a)
(2.14b)
(2.14c)
where
Bairstow’s
Method
Then substituting into equations (2.13a) and (2.13b)
gives
and (2.15)
Bairstow’s
Method
If and where is a stopping
criterion, the values of the roots can be determined by
(2.16)
x0 = 1.2;
iter = 0;
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
>> p = [1 0 -7 -6];
>> polyval(p, [1 2 3])
ans
-12 -12 0
MATLAB
Implementa<on
Using MATLAB’s built-in functions
>> polyder(p)
ans
3 0 -7
MATLAB
Implementa<on
Using MATLAB’s built-in functions
To find roots of
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