0% found this document useful (0 votes)
16 views50 pages

Numerical Method Nonlinear II

Uploaded by

namfghj731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views50 pages

Numerical Method Nonlinear II

Uploaded by

namfghj731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Numerical Methods

Roots of Non-linear equations

Thai Minh Quan - Numerical Methods 1


Contents
1. Introduction
2. Roots of Non-linear equations
1. Bisection method
2. Newton-Raphson method
3. Roots of polynomials
4. Roots of systems of non-linear equations
3. Systems of linear equations
4. LU decomposition
5. Linear Programming
6. Numerical Differentiation and Integration
Thai Minh Quan - Numerical Methods 2
Roots of Non-linear equations
 Roots of polynomials
 Polynomials
 roots
 Roots of systems of non-linear equations
 Fixed-point iteration
 Newton-Raphson

Thai Minh Quan - Numerical Methods 3


Roots of Non-linear equations Polynomials

 Polynomials: the general form


n
f n ( x)   ai x i
n 1
f n ( x)  an x  an 1 x
n
 ...  a1 x  a0 or
i 0

 where n is the order of the polynomial, and the a’s are


constant coefficients
 Polynomials have many applications in engineering and
science.
 They are used extensively in curve-fitting.
 One of their most interesting and powerful applications is in
characterizing dynamic systems and, in particular, linear systems.
Examples include mechanical devices, structures, and electrical
circuits.
Thai Minh Quan - Numerical Methods 4
Roots of Non-linear equations Polynomials

 Polynomials are a special type of nonlinear algebraic


equation
f n ( x)  an x n  an 1 x n 1  ...  a1 x  a0  0 or f n ( x)  0

 The solutions of this equation are called the roots of the


polynomial, In general, an nth order polynomial will have n
roots (can be real and/or complex)
 If n is odd, there is at least one real root.
 they are the zeroes of the function f (corresponding to the
points where the graph of f meets the x-axis)

Thai Minh Quan - Numerical Methods 5


Roots of Non-linear equations Polynomials

 A polynomial function in one real variable can be represented


by a graph

The graph of a polynomial The graph of a polynomial The graph of a polynomial


function of degree 2 function of degree 3 function of degree 6

Thai Minh Quan - Numerical Methods 6


Roots of Non-linear equations Polynomials

Characteristics of polynomials
 The relation between the roots of a polynomial and its
coefficients is described by Vieta's formulas

f ( x)  ax 2  bx  c

Roots x1, x2 of the equation f(x) = 0 satisfy

b c
x1  x2   , x1 x2 
a a

Thai Minh Quan - Numerical Methods 7


Roots of Non-linear equations Polynomials

 In general case, Vieta's formulas

Thai Minh Quan - Numerical Methods 8


Roots of Non-linear equations Polynomials

 To find the roots of any given monic polynomial, two problems


need to be solved:
1. construct a square matrix A whose characteristic polynomial
2. find the eigenvalues of this matrix A

Thai Minh Quan - Numerical Methods 9


Roots of Non-linear equations Polynomials
Companion matrix
In general, the monic polynomial of degree n

An n-by-n matrix
A companion matrix (square matrix)

Characteristics: xi is a root of the polynomial p(x)

xi is also a eigenvalue of the companion matrix A


Thai Minh Quan - Numerical Methods 10
Roots of Non-linear equations Polynomials

 Example
 Suppose we have a polynomial

Dividing by a1 and rearranging yields

A special matrix
(5x5) Calculate the
eigenvalues?
polynomial’s
companion matrix

Thai Minh Quan - Numerical Methods 11


Roots of Non-linear equations Polynomials

 Example
 Suppose we have a polynomial f ( x)  x 3  7 x  6

polynomial’s companion matrix

0 7  6 
A  1 0 0 
0 1 0 

Thai Minh Quan - Numerical Methods 12


Roots of Non-linear equations Polynomials

Eigenvalue
 The eigenvalues of matrix A are values of λ that satisfy the
equation

 The fundamental theorem of algebra implies that the


characteristic polynomial of an n by n matrix A, being a
polynomial of degree n, can be factored into the product of n
linear terms

Roots

Eigenvalues : characteristic roots, characteristic values, proper values

Thai Minh Quan - Numerical Methods 13


Roots of Non-linear equations Polynomials
Case study 1
Find the eigenvalue of a matrix

Step 1: We need to solve the equation

Step 2: Calculation

Step 3: calculate the determinant: det


  0

  2
  3

Thai Minh Quan - Numerical Methods 14


 Example
Find the eigenvalue of a matrix

x1 = 2, x2 = 3

Thai Minh Quan - Numerical Methods 15


Roots of Non-linear equations Systems of non-linear equations
Case study 2
Find the roots of a polynomial f ( x)  x 3  7 x  6

Step 1: the companion matrix


0 7  6 
A  1 0 0 
0 1 0 

Step 2: The eigenvalues of A   1



  2
  3

Step 3: The eigenvalues of A are the polynomial roots

x1  1, x2  2, x3  3

Thai Minh Quan - Numerical Methods 16


 Example
Find the roots of a polynomial

X1 = 4, x2 = -1, x3 = -3

Thai Minh Quan - Numerical Methods 17


 Roots of polynomials
 Bisection and Newton-Raphson method for real roots
Müller and Bairstow methods for real/complex roots (p.181)

Thai Minh Quan - Numerical Methods 18


 Roots of polynomials
 Polynomials
 roots
 Systems of non-linear equations
Fixed-point iteration
Newton-Raphson

Thai Minh Quan - Numerical Methods 19


Roots of Non-linear equations Systems of non-linear equations

 Objectives: the primary objective is to find the root of a system


of nonlinear equation

Example

the solution is the intersection of the curves

Thai Minh Quan - Numerical Methods 20


Roots of Non-linear equations Systems of non-linear equations

 Recall that the Newton-Raphson method was predicated on


employing the derivative (that is, the slope) of a function to
estimate its intercept with the axis of the independent
variable—that is, the root.

Thai Minh Quan - Numerical Methods 21


Roots of Non-linear equations Systems of non-linear equations

Newton-Raphson f ( x)  0

the first derivative at x is


equivalent to the slope

Single-equation forme
Newton-Raphson

Systems of non-linear equations

Thai Minh Quan - Numerical Methods 22


Roots of Non-linear equations Systems of non-linear equations

 This estimate was based on a first-order Taylor series expansion

xi+1 is solution

which is the single-equation form of the Newton-Raphson method.


=> The multi-equation form is derived in an identical fashion.
However, a multivariable Taylor series must be used

Thai Minh Quan - Numerical Methods 23


Roots of Non-linear equations Systems of non-linear equations

 Newton-Raphson
the two-equation case

u ( x, y )  0 a first-order
 Taylor series
 v( x, y )  0

the two-equation Newton-Raphson

Thai Minh Quan - Numerical Methods 24


Roots of Non-linear equations Systems of non-linear equations

u ( x, y )  0
 Newton-Raphson 
 v( x, y )  0

the two-equation Newton-Raphson

The two-equation Newton-Raphson approach can


be generalized to solve n simultaneous equations determinant of the
Jacobian of the system
it can be employed iteratively to home in on
the roots of two simultaneous equations.
Thai Minh Quan - Numerical Methods 25
Roots of Non-linear equations Systems of non-linear equations

Newton-Raphson
Input: a continuous function u, v
1. Evaluate u′(x,y), v′(x,y) symbolically

2. Use an initial guess of the root xi, yi to estimate the new value
of the root xi+1, yi+1 as

3. Find the relative approximate error

Thai Minh Quan - Numerical Methods 26


Case study 1
Use the multiple-equation Newton-Raphson method to determine
roots of equations

Thai Minh Quan - Numerical Methods 27


Case study 1
Step 1: Initiate the computation with guesses
x  1.5 , y  3.5

Step 2: The first derivatives of the function can be evaluated

Thai Minh Quan - Numerical Methods 28


Case study 1
Step 3: the determinant of the Jacobian for the first iteration

 6.5(32.5)  1.5(36.75)  156.25

Step 4: The values of the functions can be evaluated at the initial


guesses

Thai Minh Quan - Numerical Methods 29


Case study 1
Step 5: These values can be substituted into the two-equation
Newton-Raphson

Step 6: the results are converging to the true values of x = 2 and y =


3. The computation can be repeated until an acceptable accuracy
is obtained

Thai Minh Quan - Numerical Methods 30


Case study 2
Use the multiple-equation Newton-Raphson method to determine
roots of equations 5
Two equations

 x 2  y 2  10 2


2 x  y  1
1

y
-1

-2

X0= 2 -3

Y0 = -2 -4

-5
-5 -4 -3 -2 -1 0 1 2 3 4 5
Thai Minh Quan - Numerical Methods x 31
Exercise
1. Use the Newton-Raphson method to determine roots of equations

3 iterations, initial guess: x1 = 3.5

2. Use the multiple-equation Newton-Raphson method to


determine roots of equations
3 iterations, initial guess:
x1 = 0.8
x2 = 1.8

Thai Minh Quan - Numerical Methods 32


Exercise
2. Use the multiple-equation Newton-Raphson method to
determine roots of equations
2 iterations, initial guess:
x1 = 0.8
x1 = 1.8

Thai Minh Quan - Numerical Methods 33


Matlab

Thai Minh Quan - Numerical Methods 34


Matlab

In addition to ones, eye, zeros, rand and randn

Thai Minh Quan - Numerical Methods 35


Exercise
%% bisection
f=@(x)(x^3-x-2)
a=1
b=2
[p,i] = bisection(f,a,b)
Write the function: bisection(f,a,b) to solve the

Thai Minh Quan - Numerical Methods 36


Matlab
clc
clear all
close all
%%
eps=10^-8;
f=@(x)(x^2+2*x-3);
a=-5;
b=0;
while (b-a)>eps
x=(a+b)/2;
if sign(f(x))== sign(f(a))
a=x;
else
b=x;
end;
end
fprintf('root of quadratic equation x');
x

Thai Minh Quan - Numerical Methods 37


Matlab
function [ x ] = bisection(f,x_l,x_u,esp_s)
clc e=1;
clear all x_old=x_u;
close all while e>esp_s
%% x_new=(x_l+x_u)/2;
esp_s=10^(-8); if f(x_new)==0
a= 1; b=-6; c= 11; d=-6 x=x_new;
f=@(x)(a*x^3+b*x^2+c*x+d); else
x=0;y=f(x); if f(x_new)*f(x_l)>0
l=0;u=1.5;iter=0; x_l=x_new;
while (abs(y)>esp_s)&&(iter<=5000) else
x=bisection(f,l,u,esp_s); x_u=x_new;
l=l-1;u=u+1; end
y=f(x); e=abs((x_new-x_old)/x_new);
iter=iter+1; x_old=x_new;
end end
x x=x_new;
end

Thai Minh Quan - Numerical Methods 38


Find the root of a non-linear equation f=@(x)(x^3-x-2)

The fzero function is designed to find the real root of a single equation.
A simple representation of its syntax is fzero(function,x0) or fzero(function,[x0 x1])

Step 1: To find a zero of the function f(x) = x3 – x – 2, write an anonymous function


f=@(x)(x^3-x-2)

Step 2: Then find the zero near one guess

z = fzero(f,2) z  1.5214

options=optimset('Display','iter');%Option to display output


[x,fval] = fzero(f,2,options)

Thai Minh Quan - Numerical Methods 39


Case study 1-Matlab
Find the eigenvalue of a matrix

Step 1: We need to solve the equation

Step 2: Calculation

A  [3 6  8 ;0 0 6;0 0 2;]

Step 3: calculate the determinant


syms    0

  2
det( A   I )   3

Thai Minh Quan - Numerical Methods 40


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6
Step 1: the companion matrix
u  [1 0  7 6]
0 7  6 
A  diag  ones  n  1,1 , 1 ; A  1 0 0 
0 1 0 
A 1,:   u  2 : n  1 / u 1 ;

Step 2: The eigenvalues of A   1



eig ( A)   2
  3

Step 3: The eigenvalues of A are the polynomial roots

x1  1, x2  2, x3  3

Thai Minh Quan - Numerical Methods 41


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

%
u = [1 0 -7 6] A=
n= 3
A = diag(ones(n-1,1),-1); 0 7 -6
A(1,:) = -u(2:n+1)/u(1); 1 0 0
x = eig(A) 0 1 0
%

Thai Minh Quan - Numerical Methods 42


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

2nd method:

c  [1 0  7 6] 0 7  6 
A  1 0 0 
A  compan(c) 0 1 0 

Thai Minh Quan - Numerical Methods 43


Case study 2 - Matlab
3rd method:

Step 1: coefficients of polynomial


syms x
f  x3  7 x  6
c  sym2poly( f )

Step 2: the companion matrix


0 7  6 
A  compan(c) A  1 0 0 
0 1 0 

Thai Minh Quan - Numerical Methods 44


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

clc
clear all
close all
%% CALCULATE THE ROOT OF POLYNOMINALS F = X^3 - 7X + 6
u = [1 0 -7 6]
n = 3
A = diag(ones(n-1,1),-1);
A(1,:) = -u(2:n+1)/u(1);
x = eig(A)

Thai Minh Quan - Numerical Methods 45


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

clc
clear all
close all
%% CALCULATE THE ROOT OF POLYNOMINALS F = X^3 - 7X + 6

% 2nd method
c = [1 0 -7 6]
A = compan(c)
x = eig(A)

Thai Minh Quan - Numerical Methods 46


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

clc
clear all
close all
%% CALCULATE THE ROOT OF POLYNOMINALS F = X^3 - 7X + 6

% 3rd method
syms x
f = x^3 -7*x + 6
c = sym2poly(f)
A = compan(c)
x = eig(A)

Thai Minh Quan - Numerical Methods 47


Case study 2 - Matlab
Find the roots of a polynomial f ( x)  x 3  7 x  6

clc
clear all
close all
%% CALCULATE THE ROOT OF POLYNOMINALS F = X^3 - 7X + 6

% 4th method
syms x
f = x^3 -7*x + 6
c = sym2poly(f)
x = roots(c)

p = poly(x)

Thai Minh Quan - Numerical Methods 48


Case study 3 - Matlab
Find the roots of a system

%% Solver of non linear systems:


x=[1.5 3.5]'; % initial guess
N = 5000;
n = 2;
for k=1:N,
F=[ x(1)*x(1)+ x(1)*x(2) - 10 ; x(2) + 3*x(1)*x(2)*x(2)-57];
J=[2*x(1)+x(2), x(1) ; 3*x(2).^2 , 1 + 6*x(1).*x(2)];
dx=J\F;
x=x-dx
k=k+1
pause
end
x'

Thai Minh Quan - Numerical Methods 49


Case study 3 - Matlab
Find the roots of a system

clc
clear all
close all function F = myfun(x)

fun = @myfun; F(1) = x(1)^2 + x(1)*x(2) - 10;


x0 = [0,0]; F(2) = x(2) +3*x(1)*x(2)^2 -57 ;
options=optimset('Display','iter');
%Option to display output
[x,fval] = fsolve(fun,x0,options)

Thai Minh Quan - Numerical Methods 50

You might also like