numeriska beräkningar i naturvetenskap och teknik 1.solving equations

20
Numeriska beräkningar i Naturvetenskap och Teknik 1. Solving equations

Upload: skyla-pegram

Post on 14-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

1. Solving equations

Page 2: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Discretization

1x

)(xf

x

2x

y

Page 3: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Error propagation

x

)(xfxE2

fE2fE2

xE2

1ax 2ax

)(' af

ee fa

Page 4: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Discretization and error propagation

fE2

1x

)(xf

x

2x

0)(, afax

|))('min(| xf

EE fa

aE2

Page 5: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

An example using graphs

0)(

)(

xf

exxf x

x

yxy

1y

xey

5.0 6.0

Page 6: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

A numerical exemple >> bisection method

0512.0)60.0(

0357.0)59.0(

0201.0)58.0(

0045.0)57.0(

0112.0)56.0(

0269.0)55.0(

0427.0)54.0(

0586.0)53.0(

0745.0)52.0(

0905.0)51.0(

1065.0)50.0(

)(

f

f

f

f

f

f

f

f

f

f

f

exxf x

Sign change

00034.0)565.0( f

Half of the interval...

again...

00.0014)56625.0( f

0004-5.5898e)5675.0( f

and again...

Page 7: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Bisection

xexxf )(

y

x

00034.0)565.0( f

00.0014)56625.0( f

0004-5.5898e)5675.0( f

00112.0)56.0( f

00045.0)57.0( f

Page 8: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Bisection method

A clear limitation of the method is that the new approximation does not take into account the value of the function for the latest x-value it was calculated at.

compare

which gives

So, we have stepped two times but are hardly any closer to the solution than we were two steps earlier…(the sign has changed though…)

How can we use the knowledge we have of the value of the function in order to guess

a new better value?

0004-5.5898e)5675.0( f

00.0014)56625.0( f

0004--4.2047e)566875.0( f

Page 9: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Secant method

0x

)(xf

x

1x

)()()(

)(

0)(

)()(

)()()(

)()()()(

101

0112

01

1011

01

01

1

1

xfxfxf

xxxx

xf

xfxf

xfxfxxxx

xx

xfxf

xx

xfxf

Sekantens ekvation

)( 0xf

)( 1xf

Iteration formula!

Root

x2, approximation

Page 10: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

The secant method

)()()(

)(

1

11 n

nn

nnnn xf

xfxf

xxxx

Code example for the secant method in the diff. equation section

Page 11: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Newton-Raphson’s method

nnn

nnn

nnn

nnnn

xxxf

xfxx

xfxfxf

xxxx

11

1

11

,)('

)(

)()()(

)(

Let the step between xn and xn-1 tend to zero...

)(xf

x

1x

)( 1xf

2x

)('

)(0)(

,)()(

)('

n

nn

n

nn

xf

xfxxxf

xx

xfxfxf

or the eq. of the tangent…

Page 12: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Iteration principle

)(1 nn xGx

),( 11 nnn xxGx

1-point method

2-point method

Page 13: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Our exemple once more:

xexxf )(

xex

xf

0)(

Solve for the root:

xexG )(i.e. is a possibility. Are there others?

yes, infinitely many!

22

22

22

xexx

xexx

ex

ex

x

x

x

x

22)( xexxG x

xx

xx

ex x

ln

ln

xxG ln)(

x

x

x

x

exx

exxx

ex

ex

64.036.0

64.036.036.064.0

64.064.0

xexxG 64.036.0)(

Page 14: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

xexxG 64.036.0)(xexG )(

nxn ex 1 nx

nn exx 64.036.01

567143.0

567144.0

...

566907.0

56756.0

566409.0

568438.0

564863.0

571172.0

560065.0

579703.0

545239.0

606531.0

5.0

22

21

10

9

8

7

6

5

4

3

2

1

0

x

x

x

x

x

x

x

x

x

x

x

x

x

x0 = 0.5

x1 = 0.56818

x2 = 0.56714

x3 = 0.567143

x4 = 0.567143

Page 15: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

The mean value theorem:

)()(1 aGxGax nn

)(')()( G

ax

aGxG

n

n

but)(xG

x

a

)(aG

nx

)( nxG

i.e.

))((')()(1 axGaGxGax nnn

or

)('1 Gax

ax

n

n

Page 16: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

The relative error between two iterations

)('1 Gax

ax

n

n

If G’(ξ) is less than 1 the iteration will converge

If xn och xn+1 are close to a then ξ is also an approximation for a,

i.e. if G’(ξ)<1 around the root a, the iteration will converge.

The convergence is quicker the smaler G’ is in the surrounding of a

How can this be used in order to optimize how we write the iteration formula?

Page 17: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Let us rewrite f(x)=0

)(

0)(

xcfxx

xf

that is

)('1)('

)()(

xcfxG

xcfxxG

Assume that the start value is a good approximation for the root:

0)('1

)('1)('

0

00

xcf

xcfxG

which leads to

)('/1 0xfc

Page 18: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Newton Raphson’s modified method:

)('/)( 01 xfxfxx nnn

Our exemples

57.0)5.0('

)('

)(

G

exG

exGx

x

003.0)5.0('

64.036.0)('

64.036.0)(

G

exG

exxGx

x

622459.0

)5.0('/1

1)5.0('

1)('

)(

5.0

c

fc

ef

exf

exxfx

x

Applying Newton Raphson’s modified method

n

n

n

xnn

xnnn

xnnn

exx

exxx

exxx

622459.0377541.0

)(622459.0

)(622459.0

1

1

1

Page 19: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

)(xG

x

0x

xy y

Page 20: Numeriska beräkningar i Naturvetenskap och Teknik 1.Solving equations

Numeriska beräkningar i Naturvetenskap och Teknik

Kodexempel, Newton Raphsons modifierade metod etc.

xexxf )(