Modeling and simulation of systems

13
Modeling and simulation of systems Numerical methods for solving of differential equations Slovak University of Technology Faculty of Material Science and Technology in Trnava

description

Slovak University of Technology Faculty of Material Science and Technology in Trnava. Modeling and simulation of systems. Numerical methods for solving of differential equations. Euler´s method. we solve simple differential equation of first order y ’ = f(x,y),y(x 0 ) = y 0 - PowerPoint PPT Presentation

Transcript of Modeling and simulation of systems

Page 1: Modeling and simulation of systems

Modeling and simulation of systems

Numerical methods for solving of differential equations

Slovak University of TechnologyFaculty of Material Science and Technology in Trnava

Page 2: Modeling and simulation of systems

Euler´s method

we solve simple differential equation of first order y’ = f(x,y), y(x0) = y0

when we know the value yn= y(xn) solutions at the point xn

and f(xn,yn) = y’(xn) is the directive of tangent to graph of solution at the point (xn,yn)

we can substitute the graph of solution by the line segment with directive f(xn,yn) it means yn+1= y(xn+1) = yn + h f(xn,yn) for small? h on the interval xn,xn +h

Page 3: Modeling and simulation of systems

Euler´s method

y = ex

0 1 2 3 4

Lack of Euler´s method – little precision.

Page 4: Modeling and simulation of systems

Method of Runge-Kutta

The enlargement of the precision of Euler´s method in the method of Runge-Kutta lies in searching of increasing of at several points on the interval xn,xn+1

A = (xn,yn) slope at A k1 = h f(xn,yn)

B = (xn+ h/2, yn+ k1/2) slope at B k2 = h f (xn+ h/2, yn+ k1/2)

C = (xn+ h/2, yn+ k2/2) slope at C k3 = h f (xn+ h/2, yn+ k2/2)

D = (xn+ h, yn+ k3) slope at D k4 = h f (xn+ h, yn+ k3)

Page 5: Modeling and simulation of systems

k1

k2

k3

k4

xn xn+ h/2 xn+1 xn+1+ h/2 xn+2

A

B

CD

Method of Runge-Kutta

Page 6: Modeling and simulation of systems

Method of Runge-Kutta

Method of Runge-Kutta makes the increase – the value yn+1 as a linear combination k1,k2, k3,k4

Slope of function n = yn+1 - yn

n = 1/6 (k1+2k2+2 k3+k4) Accumulated error is not bigger than

constant multiple h5

Page 7: Modeling and simulation of systems

Predictor-corrector method

For the precise/exact value is in force:

1

),(11

n

in

x

x

ii dxyxfyy

It is also necessary to know values of solution in several previous point, this follows from the formula.

Let´s substitute integral for closed trapezoid formula:

)(2

),(),(2

'1

'

111

1

nnn

nnnnnn

nn

yyh

y

yxfyxfxx

yy

1

Page 8: Modeling and simulation of systems

Predictor-corrector method

Let´s subsitute integral for opened trapezoid formula:

)(23

),(),(2

''12

1121

21

nnn

nnnnnn

nn

yyhy

yxfyxfxx

yy

2

The first formula is more precise but is in implicit state. First of all we calculate the predictive value yn+1,0 by help of the second formula. Then we set y’

n+1,0 and finally we calculate reconstructive value yn+1,1 according to relation 1. This method repeats until the difference of two calculated values is smaller than determined accuracy.

Page 9: Modeling and simulation of systems

Prediction of valueyn+1,0

Calculationy‘

n+1,0= f(xn+1, yn+1,0)

0j

Calculation y‘

n+1,j+1= f(xn+1, yn+1,j)

Calculation of corrected valueyn+1,j+1

y‘n+1,j+1- y‘

n+1,j

yn+1= yn+1,j+1

y‘n+1 = y‘

n+1,j+1

j+1 j

A

N

Predictor-corrector method

Page 10: Modeling and simulation of systems

Comparison of methods of numerical integration

The method R-K does not call for additional primary values. There is the possibility to change the step of integration randomly.

The methods P-C call for others primary values. It is generally needed to calculate the primary conditions for the new step at the change of the step of integration.

The accuracy of both methods is approximately the same, often R-K are more precise than P-C of the same rule

R-K needs at each step so much calculation of value f(x,y) as the rule of method. The methods P-C of the fourth rule usually demand two calculation – prediction and correction. That is why we can say that they are about faster twice as R-K of the same order.

Page 11: Modeling and simulation of systems

The usage of methods of numerical integration

How big is the local defect (error of method, rounding error...)

How influence has the local error upon the results in the next step. Then it is necessary to notify the stability of the method.

The necessity to know the primary conditions The speed of method

Page 12: Modeling and simulation of systems

Example

Calculate the value(1.5) of solution of differential equationy’=yx, if y(1)=2 and select step 0,1.

y0=y(1) a y1=y(1.1)

k1= h f(x0,y0)= 0.1*21=0.2

2179.0)22.0

2(*1.0

)2

,2

(

2

1.01

1002

ky

hxfhk

Page 13: Modeling and simulation of systems

Example

2189.0)2

2179.02(*1.0

)2

,2

(

2

1.01

2003

ky

hxfhk

k4=h*f(x0+h,y0+k3)=0.1*(2+0.2189)1+0.1=0.2403

y1=y0+1/6*(k1+2k2+2k3+k4)=...=2.219