55
AM ATHEMATICA interface for the Taylor series method A. Abad, R. Barrio, F. Blesa, M. Rodr ´ ıguez Grupo de Mec ´ anica Espacial. University of Zaragoza AMATHEMATICA interface for the Taylor series method – p. 1/21

A MATHEMATICA interface for the Taylor series method

  • Upload
    lehuong

  • View
    221

  • Download
    2

Embed Size (px)

Citation preview

Page 1: A MATHEMATICA interface for the Taylor series method

A MATHEMATICA interface for theTaylor series method

A. Abad, R. Barrio, F. Blesa, M. Rodrıguez

Grupo de Mecanica Espacial. University of Zaragoza

A M ATHEMATICA interface for the Taylor series method – p. 1/21

Page 2: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (I):• Differential equation:

x = f(t,x,p), x(0) = x0

A M ATHEMATICA interface for the Taylor series method – p. 2/21

Page 3: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (I):• Differential equation:

x = f(t,x,p), x(0) = x0

• Power series expansion solution

x(t) =∑

i

xiti

A M ATHEMATICA interface for the Taylor series method – p. 2/21

Page 4: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (I):• Differential equation:

x = f(t,x,p), x(0) = x0

• Power series expansion solution

x(t) =∑

i

xiti

• Formn-th to (n + 1)-th order

f(t,∑

i

xiti,p) =

i

fiti =

i

(i + 1)xi+1ti, xi+1 =

fi

i + 1

A M ATHEMATICA interface for the Taylor series method – p. 2/21

Page 5: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (II):• OrderN of the method:

• − log ǫ/2, ǫ =tolerance• Variable order strategy (Barrio et al.).

A M ATHEMATICA interface for the Taylor series method – p. 3/21

Page 6: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (II):• OrderN of the method:

• − log ǫ/2, ǫ =tolerance• Variable order strategy (Barrio et al.).

• Step (convergence radius * safety factor)

h = min

(

ǫ1/(n+1)

‖xn ‖1/n∞

,ǫ1/n

‖xn−1 ‖1/(n−1)∞

)

A M ATHEMATICA interface for the Taylor series method – p. 3/21

Page 7: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (II):• OrderN of the method:

• − log ǫ/2, ǫ =tolerance• Variable order strategy (Barrio et al.).

• Step (convergence radius * safety factor)

h = min

(

ǫ1/(n+1)

‖xn ‖1/n∞

,ǫ1/n

‖xn−1 ‖1/(n−1)∞

)

• Computing:x0 = x(t0), . . . xi = x(ti),xi+1 = x(ti+1), . . .

• ti+1 < ti + h: direct evaluation of power series

• ti+1 > ti + h: recomputation of power series takingti + h

as initial point.

A M ATHEMATICA interface for the Taylor series method – p. 3/21

Page 8: A MATHEMATICA interface for the Taylor series method

Sensitivity analysis• Differential equation: x = f(t,x,p), x(0) = x0

A M ATHEMATICA interface for the Taylor series method – p. 4/21

Page 9: A MATHEMATICA interface for the Taylor series method

Sensitivity analysis• Differential equation: x = f(t,x,p), x(0) = x0

• Partial derivativessk = ∂x/∂pk, with respect to a parameter (or

an initial condition) . Sensitivity equations:

sk =∂f

∂xsk +

∂f

∂pk

A M ATHEMATICA interface for the Taylor series method – p. 4/21

Page 10: A MATHEMATICA interface for the Taylor series method

Sensitivity analysis• Differential equation: x = f(t,x,p), x(0) = x0

• Partial derivativessk = ∂x/∂pk, with respect to a parameter (or

an initial condition) . Sensitivity equations:

sk =∂f

∂xsk +

∂f

∂pk

• (skj)m = ∂2xm/∂pk∂pj . Higher order sensitivity equations:

d(skj)mdt

=∂fm

∂xskj+(sj)

T ∂2fm

∂x2sk+

∂2fm

∂pj∂xsk+

∂2fm

∂pk∂xsj+

∂2fm

∂pk∂pj

A M ATHEMATICA interface for the Taylor series method – p. 4/21

Page 11: A MATHEMATICA interface for the Taylor series method

Sensitivity analysis• Differential equation: x = f(t,x,p), x(0) = x0

• Partial derivativessk = ∂x/∂pk, with respect to a parameter (or

an initial condition) . Sensitivity equations:

sk =∂f

∂xsk +

∂f

∂pk

• (skj)m = ∂2xm/∂pk∂pj . Higher order sensitivity equations:

d(skj)mdt

=∂fm

∂xskj+(sj)

T ∂2fm

∂x2sk+

∂2fm

∂pj∂xsk+

∂2fm

∂pk∂xsj+

∂2fm

∂pk∂pj

• Extended Taylor method:easier way to compute partial

derivatives up to any orderp.

A M ATHEMATICA interface for the Taylor series method – p. 4/21

Page 12: A MATHEMATICA interface for the Taylor series method

Structure of functions

f(x) =sin x2

x2 + 5

A M ATHEMATICA interface for the Taylor series method – p. 5/21

Page 13: A MATHEMATICA interface for the Taylor series method

Structure of functions

f(x) =sin x2

x2 + 5

Tree structure :

/

sin

*

x x

+

5 *

x x

A M ATHEMATICA interface for the Taylor series method – p. 5/21

Page 14: A MATHEMATICA interface for the Taylor series method

Structure of functions

f(x) =sin x2

x2 + 5

Tree structure :

/

sin

*

x x

+

5 *

x x

Chain structure(linked functions):

l1 = x

l2 = l1 l1l3 = 5 + l2l4 = sin l2l5 = l4/l3f(x) = l5

A M ATHEMATICA interface for the Taylor series method – p. 5/21

Page 15: A MATHEMATICA interface for the Taylor series method

Linked functions, useful for:• Efficient evaluation.

A M ATHEMATICA interface for the Taylor series method – p. 6/21

Page 16: A MATHEMATICA interface for the Taylor series method

Linked functions, useful for:• Efficient evaluation.

• Automatic differentiation.

l1 = x

l2 = l1 l1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

f(x) = l5

l′1 = 1

l′2 = 2 l1 l′1

l′3 = l′2

l′4 = l′2 cos l2

l′5 = (l′4l3 − l4l′3)/(l3 l3)

f ′(x) = l′5

A M ATHEMATICA interface for the Taylor series method – p. 6/21

Page 17: A MATHEMATICA interface for the Taylor series method

Linked functions, useful for:• Efficient evaluation.

• Automatic differentiation.

l1 = x

l2 = l1 l1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

f(x) = l5

l′1 = 1

l′2 = 2 l1 l′1

l′3 = l′2

l′4 = l′2 cos l2

l′5 = (l′4l3 − l4l′3)/(l3 l3)

f ′(x) = l′5

• Power series: Algebra of Series & Taylor

method.

A M ATHEMATICA interface for the Taylor series method – p. 6/21

Page 18: A MATHEMATICA interface for the Taylor series method

Linked functions, useful for:• Efficient evaluation.

• Automatic differentiation.

l1 = x

l2 = l1 l1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

f(x) = l5

l′1 = 1

l′2 = 2 l1 l′1

l′3 = l′2

l′4 = l′2 cos l2

l′5 = (l′4l3 − l4l′3)/(l3 l3)

f ′(x) = l′5

• Power series: Algebra of Series & Taylor method.• Partial derivatives: Extended Taylor method.

A M ATHEMATICA interface for the Taylor series method – p. 6/21

Page 19: A MATHEMATICA interface for the Taylor series method

Algebra of series (I)

u =n∑

i=0

uiti, v =

n∑

i=0

viti, w =

n∑

i=0

witi, α ∈ IR

Elementary functions

w = u + v → wk = uk + wk,

w = uv → wk =∑k

j=0 ujvk−j,

w = α + u → w0 = α + u0, wk = uk,

w = αu → wk = αuk,

w = 1/u → w0 = − 1u0

, wk = − 1u0

∑k−1j=0 ujvk−j,

w = dudt → wk = (k + 1)uk.

A M ATHEMATICA interface for the Taylor series method – p. 7/21

Page 20: A MATHEMATICA interface for the Taylor series method

Algebra of series (II)

w = f(u), withdf

du=

1

g(u)−→ wk =

1

go

uk − 1

k

k−1∑

j=1

jwjgk−j

• f = log u,−→ g = u.

• f = asin u,−→ g =√

1 − u2.

• f = acos u,−→ g = −√

1 − u2.

• f = atan u,−→ g = 1 + u2.

• f = asinhu,−→ g =√

1 + u2.

• f = acoshu,−→ g =√

u2 − 1.

• f = atanhu,−→ g = 1 − u2.

A M ATHEMATICA interface for the Taylor series method – p. 8/21

Page 21: A MATHEMATICA interface for the Taylor series method

Algebra of series (III)More functions:

• uα, αu, uv

• s = sin u, c = cosu

sk =1

k

k−1∑

j=0

(k − j)cjuk−j , ck = −1

k

k−1∑

j=0

(k − j)sjuk−j .

• s = sinh u, c = cosh u

sk =1

k

k−1∑

j=0

(k − j)cjuk−j , ck =1

k

k−1∑

j=0

(k − j)sjuk−j .

• tanu =sin u

cos u, tanh u =

sinh u

coshu

A M ATHEMATICA interface for the Taylor series method – p. 9/21

Page 22: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (TSM)l1 = x

l2 = l1 f1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

A M ATHEMATICA interface for the Taylor series method – p. 10/21

Page 23: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (TSM)l1 = x

l2 = l1 f1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

l1 = x

l2 = l1 l1

l3 = 5 + l2

l4 = sin l2

l5 = cos l2

l6 = l4/l3

A M ATHEMATICA interface for the Taylor series method – p. 10/21

Page 24: A MATHEMATICA interface for the Taylor series method

Taylor Series Method (TSM)l1 = x

l2 = l1 f1

l3 = 5 + l2

l4 = sin l2

l5 = l4/l3

l1 = x =

n∑

i=0

xiti

l2 = l1 l1

l3 = 5 + l2

l4 = sin l2

l5 = cos l2

l6 = l4/l3 =

n∑

i=0

fiti

xn+1 = fn/(n + 1)

Algebra series + extended linked functions:Taylor series method

x0, . . . , xn → f(t,

n∑

i=0

xiti, p) =

n∑

i=0

fiti → xn+1 =

fn

n + 1

A M ATHEMATICA interface for the Taylor series method – p. 10/21

Page 25: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(I)• f(x),x = (x1, . . . , xn) ∈ Rn

fi=

∂(i1+...+in)f

∂xi11 . . . ∂xin

n

, i = (i1, . . . , in) ∈ Nn0

A M ATHEMATICA interface for the Taylor series method – p. 11/21

Page 26: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(I)• f(x),x = (x1, . . . , xn) ∈ Rn

fi=

∂(i1+...+in)f

∂xi11 . . . ∂xin

n

, i = (i1, . . . , in) ∈ Nn0

• then-tuplei identifies each partial derivative.

A M ATHEMATICA interface for the Taylor series method – p. 11/21

Page 27: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(I)• f(x),x = (x1, . . . , xn) ∈ Rn

fi=

∂(i1+...+in)f

∂xi11 . . . ∂xin

n

, i = (i1, . . . , in) ∈ Nn0

• then-tuplei identifies each partial derivative.• i − j = (i1 − j1, . . . , in − jn).

A M ATHEMATICA interface for the Taylor series method – p. 11/21

Page 28: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(I)• f(x),x = (x1, . . . , xn) ∈ Rn

fi=

∂(i1+...+in)f

∂xi11 . . . ∂xin

n

, i = (i1, . . . , in) ∈ Nn0

• then-tuplei identifies each partial derivative.• i − j = (i1 − j1, . . . , in − jn).• i∗ = (0, . . . , 0, ik − 1, . . . , in) whereik is the first

nonzero element.

A M ATHEMATICA interface for the Taylor series method – p. 11/21

Page 29: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(I)• f(x),x = (x1, . . . , xn) ∈ Rn

fi=

∂(i1+...+in)f

∂xi11 . . . ∂xin

n

, i = (i1, . . . , in) ∈ Nn0

• then-tuplei identifies each partial derivative.• i − j = (i1 − j1, . . . , in − jn).• i∗ = (0, . . . , 0, ik − 1, . . . , in) whereik is the first

nonzero element.• Dm

n = {i | i1 + . . . + in ≤ m} is the set of allpartial derivatives until orderm

A M ATHEMATICA interface for the Taylor series method – p. 11/21

Page 30: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(II)• Total order inDm

n : i ≤ j

A M ATHEMATICA interface for the Taylor series method – p. 12/21

Page 31: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(II)• Total order inDm

n : i ≤ j

• V(i) = {v |v ≤ i}, is the set of all partialderivativesv that we need to compute thederivativei.

A M ATHEMATICA interface for the Taylor series method – p. 12/21

Page 32: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(II)• Total order inDm

n : i ≤ j

• V(i) = {v |v ≤ i}, is the set of all partialderivativesv that we need to compute thederivativei.

• V(D) =⋃

i∈D V(i) ⊂ Dmn , is the set of all partial

derivativesv that we need to compute thederivative of the setD.

A M ATHEMATICA interface for the Taylor series method – p. 12/21

Page 33: A MATHEMATICA interface for the Taylor series method

Partial derivatives: Notation(II)• Total order inDm

n : i ≤ j

• V(i) = {v |v ≤ i}, is the set of all partialderivativesv that we need to compute thederivativei.

• V(D) =⋃

i∈D V(i) ⊂ Dmn , is the set of all partial

derivativesv that we need to compute thederivative of the setD.

• O(V(D)) is the result of ordering the setV(D)

A M ATHEMATICA interface for the Taylor series method – p. 12/21

Page 34: A MATHEMATICA interface for the Taylor series method

Partial derivatives:Notation(III)

f [j](t) =1

j!f (j)(t), f [j]

i=

∂(i1+...+in)f [j]

∂xi11 . . . ∂xin

n

,

(

i

v

)

=

(

i1v1

)

. . .

(

invn

)

A M ATHEMATICA interface for the Taylor series method – p. 13/21

Page 35: A MATHEMATICA interface for the Taylor series method

Partial derivatives:Notation(III)

f [j](t) =1

j!f (j)(t), f [j]

i=

∂(i1+...+in)f [j]

∂xi11 . . . ∂xin

n

,

(

i

v

)

=

(

i1v1

)

. . .

(

invn

)

• h(t) = exp(f(t))

h[0]0

= exp(f [0](t))

h[0]i

=∑

v∈V(i∗)

(

i∗

v

)

h[0]v

f [0]i−v

h[n]i

= 1n

n−1∑

j=0

(n − j)

v∈V(i)

(

i

v

)

h[j]v

f [n−j]i−v

A M ATHEMATICA interface for the Taylor series method – p. 13/21

Page 36: A MATHEMATICA interface for the Taylor series method

Generating partial derivatives

v,w∈V(i)

Ci,vf [−]v

g[−]w

,∑

v,w∈V(i∗)

Ci∗,vf [−]v

g[−]w

, w = i−v, Ci,v =

(

i

v

)

,

• Compute theN elements ofV(D).

A M ATHEMATICA interface for the Taylor series method – p. 14/21

Page 37: A MATHEMATICA interface for the Taylor series method

Generating partial derivatives

v,w∈V(i)

Ci,vf [−]v

g[−]w

,∑

v,w∈V(i∗)

Ci∗,vf [−]v

g[−]w

, w = i−v, Ci,v =

(

i

v

)

,

• Compute theN elements ofV(D).

• SortV(D) −→ O(V(D)) −→ 0 ≤ i < N .

A M ATHEMATICA interface for the Taylor series method – p. 14/21

Page 38: A MATHEMATICA interface for the Taylor series method

Generating partial derivatives

v,w∈V(i)

Ci,vf [−]v

g[−]w

,∑

v,w∈V(i∗)

Ci∗,vf [−]v

g[−]w

, w = i−v, Ci,v =

(

i

v

)

,

• Compute theN elements ofV(D).

• SortV(D) −→ O(V(D)) −→ 0 ≤ i < N .

• i ∈ O(V(D)) −→ V(i),V(i∗) −→ Ci,v, Ci∗,v

A M ATHEMATICA interface for the Taylor series method – p. 14/21

Page 39: A MATHEMATICA interface for the Taylor series method

Generating partial derivatives

v,w∈V(i)

Ci,vf [−]v

g[−]w

,∑

v,w∈V(i∗)

Ci∗,vf [−]v

g[−]w

, w = i−v, Ci,v =

(

i

v

)

,

• Compute theN elements ofV(D).

• SortV(D) −→ O(V(D)) −→ 0 ≤ i < N .

• i ∈ O(V(D)) −→ V(i),V(i∗) −→ Ci,v, Ci∗,v

• Two lists of integer numbers that represent the indexes

v,w ∈ V(i) .

A M ATHEMATICA interface for the Taylor series method – p. 14/21

Page 40: A MATHEMATICA interface for the Taylor series method

Generating partial derivatives

v,w∈V(i)

Ci,vf [−]v

g[−]w

,∑

v,w∈V(i∗)

Ci∗,vf [−]v

g[−]w

, w = i−v, Ci,v =

(

i

v

)

,

• Compute theN elements ofV(D).

• SortV(D) −→ O(V(D)) −→ 0 ≤ i < N .

• i ∈ O(V(D)) −→ V(i),V(i∗) −→ Ci,v, Ci∗,v

• Two lists of integer numbers that represent the indexes

v,w ∈ V(i) .

• Two lists of integer numbers that represent the indexes

v,w ∈ V(i∗) .

A M ATHEMATICA interface for the Taylor series method – p. 14/21

Page 41: A MATHEMATICA interface for the Taylor series method

Storage data structures• Example: ∂3f

∂x1∂x2

2

A M ATHEMATICA interface for the Taylor series method – p. 15/21

Page 42: A MATHEMATICA interface for the Taylor series method

Storage data structures• Example: ∂3f

∂x1∂x2

2

• O(V(D)) = {(0, 0), (1, 0), (0, 1), (1, 1), (0, 2), (1, 2)}= {0, 1, 2, 3, 4, 5}

A M ATHEMATICA interface for the Taylor series method – p. 15/21

Page 43: A MATHEMATICA interface for the Taylor series method

Storage data structures• Example: ∂3f

∂x1∂x2

2

• O(V(D)) = {(0, 0), (1, 0), (0, 1), (1, 1), (0, 2), (1, 2)}= {0, 1, 2, 3, 4, 5}

• V(4) = V((0, 2)) = {(0, 0), (0, 1), (0, 2)} = {0, 2, 4}

A M ATHEMATICA interface for the Taylor series method – p. 15/21

Page 44: A MATHEMATICA interface for the Taylor series method

Storage data structures• Example: ∂3f

∂x1∂x2

2

• O(V(D)) = {(0, 0), (1, 0), (0, 1), (1, 1), (0, 2), (1, 2)}= {0, 1, 2, 3, 4, 5}

• V(4) = V((0, 2)) = {(0, 0), (0, 1), (0, 2)} = {0, 2, 4}• Data arrays:

PREV_ACUM 0 1 3 5 9 12 18

PREV_COEF 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 2 1

PREV_VI 0 0 1 0 2 0 2 1 3 0 2 4 0 2 4 1 3 5

PREV_IV 0 1 0 2 0 3 1 2 0 4 2 0 5 3 1 4 2 0

A M ATHEMATICA interface for the Taylor series method – p. 15/21

Page 45: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 46: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

• Numerical software extremely easy to use via a MATHEMATICA

preprocessor.

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 47: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

• Numerical software extremely easy to use via a MATHEMATICA

preprocessor.

• Taylor series method using Variable-Stepsize Variable-Order

formulation and extended formulas for the variational equations.

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 48: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

• Numerical software extremely easy to use via a MATHEMATICA

preprocessor.

• Taylor series method using Variable-Stepsize Variable-Order

formulation and extended formulas for the variational equations.

• Automatic construction of Fortran codes for solving solutions of

ODEs.

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 49: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

• Numerical software extremely easy to use via a MATHEMATICA

preprocessor.

• Taylor series method using Variable-Stepsize Variable-Order

formulation and extended formulas for the variational equations.

• Automatic construction of Fortran codes for solving solutions of

ODEs.

• Automatic construction of C codes for solving solutions of ODEs

and variational equationsup to any order (and sensitivities with

respect to any parameter up to any order) .

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 50: A MATHEMATICA interface for the Taylor series method

TIDES (I)• TIDES :a Taylor series Integrator for Differential EquationS.

• Numerical software extremely easy to use via a MATHEMATICA

preprocessor.

• Taylor series method using Variable-Stepsize Variable-Order

formulation and extended formulas for the variational equations.

• Automatic construction of Fortran codes for solving solutions of

ODEs.

• Automatic construction of C codes for solving solutions of ODEs

and variational equationsup to any order (and sensitivities with

respect to any parameter up to any order) .

• Easy to usearbitrary precision solver(do you need 500 digits?,

1000?)

A M ATHEMATICA interface for the Taylor series method – p. 16/21

Page 51: A MATHEMATICA interface for the Taylor series method

TIDES (II)MathTIDES preprocessor MATHEMATICA

libTIDES.a library C

(objects or source code)

minf-tides basic TSM FORTRAN files

minc-tides basic TSM C files

dp-tides extended TSM C files

basic + partial derivatives + libTIDES.a

mp-tides extended TSM C files

extended + arbitrary precision+ libTIDES.a

+ libmpfr.a

A M ATHEMATICA interface for the Taylor series method – p. 17/21

Page 52: A MATHEMATICA interface for the Taylor series method

Double precision tests

A M ATHEMATICA interface for the Taylor series method – p. 18/21

Page 53: A MATHEMATICA interface for the Taylor series method

Multiple precision test

A M ATHEMATICA interface for the Taylor series method – p. 19/21

Page 54: A MATHEMATICA interface for the Taylor series method

TIDES session

A M ATHEMATICA interface for the Taylor series method – p. 20/21

Page 55: A MATHEMATICA interface for the Taylor series method

Join TIDES community• Free software• Where?:http://gme.unizar.es/software/tides• or email: [email protected]

A M ATHEMATICA interface for the Taylor series method – p. 21/21