You are on page 1of 31

CE 6011

Non linear equations


in MATLAB
Lecture 7
Riddhi Singh
Email: riddhi@iith.ac.in
1

Todays outline
Non-linear equations
System of non-linear equations

NON-LINEAR EQUATIONS

A non-linear system does not follow the rules of a


linear system: additivity and homogeneity

additivity : f ( x y ) f ( x) f ( y )
homogeneity : _______________________
superposition : _______________________

An equation, f(x)=K, is linear if it satisfies the principles above,


nonlinear otherwise
4

f(x)

g(x)

x
Linear system

x
Nonlinear system

Examples of non linear equations

f ( x) x 2 x 1
f ( x) sin( x)
f ( x) x1/3 1
f ( x) log( x ) 2
2

....

Non linear equations can have one or more than


one (system of equations) unknowns
1. ______ unknown solution is a ___________________

f ( x) x x 1
2

f ( x) sin( x)
2. ______________ unknown: _______________________

f1 ( x) x x2 1
2
1

f 2 ( x) sin( x1 ) cos(x 2 )
In case of more than one unknown, the solutions is a _______
7

We need to find the value of x at which:


1. One unknown solution is a scalar

f ( x)
2. More than one unknown: system of non-linear equations

fi ( x )
Also termed, ___________
8

Case I. Single unknown: All method are iterative


1.
2.
3.
4.
5.

_____________
_____________
_____________
_____________
_____________

identification
method
method
method
method

Case II. Multiple unknowns in a system of nonlinear equations

Increasing complexity

Each method uses more information about f(x)


than the previous one
Method

Information used

Interval identification

Signs of f(x)

Bisection

Signs of f(x)

False position

Signs and values of f(x)

Newton-Raphson

Values of f(x) and its


derivatives

Secant

Values of f(x), computes


derivatives using f(x)
10

NON-LINEAR EQUATIONS
WITH ONE UNKNOWN
11

MATLAB has inbuilt solvers to solve any type of


equation. The key command is solve
%define an unknown
>> syms x;
%solve a nonlinear equations in x
>>solve(x^3-3*x+1)

%get the output in numbers


>>eval(solve(x^3-3*x+1))
%define a system of equations:
>> syms x1 x2 x3
>> S = solve('x1+x2+x3=3','x1^2+x2^2+x3^2=5','exp(x1)+x1*x2-x1*x3=1')
>> Sx1 = S.x1;
>> Sx2 = S.x2;
>> Sx3 = S.x3;

12

Method I. Interval identification is based on the


Intermediate value theorem
If a function f is continuous on the closed interval [a,b], and if f(a)yf(b)
or f(b)yf(a), then there exists a point c such that acb and f(c)=y

f(x)

If a root of f(x) lies in the interval [a,b],


then at some point r,
f(r) =_____. Therefore, f(a)and f(b) are
of ____________ signs, or

f (a ) 0 f (b)

13

Method I. Interval identification algorithm*


1. Start with a guess (eg. xo=0) and interval width x
2. Let x1=xo and x2=xo + x
3. While f(x1)*f(x2)>0
new x1 = x2
new x2 = x1 + x
4. Root lies in the interval [x1,x2]

*Limitations:
1. Cannot detect double roots
2. Cannot detect closely spaced roots if the chosen interval
is too large
14

Method 2. Bisection method is an extension of


the interval identification method
Repeat the interval identification method for successively small intervals
If a root of f(x) lies in the interval
[a,b], then construct a new interval,
c=(a+b)/2. Reevaluate:

f(x)

f (a ) * f (c), and

c
a

f (b) * f (c)
15

Method 2. Bisection method algorithm*


1. If the root lies in the interval [x1,x2]
2. While error>tolerable error
c=(x1+x2)/2
error = (x2-x1)/2
If f(x1)*f(c)>0
x1=c
Else
x2=c
*Limitations:
1. Slow convergence than other methods that use more
information
16

Method 3. False position is an extension of the


interval identification method
Instead of using the mid-point, this method uses the point where the secant
between f(a) and f(b) intersects the x-axis
The triangles formed by the secant
are similar, therefore:

f(x)

bc
ca

f (b) f (a )

b, f(b)

a c

a, f(a)
17

Method 3. False position algorithm (faster than


bisection)
1. If the root lies in the interval [x1,x2]
2. While error>tolerable error
c= af (b) bf (a )
f (b) f (a )
If f(x1)*f(c)>0
x1=c
Else
x2=c
*Limitations:
1. May select the same endpoint- in that case will converge
slowly

18

Method 4. Newton-Raphson approximates the


curve with a tangent
This method assumes that the function f is differentiable.

The curve at xo is approximated


using:

tangent

l ( x) f ( xo )( x xo ) f ( xo )
x1 xo

y=f(x)
0

x1

xo

19

Method 4. Newton-Raphson algorithm


1. Assume an initial estimate of the root, xo
2. fx=f(xo), fp=f(xo)
3. While precision>prescribed_precision
x=x- fx/fp
fx= f(x)
fp=f(x)
precision= abs(fx/fp);
*Limitations:
1. Sensitive to the nature of the function may get trapped
if the tangent to the curve is parallel to the x-axis
2. Detects a multiple root (root of the function is also a
root of its derivative) only with linear convergence

20

Method 5. Secant method approximates the


derivative instead of estimating them analytically
This method is the same as Newton-Raphson except that the derivatives
are approximated
secant

The derivative at xo is approximated


as:

f ( x h) f ( x )
f ( xo ) lim
h 0
h
f ( xn 1 ) f ( xn )

f ( xn )
xn 1 xn

y=f(x)
0

xn+1

xn

xn-1

xn 1 xn ____________ f ( xn )
21

Method 5. Secant method algorithm


1. Assume two intial intervals in which the root will lie, x1 and x2
2. fx1=f(x1), fx2=f(x2)
3. While precision>prescribed_precision
x1 = x2
fx1 = fx2
fp = (fx2-fx1)/(x2-x1)
x2 = x2-fx2/fp
precision = fx2/fp

*Limitations:
1. Slower than Newton-Raphson (although faster than bisection)
2. Can diverge instead of converging
22

SYSTEM OF NONLINEAR
EQUATIONS
23

Goal: to identify the vector, x such that:


f1 ( x1 , x2 ,..., xn ) 0
f 2 ( x1 , x2 ,..., xn ) 0
.
.
.
f n ( x1 , x2 ,..., xn ) 0
Matrix notation:

F ( X) 0
24

The ___________ : derivatives for vectors


In case of an unknown vector, the derivative of the function can be
estimated w.r.t each component of the vector
Suppose, vector X is defined as:

X [ x1 , x2 ,..., xn ]
Then, the derivative of a function, f, w.r.t the vector
X is given by the ________ vector:

F1 F1
F1
J
,...,

x
n
1 2
25

The Jacobian for a system of equations is:


System

f1 ( x1 , x2 ,..., xn ) 0
f 2 ( x1 , x2 ,..., xn ) 0
.
.
.
f n ( x1 , x2 ,..., xn ) 0

Jacobian matrix

f1
f1
x . . . x
n
1

f 2
f 2
x . . . x
n
1
.
J .

.
.
.
.

f n . . . f n
x1
xn

26

Newton-Raphson is extended to nonlinear


systems by using the matrix notation*:
X k 1 X k [F '( X k )]1 F ( X k )
X

k 1

k 1

X [ J ] F( X )
k

( X k 1 X k ) [ J k ]1 F( X k )
J (X
k

k 1

X ) F ( X )
k

J k H k F ( X k )
Solving the Jacobian linear systems yields the value of the
vector for the next time step
*Derivation is based on _____________ expansion.
27

Example: Solve the following linear system using


Newton-Raphson

x y z 3
x y z 5
2

e xy xz 1
x

28

Step 1. Find the Jacobian (analytically)

J ?
?

?
?
?

?
?
29

Step 2. Implement Newton-Raphson for vectors


1. Assume an initial estimate of the root vector
x=[xo, x1,, xn]
2. While precision>required_precision
Estimate, F=f(x)
Estimate, J=Jacobian(x)
Solve: JH=-F
X = X+H
precision= norm(H);

In the same manner, the secant method can be extended to a


system of non-linear equations
30

Method

Convergence formula

Convergence type

Interval identification

---

---

Bisection

False position

log(b a ) log(2 )
log 2

Linear

(an r ) f (r )
2 f (r ) f (r )(en 1 an r )

Linear

en 1

Newton-Raphson

1 f ( n ) 2
en
en 1
2 f ( xn )

Quadratic

Secant

1 f (r )
en 1
en en 1

2 f (r )

Super linear

Increasing complexity

Convergence of these methods generally depends on


the required precision and initial guesses

31