roots of nonlinear equations 1roots of nonlinear equations 1 · roots of equations mechanical...

Post on 24-Aug-2020

6 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Engineering Computation

Roots of NonLinear Equations 1Roots of NonLinear Equations_1

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 1

Roots of Equations

Obj tiObjective:Solve for x, given that f(x) = 0Solve for x, given that f(x) 0

-or-Equivalently, solve for x such that

g(x) = h(x) ==> f(x) = g(x) – h(x) = 0g(x) h(x) f(x) g(x) h(x) 0

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 2

Roots of Equations

Chemical Engineering (C&C 8.1, p. 187): van der Waals equation; v = V/n (= volume/# moles)van der Waals equation; v V/n ( volume/# moles)

Find the molal volume v such thata2

af(v) = (p + )(v - b) - RT = 0v

Known data:

p = pressure,

T = temperature,

R = universal gas constantR = universal gas constant,

a & b = empirical constants

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 3

Roots of Equations

Civil Engineering (C&C Prob. 8.17, p. 205):

Find the horizontal component of tension, H, in a cable that passes through (0 y0) and (x y)cable that passes through (0,y0) and (x,y)

0H wxf(H) = cosh -1 + y - y = 0

Known data:

0f(H) cosh 1 y y 0

w H

Known data:. w = weight per unit length of cable. y0. y0. (x,y)

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 4

Roots of Equations

Electrical Engineering (C&C 8.3, p. 194): Find the resistance, R, of a circuit such that theFind the resistance, R, of a circuit such that the charge reaches q at specified time t

t

2-Rt 2L

0

1 R qf(R) = e cos - - = 0LC 2L q

Known data:

. L = inductance,

. C = capacitance,. C capacitance,

. q0 = initial chargeq t

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 5

. q, t

Roots of Equations

Mechanical Engineering (C&C 8.4, p. 196):Find the value of stiffness k of a vibrating mechanical system

h th t th di l t (t) b t t 0 5such that the displacement x(t) becomes zero at t= 0.5 s. The initial displacement is x0 and the initial velocity is zero. The mass m and damping c are known and λ = c/(2m)The mass m and damping c are known, and λ = c/(2m).

- t0x(t) = x e cos t + sin t = 0

2k cμ= - 0x(t) x e cos t sin t 0

Known data:

2μm 4m

. x0

. m, c , λ = c/(2m). m, c , λ c/(2m)

. t=0.5

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 6

Roots of Equations

Determine real roots of :Determine real roots of :

• Algebraic equations (including polynomials)

• Transcendental equations such as f(x) = sin(x) + e-x

• Combinations thereof

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 7

Roots of Equations

• Graphical methods:• Graphical methods:– Determine the friction coefficient c necessary for a

parachutist of mass m=68.1 kg to have a speed of 40 p g pm/seg at 10 seconds (g: gravity acceleration, 9.81 m/s2).

– Reorganizing.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 8

Roots of Equations

Two positions for focusing the general root finding problem:

- Global methods:

. Accurate calculation of ALL the solutions:

research, not completely solved problem. , p y p

(Simple example solved : roots of a 2nd degree polynomial)

- Local methods:

Starting with some local information on the roots. Starting with some local information on the roots

(most common techniques)

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 9

Roots of Equations

Two Fundamental Approachespp1. Bracketing or Closed Methods

Bisection Method- Bisection Method

- False-position Method (Regula falsi).

2. Open Methods- Newton-Raphson Methodp

- Secant Method

Fi d i t M th d- Fixed point Methods

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 10

Bracketing Methodsf( )f(x) In Figure a) we have the case of f(xl)

and f(xu) with the same sign, and there is no root in the interval (x x )

f(x)a) x

is no root in the interval (xl,xu).

In Figure b) we have the case of f(xl)

b) x

and f(xu) With different sign, and there is a root in the interval (xl,xu).

f(x)b) x

In Figure c) we have the case of f(xl) and f(xu) with the same sign, and there

t tf(x) c) x are two roots.

In Figure d) we have the case of f(xl)

xl xd) x

g ) ( l)and f(xu) with different sign, and there is an odd number of roots.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 11

xud)

Bracketing Methods

• Though the cases above are generally valid, there are cases in which they do not hold.

In Figure a) we have the case of f(xl) and f(xu) with different sign, but there is

d bl t

f(x)

a double root.

f(x)a) x

In Figure b) We have the case of f(xl) f(x)

x

g ) ( l)and f(xu) With different sign, but there are two discontinuities.

f(x) b) xIn Figure c) we have the case of f(xl) and f(xu) with the same sign, but there

xl xuc) x

( u) gis a multiple root.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 12

Bracketing Methods (Bisection method)

Bisection Method

f(x) f(x)( )

l ur

x xx2

f(xu) f(x )

f(x)

f(xl) f(xr) > 0x(x )

(x1)

f(xu)

(x1)( )( )

f(xr)

x(xu)

f(x )

f(xr) f(x1)(xu)(xr) xxr => xl

f(xl)

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 13

Bisection Method

Bracketing Methods (Bisection method)

Bisection Method Advantages:

1 Simple1. Simple2. Estimate of maximum error: l u

maxx xE

2

3. Convergence guaranteed

Di d t

i 1 imax maxE 0.5 E

Disadvantages:1. Slow2 Req ires t o good initial estimates hich define2. Requires two good initial estimates which define

an interval around root: use graph of function use graph of function, incremental search, or trial & error (common sense eng view)

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 14

trial & error (common sense, eng view)

Bracketing Methods (False-position Method)

False-position Method

f(x)

u 1 uf (x )(x x )x x

f(x)

f(xu)r u

1 ux x

f (x ) f (x )

f(x1) f(x ) > 0f(xu)

(xr)

x(xu)(x1)

f(x1) f(xr) 0

x1 = xr (x1)(xu)

f(x1)

f(xr) f(x1)f(xr)

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 15

Bracketing Methods (False-position Method)

There are some cases in which the false position method is very slow, and the bisection method gives a faster solutiona faster solution.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 16

Bracketing Methods (False-position Method)

Summary of False-Position Method:

Advantages:1 Simple1. Simple2. Brackets the Root

Disadvantages:1. Can be VERY slow2. Like Bisection, need an initial interval around the

root.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 17

R t f E ti O M th d

Open Methods

Roots of Equations - Open MethodsCharacteristics:

1. Initial estimates need not bracket the root

2 Generally converge faster2. Generally converge faster

3. NOT guaranteed to converge

Open Methods Considered:

Fixed point Methods- Fixed-point Methods (Transform f(x)=0 into x=g(x))

Newton Raphson Iteration- Newton-Raphson Iteration

- Secant Method

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 18

N t R h M th d

Open Methods (Newton-Raphson Method)

Newton-Raphson Method:

Geometrical Derivation:Slope of tangent at xi is

ii

i i 1

f (x ) 0f '(x )x x

Solve for xi+1: if (x )x x

[Note that this is the same form as the generalized one-

i 1 ii

x xf '(x )

[Note that this is the same form as the generalized one-point iteration, xi+1 = g(xi), x=x-f(x)/f’(x)]

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 19

Open Methods (Newton-Raphson Method)

N t R h d d d f T l iNewton-Raphson deduced from Taylor expansion:

f(xi+h) =0 if we are at xi. What h to get a root?f(xi h) 0 if we are at xi. What h to get a root?. Truncated Taylor expansion (linear!):

f(xi)+h·f’(xi) ≈ 0,( i) ( i) ,. Consider approx equality and solve for h:

h ≈ -f(xi)/f’(xi) (an approximation)( i) ( i) ( pp )

We write the equality f(xi)+hi·f’(xi) = 0, and solve for hi:hi = - f(xi)/f’(xi) , and then iterate:

xi+1 = xi+hi = xi - f(xi)/f’(xi) , i =0,1, 2, .

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 20

Open Methods (Newton-Raphson Method)

Newton-Raphson Method

Tangent w/slope=f '(xi )f(x)

f ( ) 0

f(x)

if (x ) 0f '(x )

f(xi)

f( )

ii

i i 1

f (x ) 0f '(x )x x

f(xi)

ii

i i 1

( )f '(x )x x

xxi

f(xi+1)

x

f(xi)

(xi)f(xi+1)

xi+

ii 1 i

i

f (x )x xf '(x )

1

xi+1

xi = xi+1

i( )

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 21

Open Methods

a) Inflection point in the neighborhood of a root.

b) Oscilation in the neighborhoodb) Oscilation in the neighborhood of a maximum or minimum.

c) Jumps in functions with ) pseveral roots.

d) Existence of a null derivative.

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 22

Open Methods (Newton-Raphson Method)

Example 1:

x 1=sin(x) (one real root; interval? make a drawing !!)x-1=sin(x) (one real root; interval? , make a drawing !!)

x1=xi i; i=1Newton-Raphson:

f(x)= x-1-sin(x)

x1 xini; i 1

tol=1e-6; nlimit=1000;

While err>tol & i<nlimit( ) ( )

f’(x)= 1 – cos (x)

Starting point x1=xini ?

While err tol & i nlimit

ii 1 i

i

f (x )x xf '(x )

Starting point x1 xini ?err=abs(xi+1-xi)

i=i+1

if (x )

Example 2 , smaller root of:

End while

Print results/messages8x - cos x – 2 x2 = 0

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 23

Open Methods (Secant Method)

Secant Method

Approx. f '(xi) with backward FDD: i 1 i

i 1 i

f (x ) f (x )f '(x)x x

i

Substitute this into the N-R equation:if (x )i

i 1 ii

( )x xf '(x )

to obtain the iterative expression: i i 1 i

i 1 if (x )(x x )x xf ( ) f ( )

i 1 if (x ) f (x )

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 24

Open Methods (Secant Method)

Secant Method

f(x)

i-1 ii

f(x ) - f(x )f '(x )

f(x)

i-1 ii

f(x ) - f(x )f '(x )

f(x )

f(xi-1)

ii-1 i

( )x - x i

i-1 ix - x

f(xi)f(xi)

f(xi-1)

i i if (x )(x x )

xxi xi-1xi+1 xxi xi-1xi+1

xi = xi+1 , xi-1 = xi

i i 1 ii 1 i

i 1 i

f (x )(x x )x xf (x ) f (x )

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 25

i i+1 i 1 i

Make a drawing (if possible!)

Ej. Smaller root of 8x - cos x – 2 x2 = 0Intersection of y = cos(x) with y = 8x-2x2

6

8

2

4

-2

0

-6

-4

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-10

-8

x

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 26

•Newton-Raphson:Example 2: Newton-Raphson

xi+1=xi – f(xi)/f’(xi) = (xi*sin(xi)+cos(xi)-2*xi^2)/(8+sin(xi)-4*xi)

» x0=(0+pi/6)/2;x1=(x0*sin(x0)+cos(x0)-2*x0^2)/(8+sin(x0)-4*x0)x1 = 1.243280246614876e-001

» x0=x1; x1=(x0*sin(x0)+cos(x0)-2*x0^2)/(8+sin(x0)-4*x0)x1 = 1.280743310786962e-001

» x0=x1; x1=(x0*sin(x0)+cos(x0)-2*x0^2)/(8+sin(x0)-4*x0)x1 = 1.280771027522815e-001

» x0=x1; x1=(x0*sin(x0)+cos(x0)-2*x0^2)/(8+sin(x0)-4*x0)x1 = 1.280771027537988e-001

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 27

BISECTION for 8x-cos(x)–2x2 = 0, From [a,b]=[0, pi/6]

Example 2: Bisection

* Iterative for x= cos(x)/8 + x2/4» a=0;x=a;f=8*x-cos(x) -2*x^2;» b=pi/6;x=b;f=8*x-cos(x) -2*x^2f = 2.774453445385877e+000» m=(a+b)/2;x=m;f=8*x-cos(x) -2*x^2f = 9.913914372001083e-001

* Iterative for x= cos(x)/8 + x2/4,xi+1 = cos(xi)/8 + xi

2 / 4

» x0=(0+pi/6)/2; x0=(0+pi/6)/2;» b=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = 2.148323009678254e-002» b=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = -4.828275125718058e-001» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f 2 290631343706263 001

» x1 = cos(x0)/8 + x0^2 / 4x1 = 1.378754581491359e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1 285661887923833e 001f = -2.290631343706263e-001

» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = -1.033874768251438e-001» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = -4.085147268920845e-002

( +b)/2 f 8* ( ) 2* ^2

x1 = 1.285661887923833e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1.281006593881692e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4

» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = -9.658954403317981e-003» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = 5.918430113168408e-003» b=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = 1 868689147045383e 003

x1 = 1.280782352879055e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1.280771571979526e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4f = -1.868689147045383e-003

» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = 2.025263741098800e-003» b=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = 7.838561046712850e-005» b=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2

» x0=x1; x1 = cos(x0)/8 + x0 2 / 4x1 = 1.280771053710740e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1.280771028796181e-001

» b=m;m=(a+b)/2;x=m;f=8 x-cos(x)-2 x 2f = -8.951271900622879e-004» a=m;m=(a+b)/2;x=m;f=8*x-cos(x)-2*x^2f = -4.083646452242989e-004» a,b,ma = 1.279595640561272e-001 b = 1.280873957884510e-001

» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1.280771027598473e-001» x0=x1; x1 = cos(x0)/8 + x0^2 / 4x1 = 1 280771027540895e-001

E. T. S. de Ingeniería de Caminos, Canales y Puertos. Santander. 28

m = 1.280234799222891e-001 x1 = 1.280771027540895e-001

top related