Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß...

48
Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis Equilibria Stable path (In)active constraints BVP Implementation Initialization Dynamic files Dynamics BC files Two-state model Numeric analysis Equilibria Stable path Multiple constraints Slice manifold Boundary curves BVP Implementation Initialization Plotting References OCMat functions Lecture 3 : Higher dimensional models and constraints Increasing the complexity! OCMat: A MATLAB package for the analysis of optimal control problems Dieter Graß: [email protected] Operations Research and Control Systems (ORCOS)

Transcript of Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß...

Page 1: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Lecture 3:

Higher dimensional models and

constraintsIncreasing the complexity!

OCMat: A MATLAB package for the analysis ofoptimal control problems

Dieter Graß: [email protected] Research and Control Systems (ORCOS)

Page 2: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Optimal control problems with constraints

General model formulation

maxu(·)

∫ ∞

0

e−rtg(x(t), u(t)) dt

s.t. x(t) = f (x(t), u(t)), t ∈ [0, ∞)

with x(0) = x0

c(x(t), u(t)) ≥ 0, t ∈ [0, ∞),

with x(t) ∈ Rn, u(t) ∈ R

m and f : Rn+m → Rn, g : Rn+m → R, and the

mixed path constraints c : Rn+m → Rl .

Necessary optimality conditions

H(x , u, λ) = g(x , u) + λf (x , u), L(x , u, λ, µ) = H(x , u, λ) + µc(x , u)

u∗(t) = max

uH(x∗(t), u, λ(t)) ⇒

{

Lu(x∗(t), u∗(t), λ(t), µ(t)) = 0

µ(t) ≥ 0, µ(t)c(x(t), u(t)) = 0

λ(t) = rλ(t)−Hx(x∗(t), u∗(t), λ(t))− µ(t)cu(x

∗(t), u∗(t))

Page 3: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Region of Constraints

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

K1

K2

State space

Page 4: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

A simplified coral reef model

Model formulation (coral reef model)

maxh(·)

0

e−rt(

ph(t)F (t)− h(t)2)

dt

s.t. F (t) = F (t)

(

1−F (t)

A

)

−1

τ + C

F (t)2

1 + F (t)2− h(t)F (t)

with F (0) = F0 ≥ 0

h(t) ≥ 0, for all t

• fish (F (·))

• algae (A)

• coral (C )

• fishing effort (h(·))

Page 5: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

A simplified coral reef model

Initialization file (coralreef1D.m)

% An Opt ima l l y Managed Co ra l Ree fs t a t ed ynam i c s=sym( ’ s igma∗x1∗(1−x1/A)−1/( tau+C)∗x1ˆ2/(1+x1 ˆ2)−

u1∗x1 ’ ) ;o b j e c t i v e f u n c t i o n=sym( ’ p∗u1∗x1−u1ˆ2 ’ ) ;c o n t r o l c o n s t r a i n t=sym( ’ u1−ulow ’ ) ;% Gene ra ld=1;A=10;p=1;r =0.1 ;tau =0.25 ;C=0;sigma=1;ulow=0

Page 6: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Necessary optimality conditions

Hamiltonian/Lagrangian

H(F , h, λ) = phF − h2 + λ

(

F

(

1−F

A

)

−1

τ + C

F 2

1 + F 2− hF

)

L(F , h, λ, µ) = H(F , h, λ) + µh

Hamiltonian maximizing condition

h◦(t) = max

h≥0H(F (t), h, λ(t)) ⇔

∂L

∂h(F (t), h◦(t), λ(t), µ(t)) = 0

µ(t) ≥ 0, for all t

h◦(t)µ(t) = 0, for all t

Canonical system

F (t) = F (t)

(

1−F (t)

A

)

−1

τ + C

F (t)2

1 + F (t)2− h

◦(t)F (t)

λ(t) = rλ(t)−∂L

∂F(F (t), h◦(t), λ(t), µ(t))

Page 7: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

First case: h(t) > 0

Optimal control value

∂H

∂h(F (t), h∗(t), λ(t)) = 0 ⇔ h◦(t) = F (t)

p − λ(t)

2

Canonical system

F (t) = F (t)

(

1−F (t)

A

)

−1

(C + τ )

F (t)2

1 + F (t)2− h◦(t)F (t)

λ(t) = λ(t)

(

r − 1 +2F (t)

A+

2F (t)

(C + τ )(1 + F (t)2)2

)

− h◦(t)

Lagrangian multiplier

µ(t) = 0

Page 8: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Second case: h(t) = 0

Optimal control value

h◦(t) = 0

Canonical system

F (t) = F (t)

(

1−F (t)

A

)

−1

(C + τ )

F (t)2

1 + F (t)2

λ(t) = λ(t)

(

r − 1 +2F (t)

A+

2F (t)

(C + τ )(1 + F (t)2)2

)

Lagrangian multiplier

µ(t) = −F (t)(p − λ(t))

Page 9: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Concept of arc identifiers

Remark

To distinguish between the different cases in OCMat ofactive/inactive constraints each case is assigned a number, calledthe arc identifier (arcid ).

Optimal control value

f u n c t i o n out=co r a l r e e f 1DOp t ima lCon t r o l ( t , dynVar , pararg , a r c a r g )%% r e t u r n s the op t ima l c o n t r o l v a l u e o f model c o r a l r e e f 1D

% Parameter Valuer=pa ra r g (1 ) ;A=pa ra r g (2 ) ;C=pa ra r g (3 ) ;gamma=para r g (4 ) ;e ta=pa ra r g (5 ) ;p=pa ra r g (6 ) ;ph i=pa ra r g (7 ) ;s igma=pa ra r g (8 ) ;tau=pa ra r g (9 ) ;t h e t a=pa ra r g (10) ;ulow=pa ra r g (11) ;T=pa ra r g (12) ;% Optimal Con t r o l Valuesw i t ch a r c a r g

case {1}out =[1./2 .∗ dynVar ( 1 , : ) .∗(p−dynVar ( 2 , : ) .∗ e ta ) . / ph i ] ;

case {2}out=[ repmat ( ulow , 1 , s i z e ( dynVar , 2 ) ) ] ;

end

Page 10: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Numeric analysis: Equilibria

>> m=ocmodel ( ’ c o r a l r e e f 1D ’ ) ;m=changeparameter (m, ’A,C ’ , [ 7 1 0 ] ) ;>> ocEP=ca l c e p (m) ; b=i s a dm i s s i b l e (m, ocEP) ; ocEP(˜ b ) = [ ] ;>> b=i s n e g a t i v e s t a t e (m, ocEP ) ; ocEP(b==1)= [ ] ; ocEP=un iqueoc ( ocEP , opt ) ; ocEP{:}

Search f o r z e r o sans =

d yn p r im i t i v e o b j e c t :Coo rd i n a t e s :

00

Arc i d e n t i f i e r : 1L i n e a r i z a t i o n : [ 2 x2 doub l e ]

ans =d yn p r im i t i v e o b j e c t :

Coo rd i n a t e s :3 .65860.75261

Arc i d e n t i f i e r : 1L i n e a r i z a t i o n : [ 2 x2 doub l e ]

ans =d yn p r im i t i v e o b j e c t :

Coo rd i n a t e s :00

Arc i d e n t i f i e r : 2L i n e a r i z a t i o n : [ 2 x2 doub l e ]

>> i s s a d d l e ( ocEP{:})ans =

1 1 1>> m=s t o r e (m, ocEP ( 1 : 2 ) )

Page 11: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Numeric analysis: Stable path ( arcid=1)

>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , 1 , 0 , ocEP{2}, ’ I n t e g r a t i o nT ime ’ , 500) ;>> opt=s e t o c o p t i o n s ( ’OCCONT ’ , ’ I n i t S t epWid th ’ , 0 . 01/5ˆ3 , ’ MaxStepWidth ’ , 0 . 0 1 ) ;>> [ s o l s o l n ]= occon t (m, i n i t S t r u c t , opt ) ; s o l n

Con t i n ua t i on s t ep No . : 0s t epw id th : 8e−005Mesh s i z e : 10I t e r a t i o n number : 12Residuum norm : 0R e l a t i v e d i s t a n c e : 1

.

.Con t i n ua t i on s t ep No . : 57s t epw id th : 0 . 01Mesh s i z e : 28I t e r a t i o n number : 9Residuum norm : 2.90075 e−017

Warning : Ca l c u l a t e d t r a j e c t o r y i s not a dm i s s i b l e .> I n optdyn . occon t at 246Mesh s i z e : 28I t e r a t i o n number : 9Residuum norm : 2.69873 e−017R e l a t i v e d i s t a n c e : 0 .52056

.

.s o l n =

oca s ymp to t i c o b j e c t :l i m i t s e t : [ d y n p r im i t i v e o b j e c t ]dynVar : [ 2 x28 doub l e ]t : [ 1 x28 doub l e ]a r c i d : 1t r a n s f o rm i d : 0t i m e i n t e r v a l s : 500s o l v e r i n f o s : [ 1 x1 s t r u c t ]v i o l a t i o n : [ 2 x28 doub l e ]

>> s o l n . v i o l a t i o nans =

1 0 0 0 0 0 0 0 0 0 0 . . . 00 0 0 0 0 0 0 0 0 0 0 . . . 0

Page 12: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Numeric analysis: Stable path ( arcid=[2 1])

>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , 1 , 0 , so ln , ’ I n t e g r a t i o nT ime ’ , 500) ;>> [ s o l 1 s o l 1 n ]= occon t (m, i n i t S t r u c t , opt )

Con t i n ua t i on s t ep No . : 0s t epw id th : 0 . 002Mesh s i z e : 28I t e r a t i o n number : 15Residuum norm : 2.1833 e−012R e l a t i v e d i s t a n c e : 1..Con t i n ua t i on s t ep No . : 129s t epw id th : 1 . 024 e−008

ans =E r r o r u s i n g ==> bvp4c at 203Unable to s o l v e the c o l l o c a t i o n eq u a t i o n s −− a s i n g u l a r Jacob ian encoun te redWarning : Con t i n ua t i on p r o c e s s i n t e r r u p t e d s i n c e minimum s t epw id th i s r eached .> I n optdyn . occon t at 389s o l 1 =

oca s ymp to t i c o b j e c t :l i m i t s e t : [ d y n p r im i t i v e o b j e c t ]dynVar : [ 4 x36 doub l e ]t : [ 1 x36 doub l e ]a r c i d : [ 1 x2 doub l e ]t r a n s f o rm i d : 0t i m e i n t e r v a l s : [ 1 x2 doub l e ]s o l v e r i n f o s : [ 1 x1 s t r u c t ]v i o l a t i o n : emptys o l 1 n =

[ ]>> s o l 1 . a r c i dans =

2 1

Page 13: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Animation: Constraint becoming active

Page 14: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

The BVP allowing for different arcs

Multi-point formulation

x(t) = f (x(t)), t ∈ [0, τ ]

y(t) = g(y(t)), t ∈ [τ,∞)

x1(0) = x1,0 (2a)

limt→∞

y(t) = y (2b)

x(τ ) = y(τ ) (2c)

s(x(τ ), y(τ )) = 0 (2d)

• (2a): Initial condition.

• (2b): Stable path property.

• (2c): Continuity oft the solution path.

• (2d): Scalar condition to determine switching time τ .

Page 15: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

The BVP allowing for different arcs

Two-point formulation

x(t) = τ f (x(t)), t ∈ [0, 1]

y(s) = (T − τ )g(y(s)), s ∈ [0, 1]

x1(0) = x1,0 (3a)

Π(y − y(1)) = 0 (3b)

x(1) = y(0) (3c)

s(x(1), y(0)) = 0 (3d)

• Normalize to unit interval.

• (3a): Initial condition.

• (3b): Asymptotic transversality condition.

• (3c): Continuity oft the solution path.

• (3d): Scalar condition to determine switching time τ .

Page 16: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

The scalar condition for the switching time

Using the notation of the coral reef model

x =

(

F (2)

λ(2)

)

y =

(

F (1)

λ(1)

)

we find

Continuity of the Hamiltonian

H(F (1)(0), h◦(0), λ(1)(0))−H(F (2)(1), 0, λ(2)(1)) = 0 (4)

For a continuous control h∗(·) (4) can be replaced by

Switching from active to inactive constraint

h◦(0) = F (1)(0)p − λ(1)(0)

2= 0

Switching from inactive to active constraint

µ(1) = −F (2)(1)(p − λ(2)(1)) = 0

Page 17: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Implementation

Initialization

>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , 1 , 0 , s o l n )

i n i t S t r u c t =ArcCoo rd i n a t e s : {[2 x1 doub l e ] [ 2 x1 doub l e ]}

ArcDimens ion : 2A r c I d e n t i f i e r : [ 2 1 ]

Asymptot icBCMatr ix : [ 0 . 0729 0 . 9973 ]Cont inuat ionArgument : ’ e x t r ema l ’

Con t inuat i onType : ’ f ’Con t i n u a t i o nVa r i a b l e : ’ i n i t p o i n t ’

Con t i n ua t i onVec t o r : −1.8831Funct i on : [ 1 x1 s t r u c t ]

I d e n t i f i e r : ’ i 2 e p s ’I n i tBVSo l u t i o n : [ 1 x1 s t r u c t ]

I n i t i a l V a l u e : 1 .8831I n t e g r a t i o nT ime : 500

Mode lParameterValue : [ 0 . 1000 7 10 1 1 0.2500 0 I n f ]ODEFunction : [ 1 x1 s t r u c t ]

PathType : ’ s ’Sadd l ePo i n t : [ 2 x1 doub l e ]

Sw i t chCoo rd i n a t e : 1S w i t c h I d e n t i f i e r : ’ 1 ’Ta rge tCoo rd i n a t e : 1

Targe tVa lue : 0>> i n i t S t r u c t . I n i tBVSo l u t i o nans =

i d e n t i f i e r : ’ i 2 e p s ’pa ramete r s : 0

y : [ 4 x28 doub l e ]x : [ 1 x28 doub l e ]

Page 18: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Implementation: Constructing initial solution

First non-admissible solution

>> s o l n . v i o l a t i o nans =

1 0 0 0 0 0 . . . 00 0 0 0 0 0 . . . 0

>> s o l n . dynVarans =

1.8831 2.7867 3.3164 3.5383 3.6181 3.6451 . . . 3 .65861.0000 0.8359 0.7802 0.7617 0.7556 0.7536 . . . 0 .7526

>> s o l n . tans =

0 0.0015 0.0031 0.0046 0.0062 0.0077 . . . 1 .0000>> c o n t r o l (m, s o l n )ans =

−0.0000 0.2287 0.3645 0.4216 0.4421 0.44915 . . . 0 .4525

Two-arc solution

>> i n i t S t r u c t . I n i tO cT r a j e c t o r y . dynVarans =

1.8831 1.8831 1.8831 1.8831 1.8831 1.8831 . . . 1 .88311.0000 1.0000 1.0000 1.0000 1.0000 1.0000 . . . 1 .00001.8831 2.7867 3.3164 3.5383 3.6181 3.6451 . . . 3 .65861.0000 0.8359 0.7802 0.7617 0.7556 0.7536 . . . 0 .7526

>> i n i t S t r u c t . I n i tO cT r a j e c t o r y . tans =

0 0.0015 0.0031 0.0046 0.0062 0.0077 . . . 1 .0000>> c o n t r o l (m, i n i t S t r u c t . I n i tO cT r a j e c t o r y )ans =

0 0 0 0 0 0 . . . 0−0.0000 0.2287 0.3645 0.4216 0.4421 0.4491 . . . 0 .4525

Page 19: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Implementation: Files describing dynamics

General dynamics

f u n c t i o n out = dyn4 i 2 ep s ( t , dynVar , v a r a r g i n )%% DYN4I2EPS dynamics f o r BVP%i n t e r n a l p a r a r g = [ ] ;i f n a r g i n==3

i n t e r n a l p a r a r g=v a r a r g i n {1};end% g l o b a l v a r i a b l eg l o b a l OcBVPVarout=f e v a l (OcBVPVar . ODEFunction . Dynamics , t , dynVar , OcBVPVar . ModelParameterValue ,#,#,#,

OcBVPVar . I n t eg r a t i onT ime ,#) ;

Model specific dynamics

f u n c t i o n out = co ra l r e e f 1Ds4Con t ( t , dynVar , pararg , a r ca rg , sw i t c h i d , sw i t chcoord , t r un c t ,i n t e r n a l p a r a r g )

%% the dynamics f i l e f o r model c o r a l r e e f 1D s f o r the BVP% Dynamical sys temsw i t ch l e n g t h ( sw i t c h i d )

case 0out ( 1 : 2 , : )=t r u n c t∗c o r a l r e e f 1D sCan on i c a l S y s t em( t , dynVar ( 1 : 2 , : ) , pararg , a r c a r g (1 ) ) ;

case 1out ( 1 : 2 , : )=i n t e r n a l p a r a r g (1 )∗c o r a l r e e f 1D sCan on i c a l S y s t em( t , dynVar ( 1 : 2 , : ) , pararg ,

a r c a r g (1 ) ) ;out ( 3 : 4 , : ) =( t r un c t−i n t e r n a l p a r a r g (1 ) )∗c o r a l r e e f 1D sCan on i c a l S y s t em( t , dynVar ( 3 : 4 , : )

, pararg , a r c a r g (2 ) ) ;%ADDCASE

o t h e rw i s ee r r o r ( [ num2str ( l e n g t h ( sw i t c h i d ) ) ’ %s not d e f i n e d ’ ] , s w i t c h i d )

end

Page 20: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Implementation: Files describing boundary conditions

General boundary condition file

f u n c t i o n out = bc4 i2ep ( dynVara , dynVarb , v a r a r g i n )%% BC4I2EP boundary c o n d i t i o n s f o r s o l u t i o n conv e r g i n g to an e q u i l i b r i um%i n t e r n a l p a r a r g = [ ] ;i f n a r g i n==3

i n t e r n a l p a r a r g=v a r a r g i n {1};end% g l o b a l v a r i a b l eg l o b a l OcBVPVarout=[ f e v a l (OcBVPVar . BVPFunction . Cont inuat i on ,# , . . . ) ; . . .

f e v a l (OcBVPVar . BVPFunction . WeierstrassErdmannCond , dynVara , dynVarb , OcBVPVar .ModelParameterValue , OcBVPVar . A r c I d e n t i f i e r , OcBVPVar . Sw i t c h I d e n t i f i e r , OcBVPVar. Sw i t chCoo rd i n a t e ) ; . . .

f e v a l (OcBVPVar . BVPFunction . A s ymp to t i cT ran s v e r s a l i t yCond ,# , . . . ) ] ;

File for asymptotic boundary condition

f u n c t i o n out = coralreef1DsBVP4WEC ( dynVara , dynVarb , pararg , a r ca rg , sw i t c h i d , sw i t ch coo rd )%% the BC f i l e f o r the We i e r s t r a s s Erdman c o nd i t i o n sconnec r e s = [ ] ; % res iduum f o r connec t i n g h y b r i d path sc o n s t r a i n r e s = [ ] ; % res iduum d e s c r i b i n g the boundary o f c o n s t r a i n t smu l t r e s = [ ] ; % res iduum d e s c r i b i n g the boundary o f a dm i s s i b l e Lagrange m u l t i p l i e r s

sw i t ch sw i t c h i dcase ’ 1 ’

conn ec r e s=dynVarb ( 1 : 2 )−dynVara ( 3 : 4 ) ;c o r a l r e e f 1D sC o n s t r a i n t ( [ ] , dynVara ( 3 : 4 ) , pararg , a r c a r g (2 ) ) ;c o n s t r a i n r e s =[ c o n s t r a i n r e s ; ans ( sw i t ch coo rd (1 ) ) ] ;

endout=[ connec r e s ; c o n s t r a i n r e s ; mu l t r e s ] ;

Page 21: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

A two-state capital accumulation model

Model formulation

maxI1(·),I2(·)

0

e−rt

(

(1− γ1q1 − ηq2)q1+

(θ − γ2q2 − ηq1)q2−

1

2I 21 −

1

2I 22

)

dt

q1 = αK1

q2 = βK122 ,

s.t. K1 = I1 − δ1K1,

K2 = I2 − δ2K2,

s.t. I1 ≥ 0,

I2 ≥ 0.

Page 22: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

A two-state capital accumulation model

Initialization file (twostateaccumulation.m)

% Two s t a t e c a p i t a l ac cumu la t i on wi th he t e rogenous p r oduc t s :d i s r u p t i v e vs . non−d i s r u p t i v e goods

s t a t ed ynam i c s=sym( ’ [ u1−d e l t a 1∗x1 ; u2−d e l t a 2∗x2 ] ’ ) ;o b j e c t i v e f u n c t i o n=sym( ’ a lpha∗x1−gamma1∗ a lpha ˆ2∗x1ˆ2+the t a∗beta

∗ s q r t ( x2 )−gamma2∗beta ˆ2∗x2−3∗e t a∗ a lpha∗beta ˆ2∗x1∗x2−u1ˆ2/2−u2ˆ2/2 ’ ) ;

c o n t r o l c o n s t r a i n t=sym( ’ [ u1−I 1 ; u2−I 2 ] ’ ) ;

% Gene ra lr = 0 . 1 ;a lpha = 1 ;be ta = 1 ;d e l t a 1 = 0 .1 ;d e l t a 2 = 0 . 1 5 ;e t a = 0 . 6 ;gamma1 = 1 ;gamma2 = 1 ;t h e t a = 1 . 5 7 5 ;I 1 =0;I 2 =0;

Page 23: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Optimal control values

Possible arc identifiers

f u n c t i o n out=twos t a t eac cumu l a t i onOp t ima lCon t r o l ( t , dynVar , pararg , a r c a r g )%% r e t u r n s the op t ima l c o n t r o l v a l u e o f model two s t a t eac cumu l a t i on

% Parameter Valuer=pa ra r g (1 ) ;I 1=pa ra r g (2 ) ;I 2=pa ra r g (3 ) ;a lpha=pa ra r g (4 ) ;be ta=pa ra r g (5 ) ;d e l t a 1=pa ra r g (6 ) ;d e l t a 2=pa ra r g (7 ) ;e ta=pa ra r g (8 ) ;gamma1=pa ra r g (9 ) ;gamma2=pa ra r g (10) ;t h e t a=pa ra r g (11) ;T=pa ra r g (12) ;% Func t i on s

% Optimal Con t r o l Valuesw i t ch a r c a r g

case {1}out =[ [ ( dynVar ( 3 , : ) ) ] ; . . .

[ ( dynVar ( 4 , : ) ) ] ] ;case {2}

out =[ [ repmat ( I1 , 1 , s i z e ( dynVar , 2 ) ) ] ; . . .[ ( dynVar ( 4 , : ) ) ] ] ;

case {3}out =[ [ ( dynVar ( 3 , : ) ) ] ; . . .

[ repmat ( I2 , 1 , s i z e ( dynVar , 2 ) ) ] ] ;case {4}

out =[ [ repmat ( I1 , 1 , s i z e ( dynVar , 2 ) ) ] ; . . .[ repmat ( I2 , 1 , s i z e ( dynVar , 2 ) ) ] ] ;

o t h e rw i s ee r r o r ( [ ’ I n d ex argument ’ num2str ( a r c a r g ) ’ unknown . ’ ] )

end

Page 24: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Analysis: Equilibria

>> m=ocmodel ( ’ two s t a t eac cumu l a t i on ’ ) ;>> m=changeparameter (m, ’ beta , d e l t a1 , d e l t a2 , gamma2 , t h e t a ’ , [ 0 . 6 0 . 2 0 . 2 1 . 1 1 . 5 ] ) ;>> ocEP=ca l c e p (m) ; b=i s n e g a t i v e s t a t e (m, ocEP) ; ocEP(b==1)= [ ] ; ocEP{:}

Search f o r z e r o sWarning : E x p l i c i t s o l u t i o n cou l d not be found .> I n s o l v e at 140

I n sym . s o l v e at 49I n optdyn . f s o l v e at 93I n optdyn . c a l c e p at 39I n ocmodel . c a l c e p at 147

ans =d yn p r im i t i v e o b j e c t :

Coo rd i n a t e s :0.32958−2.9982 e−068 i0.49547+9.5313 e−068 i0.065916−5.9964 e−069 i0.099095+1.9063 e−068 i

Arc i d e n t i f i e r : 1L i n e a r i z a t i o n : [ 4 x4 doub l e ]

ans =d yn p r im i t i v e o b j e c t :

Coo rd i n a t e s :00 .979211.21820.19584

Arc i d e n t i f i e r : 2L i n e a r i z a t i o n : [ 4 x4 doub l e ]

>> b=i s a dm i s s i b l e (m, ocEP)b =

1 0>> l m u l t i p l i e r (m, ocEP{2}) , ocEP(˜ b ) = [ ] ;ans =

−1.2182 −1.21820 0

Page 25: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Analysis: Stable path

>> ocEPr=r e a l ( ocEP{1}) ; ocEPr{1}. dynVar ,m=s t o r e (m, ocEPr ) ;ans =

0.3296 0.32960.4955 0.49550.0659 0.06590.0991 0.0991

>> e i g ( ocEPr{1})ans =

−1.47401.5740

−0.61900.7190

i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , [ 1 : 2 ] , [ 1 . 5 1 . 5 ] , ocEPr{1}, ’I n t e g r a t i o nT ime ’ ,500 , ’ Con t inuat i onType ’ , ’ f ’ ) ;

Arc I d e n t i f i e r 1>> [ s o l s o l n ]= occon t (m, i n i t S t r u c t , opt ) ;>> c o n t r o l (m, s o l n ) ; ans ( : , [ 1 : 8 end ] )ans =

−0.0000 0.0358 0.0524 0.0600 0.0635 0.0650 0.0656 . . . 0 .06590.0642 0.0807 0.0889 0.0933 0.0956 0.0969 0.0976 . . . 0 .0991

>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , [ 1 : 2 ] , [ 1 . 5 1 . 5 ] , s o l n ) ;>> opt=s e t o c o p t i o n s ( opt , ’OCCONT ’ , ’ Mean I t e r a t i on ’ , 35) ;>> [ s o l 1 s o l 1 n ]= occon t (m, i n i t S t r u c t , opt ) ;>> c o n t r o l (m, s o l 1 n ) ; ans ( : , [ 1 : 8 end ] )ans =

0 0 0 0 0 0 0 . . . 0−0.0000 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 . . . 0 .0654

0 0.0357 0.0522 0.0599 0.0633 0.0649 0.0656 . . . 0 .06590.0654 0.0815 0.0895 0.0937 0.0959 0.0971 0.0978 . . . 0 .0991

>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , [ 1 : 2 ] , [ 1 . 5 1 . 5 ] , s o l 1 n ) ;>> [ s o l 2 s o l 2 n ]= occon t (m, i n i t S t r u c t , opt ) ;

Page 26: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Animation: Multiple constraints becoming active

Page 27: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Calculating the objective value

Formula∫

0

e−rt g(x◦(t), u◦(t)) dt =1

rH(x◦(0), u◦(0), λ(0))),

Page 28: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Slice manifold

Remark

The slice manifold is an occurve object, consisting of the initialsolution points calculated during continuation.

>> s l i c em a n i f o l d (m)ans =

[1 x1 occu r v e ] [ 1 x1 occu r v e ] [ 1 x1 occu r v e ]>> c l f , p l o t 3 p h a s e o c r e s u l t (m, ’ c o s t a t e ’ , 1 , 2 , 1 , ’ on l y ’ ,{ ’ S l i c eMa n i f o l d ’} , ’ Co lo r ’ , [ 0 0 0 ] ) ,

ho ld on>> p l o t 3 p h a s e o c r e s u l t (m, ’ c o s t a t e ’ , 1 , 2 , 1 , ’ on l y ’ ,{ ’ E x t r ema l S o l u t i o n ’} , ’ o n l y i n d e x ’ ,{3} , ’

Con t inuous ’ , ’ o f f ’ , ’ l i m i t s e t ’ , ’ o f f ’ )>> p l o t 3 p h a s e o c r e s u l t (m, ’ c o s t a t e ’ , 1 , 2 , 1 , ’ on l y ’ ,{ ’ E q u i l i b r i um ’} , ’ Marker ’ , ’ . ’ , ’ Marke rS i ze

’ , 16)>> s e t ( gca , ’XLim ’ , [ 0 . 4 1 ] , ’YLim ’ , [ 0 . 5 0 . 9 ] , ’ ZLim ’ ,[−2 0 ] ) , v iew (−26 ,42)

0.40.5

0.60.7

0.80.9

1

0.5

0.55

0.6

0.65

0.7

0.75

0.8

0.85

0.9

−2

−1.5

−1

−0.5

0

K1

K2

λ1

Page 29: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Calculating boundary curves

OCMat syntax

>> ocExn=e x t r ema l s o l v (m) ;>> i n i t S t r u c t=i n i t o c c o n t ( ’ boundary ’ ,m, ’ i n i t p o i n t ’ , 2 , 0 , ocExn{1}) ;>> opt=s e t o c o p t i o n s ( opt , ’OCCONT ’ , ’ I n i t S t epWid th ’ , 0 . 01/5ˆ1 , ’MaxStepWidth ’ , 0 . 0 1 ) ;>> [ s o l b s o l bn ]= occon t (m, i n i t S t r u c t , opt ) ;

Page 30: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

The BVP describing the boundary curve

x(t) = f (x(t)), t ∈ [0,∞), x ∈ R4

xi (0) = xi,0, i ∈ {1, 2} (5a)

limt→∞

x(t) = x (5b)

s(x(0)) = 0 (5c)

• (5a): Fixing one coordinate of the initial point.

• (5b): Stable path property.

• (5c): Active control constraint (I1 = 0 or I2 = 0).

Remark

Using a detected non-admissible solution soln, a continuationalgorithm can be used to continue problem (5).

Page 31: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Implementation

Initialization

>> ocExn=e x t r ema l s o l v (m)>> i n i t S t r u c t=i n i t o c c o n t ( ’ boundary ’ ,m, ’ i n i t p o i n t ’ , 2 , 0 , ocExn{1})i n i t S t r u c t =

Asymptot icBCMatr ix : [ 2 x4 doub l e ]Con t inuat i onType : ’ f ’

I d e n t i f i e r : ’ boundary ’I n i tBVSo l u t i o n : [ 1 x1 s t r u c t ]

I n i tO cT r a j e c t o r y : [ 1 x1 oca s ymp to t i c ]I n i t i a l V a l u e : 0 .5356

I n t e g r a t i o nT ime : 500Ta rge tCoo rd i n a t e : 2

Targe tVa lue : 0Te rm ina lCond i t i on : ’ ’

Ze ro Index : 1>> i n i t S t r u c t . BVPFunctionans =

Con t i nua t i on : ’ twos ta t eaccumu la t i onBVP4Cont inuat i on ’Weiers t rassErdmannCond : ’ twostateaccumulationBVP4WEC ’

Asymp to t i cT ran s v e r s a l i t yCond : ’ twostateaccumulat ionBVP4AsymTransCond ’Boundary : ’ twostateaccumulat ionBVP4Boundary ’

f u n c t i o n out = twostateaccumulat ionBVP4Boundary( dynVara , pararg , a r ca rg , z e r o i n d e x )%% the BC f i l e f o r the boundary r e g i o n o f c o n s t r a i n t s

two s t a t e a c c umu l a t i o nAdm i s s i b l e ( [ ] , dynVara ( 1 : 4 ) , pararg , a r c a r g (1 ) ) ;out=ans ( z e r o i n d e x ) ;

Page 32: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

The boundary curve as an occurve object

Fields of the boundary curve

>> m=s t o r e (m) ;>> m. o cRe s u l t sans =

BoundaryCurve : {[1 x1 occu r v e ] [ 1 x1 occu r v e ] [ 1 x1 occu r v e ] [ 1 x1 occu r v e ]}>> m. o cRe s u l t s . BoundaryCurve ; ocC=ans ( [ 1 end ] ) ; s t r u c t ( ocC{1})ans =

dynVar : [ 4 x122 doub l e ]a r c i d : [ 1 x122 doub l e ]t ype : ’ boundary ’

a s s o c i a t e d s o l : [ 1 x1 oca s ymp to t i c ]i n f o : [ 1 x1 s t r u c t ]

>> ocC{1}. a r c i d ( [ 1 end ] )ans =

1 1>> ocC{1}. i n f oans =

name : ’ C o n t r o l C o n s t r a i n t ’z e r o i n d e x : 1

>> ocC{2}. a r c i d ( [ 1 end ] )ans =

3 3>> ocC{2}. a r c i d ( [ 1 end ] )ans =

3 3>> ocC{2}. i n f oans =

name : ’ C o n t r o l L a g r a n g eMu l t i p l i e r ’z e r o i n d e x : 4

Page 33: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Plotting boundary curves

Fields of the boundary curve

>> p l o t p h a s e o c r e s u l t (m, ’ s t a t e ’ , 1 , 2 , ’ on l y ’ ,{ ’ BoundaryCurve ’} , ’ Co lo r ’ , [ 0 0 0 ] )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e d s o l ’ , ’ on ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e c o n t i n u o u s ’ , ’ o f f ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e l i m i t s e t ’ , ’ on ’ , ’ a s s o c i a t e l i m i t s e tMa r k e r ’ , ’ . ’ , ’

a s s o c i a t e l i m i t s e tM a r k e r S i z e ’ , 16)

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Page 34: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Plotting boundary curves

Fields of the boundary curve

>> p l o t p h a s e o c r e s u l t (m, ’ s t a t e ’ , 1 , 2 , ’ on l y ’ ,{ ’ BoundaryCurve ’} , ’ Co lo r ’ , [ 0 0 0 ] )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e d s o l ’ , ’ on ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e c o n t i n u o u s ’ , ’ o f f ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e l i m i t s e t ’ , ’ on ’ , ’ a s s o c i a t e l i m i t s e tMa r k e r ’ , ’ . ’ , ’

a s s o c i a t e l i m i t s e tM a r k e r S i z e ’ , 16)

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Page 35: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Plotting boundary curves

Fields of the boundary curve

>> p l o t p h a s e o c r e s u l t (m, ’ s t a t e ’ , 1 , 2 , ’ on l y ’ ,{ ’ BoundaryCurve ’} , ’ Co lo r ’ , [ 0 0 0 ] )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e d s o l ’ , ’ on ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e c o n t i n u o u s ’ , ’ o f f ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e l i m i t s e t ’ , ’ on ’ , ’ a s s o c i a t e l i m i t s e tMa r k e r ’ , ’ . ’ , ’

a s s o c i a t e l i m i t s e tM a r k e r S i z e ’ , 16)

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Page 36: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

Plotting boundary curves

Fields of the boundary curve

>> p l o t p h a s e o c r e s u l t (m, ’ s t a t e ’ , 1 , 2 , ’ on l y ’ ,{ ’ BoundaryCurve ’} , ’ Co lo r ’ , [ 0 0 0 ] )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e d s o l ’ , ’ on ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e c o n t i n u o u s ’ , ’ o f f ’ )>> p l o t p h a s e o c r e s u l t ( . . . , ’ a s s o c i a t e l i m i t s e t ’ , ’ on ’ , ’ a s s o c i a t e l i m i t s e tMa r k e r ’ , ’ . ’ , ’

a s s o c i a t e l i m i t s e tM a r k e r S i z e ’ , 16)

0 0.5 1 1.50

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Page 37: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

General problem

Outlook

Coral reef model

Analysis

NOC

Arcs of constraints

Numeric analysis

Equilibria

Stable path

(In)active constraints

BVP Implementation

Initialization

Dynamic files

Dynamics

BC files

Two-state model

Numeric analysis

Equilibria

Stable path

Multiple constraints

Slice manifold

Boundary curves

BVP Implementation

Initialization

Plotting

References

OCMat functions

References

J.P. Caulkins, G. Feichtinger, D. Grass, and G. Tragler. Optimal controlof terrorism and global reputation: A case study with novel thresholdbehavior. Operations Research Letters, 37(6):387–391, 2009

J.P. Caulkins, G. Feichtinger, D. Grass, R.F. Hartl, and P.M. Kort. Twostate capital accumulation with heterogeneous products: disruptive vs.non-disruptive goods. Journal of EconomicDynamics and Control, 2010.In submission

I. Zeiler, J.P. Caulkins, D. Grass, and G. Tragler. Keeping options open:an optimal control model with trajectories that reach a DNSS point inpositive time. SIAM Journal on Control and Optimization, 48(6):3698–3707, 2010

D. Grass. Numerical computation of the optimal vector field in a fishery

model. The Beijer Discussion Paper 224, The Beijer Institute, The

Royal Swedish Academy of Sciences, 2010

Page 38: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.118

Retrieve non admissible solutions

f u n c t i o n ocEx = e x t r ema l s o l v ( ocObj , v a r a r g i n )%% EXTREMALSOLV r e t u r n s the non−adms s i b l e e x t r ema l s o l u t i o n s%% OCEX=EXTREMALSOLV(OCOBJ) r e t u r n s a c e l l a r r a y o f o c t r a j e c t o r i e s OCEX, which v i o l a t e% e i t h e r c o n t r o l c o n s t r a i n t s , o r the non−n e g a t i v i t y c o n d i t i o n o f the Lagrang ian% mu l t i p l i e r .%% The p o s i t i o n o f the v i o l a t i o n i s marked i n the f i e l d ’ v i o l a t i o n ’ o f the o c t r a j e c t o r y .% This f i e l d i s g i v en by a mat r i x o f z e r o s and ones , where z e r o c h a r a c t e r i z e s an% a dm i s s i b l e p o i n t and one a non−a dm i s s i b l e p o i n t . The s i z e o f t h i s mat r i x i s g i v en by% the number o f a r c s and f o r each a r c the number o f rows i s two t imes t h a t o f the% number o f c o n s t r a i n t s , where the f i r s t s e t o f rows co r r e s pond to the c o n s t r a i n t s and% the second s e t o f rows to the Lagrang ian m u t l i p l i e r s .%% OCEX=EXTREMALSOLV(OCOBJ, IDX) r e t u r n s the c e l l a r r a y o f o c t r a j e c t o r i e s OCEX s p e c i f i e d% by IDX .

Page 39: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.119

Retrieve slices through the (stable) manifold

f u n c t i o n slMF = s l i c em a n i f o l d ( ocObj , v a r a r g i n )%% SLICEMANIFOLD r e t u r n s the s l i c e man i f o l d s%% SLMF=SLICEMANIFOLD(OCOBJ) r e t u r n s a c e l l a r r a y o f o c cu r v e s SLMF, c o n s i s t i n g o f% the i n t i a l p o i n t s ( s t a t e−c o s t a t e ) , c a l c u l a t e d du r i n g c o n t i n u a t i o n . Thus% the s l i c e−man i f o l d s co r r e s pond to a s l i c e th rough the ( s t a b l e ) man i f o l d a long% a l i n e i n the s t a t e space . These p o i n t s can be used to c a l c u l a t e the o b j e c t i v e% va l u e o f an ex t r ema l u s i n g the fo rmu la% i n t 0 ˆ i n f ( eˆ(− r∗t ) g ( x ( t ) , u ( t ) ) dt=1/ r∗H( x (0 ) , u (0 ) , lambda (0 ) ) ,% s i n c e ( x (0 ) , lambda (0 ) ) co r r e s pond to the p o i n t s o f s l i c e−man i f o l d and u (0 ) i s% dete rm ined by the maximum co n d i t i o n .%% SLMF=SLICEMANIFOLD(OCOBJ, IDX) r e t u r n s the c e l l a r r a y o f o c cu r v e s SLMF s p e c i f i e d by% IDX .

Page 40: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.120

Admissibility

f u n c t i o n [ v i o l a t i o n f l a g , v i o l a t i o nma t , v a r a r g ou t ]= t e s t a dm i s s i b i l i t y 4 u n i q u e ( ocObj , o d e t r j ,a r c i d , v a r a r g i n )

%% TESTADMISSIBILITY4UNIQUE t e s t s a d m i s s i b i l i t y%% TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS) t e s t s i f th e p o i n t s o f PTS , which can be e i t h e r% an o c t r a j e c t o r y o r occurve , a r e adm i s s i b l e , i . e . , s a t i s f y the c o n s t r a i n t s and% non−n e g a t i v i t y c o n d i i t o n o f the Lagrang ian m u l t i p l i e r .%% TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS , ARCID) i f PTS i s a s o l u t i o n s t r u c t u r e o f an% IVP/BVP, the c o r r e s p on d i n g ARCID f o r each a r c has to be p rov i d ed .%% TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS , ARCID ,FUNC) wi th FUNC, a f u n c t i o n d e t e rm in i n g the% a dm i s s i b l i t y can be p rov i d ed . The d e f a u l t f u n c t i o n i s g i v en by ’ modelnameAdmiss ib le ’ .%% TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS , ARCID ,FUNC,OPT) the o c op t i o n s s t r u c t u r e OPT can be% used to s e t a t o l e r a n c e v a l u e f o r a dm i s s i b i l i t y , to change t h i s v a l u e use :% opt=s e t o c o p t i o n s ( ’OC’ , ’ A dm i s s i b i l i t y T o l e r a n c e ’ , v a l )% the d e f a u l t v a l u e i s 1e−6.%% B=TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS , . . . ) the argument B i s 0 i f the p o i n t s a r e% a dm i s s i b l e and 1 o t h e rw i s e .%% [B VM]=TESTADMISSIBILITY4UNIQUE (OCOBJ,PTS , . . . ) VM i s the c o r r e s p on d i n g v i o l a t i o n% matr ix , where each column co r r e s pond to a p o i n t o f PTS and the v a l u e s o f the rows% (0 or 1) co r r e s pond to a s p e c i f i c a d m i s s i b i l i t y check . By d e f a u l t t h e s e a r e the% c o n s t r a i n t s and Lagrang ian m u l t i p l i e r s .%% In case o f mu l t i p l e a r c s f o r PTS, the ma t r i c e s f o r each a r c a r e concatenated a long% the f i r s t d imens ion .

Page 41: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.121

Test equilibria

f u n c t i o n b=i s r e a l ( v a r a r g i n )%% ISREAL de t e rm in e s i f a d y n p r im i t i v e i s r e a l v a l u ed .%% B = ISREAL(DYNPRIM) B i s 1 i f the dynVar v a r i a b l e o f the d y n p r im i t v e% DYNPRIM i s r e a l v a l u ed and 0 o t h e rw i s e .%% ISREAL(DYNPRIM,OPT) wi th OPT the t o l e r a n c e f o r b e i n g c l a s s i f i e d as r e a l% va l u ed can be changed by s e t t i n g :% opt=s e t o c o p t i o n s ( ’OC’ , ’ Imag i n a r yTo l e r an ce ’ , v a l )%% ISREAL(DYNPRIM1 , . . . , DYNPRIMN,OPT) r e t u r n s a v e c t o r B c o n s i s t i n g o f% 0 or 1 f o r each o f the d y n p r im i t i v e o b j e c t s DYNPRIM1 , . . . , DYNPRIMN.

f u n c t i o n b=i s n e g a t i v e s t a t e ( ocObj , v a r a r g i n )%% ISNEGATIVESTATE t r u e i f a s t a t e i s n e g a t i v e .%% B = ISNEGATIVESTATE(DYNPRIM) B i s 1 i f a s t a t e o f the d y n p r im i t v e DYNPRIM i s% n ega t i v e and 0 o t h e rw i s e .%% B = ISNEGATIVESTATE(DYNPRIM1 , . . . , DYNPRIMN) r e t u r n s a v e c t o r B c o n s i s t i n g o f% 0 or 1 f o r each o f the d y n p r im i t i v e o b j e c t s DYNPRIM1 , . . . , DYNPRIMN.

f u n c t i o n r ea l d ynPr im=r e a l ( v a r a r g i n )%% REAL r e t u r n s the r e a l v a l u ed c ou n t e r p a r t .%% RDYNPRIM = REAL(DYNPRIM) r e t u r n s a d y n p r im i t i v e o b j e c t RDYNPRIM, w i th on l y% the r e a l p a r t s , as w e l l f o r the dynVar f i l e d as the l i n e a r i z a t i o n f i e l d ,% o f the d y n p r im i t i v e DYNPRIM.%% RDYNPRIM = REAL(DYNPRIM1 , . . . , DYNPRIMN) r e t u r n s a t r an s f o rmed c e l l a r r a y o f% d yn p r im i t i v e o b j e c t s RDYNPRIM.

Page 42: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.122

Default options

f u n c t i o n opt = d e f a u l t o c o p t i o n s ( )%% DEFAULTOCOPTIONS Crea t e s and r e t u r n s a s t r u c t u r e c o n t a i n i n g a l l d e f a u l t% op t i o n s f o r the OCMAT too l b ox .%% The i n t e n t i o n o f t h i s s t r u c t u r e i s to a l l ow a compact h an d l i n g o f the% d i f f e r e n t o p t i o n s . I t c o n s i s t s o f s e v e r a l s u b s t r u c t u r e s each c o n t a i n i n g% d e f a u l t o p t i o n s needed f o r d i f f e r e n t computat i on s o f the t oo l b ox .%% OPT = DEFAULTOCOPTIONS the s t r u c t u r e OPT c o n s i s t s o f s e v e r a l% su b s t r u c t u r e s , which can be i d e n t i f i e d by t h e i r name and which c on t a i n% op t i o n s needed f o r d i f f e r e n t a p p l i c a t i o n s w i t h i n the t oo l b ox :% ’OC’ . . . . . g e n e r a l OCMat op t i o n s% ’OCCONT’ . . . . . o p t i o n s f o r the c o n t i n u a t i o n a l g o r i t hm% ’OCCONTARG’ . . . . . o p t i o n s needed f o r the i n i t i a l i z a t i o n o f a BVP% ’ODE’ . . . . . o p t i o n s f o r s o l v i n g an IVP ( p rov i d ed by MATLAB% − s e e od e s e t / odeget )% ’BVP’ . . . . . o p t i o n s f o r s o l v i n g an IVP ( p rov i d ed by MATLAB% − s e e b vp s e t / bvpget )% ’EP ’ . . . . . o p t i o n s needed f o r the c a l c u l a t i o n o f s t e ad y% s t a t e s ( p r ov i d ed by MATLAB ( o p t im i z a t i o n% too l b ox )− s e e op t ims e t / op t imget )% ’MATCONT’ . . . . . c o n t a i n s o p t i o n s r e q u i r e d by MATCONT too l b ox% ( s e e c on t s e t / con tge t )% ’SBVP’ . . . . . f o r the BVPSuite ( not implemented y e t )%% Note th a t the d e f a u l t v a l u e s o f the op t i o n s a r e c e r t a i n l y not p e r f e c t l y% s u i t a b l e f o r a l l models . However , the op t i o n s can be e a s i l y a d j u s t e d by% us i n g the f u n c t i o n ’ s e t o c op t i o n s ’ , by which one can a c c e s s and man ipu la t e% the v a l u e s o f t h i s op t i on s t r u c t u r e . P l e a s e be aware t h a t a bad l y done% (manual ) man i pu l a t i on o r the use o f a d i f f e r e n t op t i on s t r u c t u r e% might l e a d to a ma l f un c t i on o f the t oo l b ox .

Page 43: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.123

Setting options

f u n c t i o n op t s=s e t o c o p t i o n s ( v a r a r g i n )%% SETOPTIONS l e t s you a d j u s t the op t i o n s o f the OCMAT too l b ox .%% OPT=SETOPTIONS(CAT1,NAME1,VALUE1 ,CAT2 ,NAME2,VALUE2 , . . . ) r e p l a c e s the% v a l u e s o f the op t i o n s NAME1, NAME2 , . . . i n the c a t e g o r i e s CAT1,CAT2 , . . o f% the d e f a u l t op t i on s t r u c t u r e w i th new v a l u e s VALUE1 , VALUE2 , . . . and% r e t u r n s an op t i on s t r u c t u r e OPT wi th the changed op t i o n s .%% OPT=SETOPTIONS(OPS,CAT1 ,NAME1,VALUE1 ,CAT2,NAME2,VALUE2 , . . . ) r e p l a c e s the% v a l u e s o f the op t i o n s NAME1, NAME2 , . . . i n the c a t e g o r i e s CAT1,CAT2 , . . o f% the op t i on s t r u c t u r e OPT wi th new v a l u e s VALUE1 , VALUE2 , . . . and% r e t u r n s the op t i on s t r u c t u r e OPT wi th the changed op t i o n s .%% OPT=SETOPTIONS(OPT,CAT1 ,NAME1,VALUE1 ,NAME2,VALUE2 ,CAT2,NAME3,VALUE3 , . . )% r e p l a c e s the v a l u e s o f the op t i o n s NAME1, NAME2, . . . o f the ca t ego r y CAT1% of the ( o p t i o n a l ) op t i on s t r u c t u r e OPT wi th the v a l u e s VALUE1 and VALUE2% and op t i on NAME3 o f ca t ego r y CAT2 wi th v a l u e VALUE3 e t c . and r e t u r n s% the changed op t i on s t r u c t u r e OPT.

Page 44: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.124

Retrieving options

f u n c t i o n v a r a r g ou t = ge t o c op t i o n s ( v a r a r g i n )%% GETOCOPTIONS r e t u r n s the v a l u e o f the op t i o n s d e f i n e d i n v a r a r g i n%% [VALUE1 VALUE2 . . . ] =GETOCOPTIONS(CAT1 ,NAME1,CAT2,NAME2 , . . . ) r e t u r n s the% d e f a u l t v a l u e s o f the op t i o n s w i th the named NAME1, NAME2 , . . . l o c a t e d i n% the c a t e g o r i e s CAT1,CAT2 , . .%% [VALUE1 VALUE2 . . . ] =GETOCOPTIONS(CAT1 ,NAME1,DEFAULTVALUE1,CAT2,NAME2 , . . . )% r e t u r n s the d e f a u l t v a l u e s o f the op t i o n s w i th the named NAME1, NAME2 , . . .% l o c a t e d i n the c a t e g o r i e s CAT1,CAT2 , . . . I f t h e d e f a u l t v a l u e s a r e empty% the o p t i o n a l i n p u t argument d e f a u l t v a l u e a s s i g n s an a l t e r n a t i v e v a l u e to% t h i s op t i on . Th is d e f a u l t v a l u e does not have to be a s s i g n ed f o r e v e r y% op t i on tha t i s to be r e t u r n e d .%% [VALUE1 VALUE2 . . . ] =GETOCOPTIONS(OPT,CAT1,NAME1,CAT2 ,NAME2 , . . . ) r e t u r n s the% va l u e o f the op t i o n s w i th the names NAME1,NAME2 , . . . o f the c a t e g o r i e s% CAT1,CAT2 , . . . o f the op t i on s t r u c t u r e OPT.%% [VALUE1 VALUE2 . . . ] =GETOCOPTIONS(OPTS,CAT1,NAME1,DEFAULTVALUE1,CAT2,NAME2 , . . . )% r e t u r n s the v a l u e o f the op t i o n s w i th the names NAME1,NAME2 , . . . o f the% c a t e g o r i e s CAT1,CAT2 , . . . o f the op t i on s t r u c t u r e OPT. To avo i d an empty% output argument one can a s s i g n d e f a u l t v a l u e s t h a t a r e r e t u r n e d i n case% the r e q u i r e d v a l u e o f the op t i on i s empty i n t h i s op t i on s t r u c t u r e .%% [VALUE1 VALUE2 . . . ] =GETOCOPTIONS(OPTS,CAT1,NAME1,DEFAULTVALUE1,NAME2,CAT2 , . . . )% r e t u r n s the v a l u e o f the op t i o n s w i th the names name1 , name2 , . . . o f the% c a t e g o r i e CAT1 o f the op t i on s t r u c t u r e OPT. To avo i d an empty% output argument one can a s s i g n d e f a u l t v a l u e s t h a t a r e r e t u r n e d i n case% the r e q u i r e d v a l u e o f the op t i on i s empty i n t h i s op t i on s t r u c t u r e .

Page 45: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.125

Important options for the continuation process

>> opt=d e f a u l t o c o p t i o n s ;>> opt .OCCONTans =

BVPBCJacobian : ’ o f f ’ . . . u s i n g the Jacob ian o f the boundary c o n d i t i o n s ( ’ on ’ / ’o f f ’ )

BVPFJacobian : ’ o f f ’ . . . u s i n g the u s u a l Jacob ian ( ’ on ’ / ’ o f f ’ )BVPMaxNum : 5000 . . . Maximum number o f mesh p o i n t s a l l owed when s o l v i n g the

BVPMaxCont inuat i onStep s : I n f . . . Maximum number o f c o n t i n u a t i o n s t e p s

MaxResiduumNorm : 1e−3 . . . Minimum t o l e r a n c e f o r a BVP s o l u t i i o n to be a dm i s s i b l eCheck : ’ on ’ . . . Check a d m i s s i b i l i t y o f the s o l u t i o n du r i n g

c o n t i n u a t i o nTo t a l R e l a t i v eD i s t a n c e : 1 . . . Change the r e l a t i v e d i s t a n c e u n t i l t h e c o n t i n u a t i o n

p r o c e s s s t o p s ( (0 i n f ] )Backward : 0 . . . D i r e c t i o n o f the c o n t i n u a t i o n p r o c e s s (0/1)

I n i t S t epWid th : 1e−4 . . . I n i t i a l s t ep width f o r the c o n t i n u a t i o n p r o c e s sSaveOutput : ’ on ’ . . . Saves the l a s t data a f t e r each c o n t i n u a t i o n s t ep .

The r e f o r e c o n t i n u a t i o n can be i n t e r r u p t e d w i thou t l o o s i n g the l a s tr e s u l t .

MaxStepWidth : 0 . 5 . . . S e t s the maximum s t ep width . For a ’ f i x e d s t e pw i d t h ’( ( 0 1) )

Mean I t e r a t i on : 15 . . . I f t h e r e t u r n e d v a l u e BCEVALS from the BVP So l v e rbvp4c /bvp5c i s sma l l e r than tha t v l a u e the s t ep width i s i n c r e a s e d .

MinStepWidth : 1e−8 . . . The c o n t i n u a t i o n p r o c e s s i s s topped i f the s t ep w i thi s l owe r than tha t v a l u e .

S a v e I n t e rmed i a t e : ’ o f f ’ . . . Th i s a l l ow s to s t o r e a l l i n t e rm e d i a t e r e s u l t s o f ac o n t i n u a t i o n p r o c e s s . Dur ing c o n t i n u a t i o n the r e s u l t s a r e w r i t t e n i n the mat−f i l e ’ Con t inuat i onData . mat ’ , which i s p l a c ed i n the d e f a u l t model dataf o l d e r . With the s t o r e command t h e s e data a r e s t o r e d i n the models o cRe s u l t s.S t epFacto r : 5 . . . The f a c t o r f o r i n c r e a i n g the s t ep width

MaxGr idPoints : 500 . . . G i v e s the maximum number o f g r i d p o i n t s f o r the BVPs o l v e r . I f th e a c t u a l number i n c r e a s e s t h i s number the s t ep width i sr educed .

Page 46: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.126

Calculating a boundary curve

Remark

To start the computation of a boundary curve a non-admissiblesolution has to be provided. The violation field then providesthe information to start continuation. The violation has to occurat the first point.

Example

>> m=ocmodel ( ’ n o n l i n c a p i t a l a c c 2 ’ )>> ocEP=ca l c e p (m)ocEP =

[1 x1 d y n p r im i t i v e ] [ 1 x1 d y n p r im i t i v e ] [ 1 x1 d y n p r im i t i v e ]>> ocEP=r e a l ( ocEP{:}) ;>> i n i t S t r u c t=i n i t o c c o n t ( ’ e x t r ema l ’ ,m, ’ i n i t p o i n t ’ , [ 1 : 2 ] , [ 1 1 ] , ocEP{1}, ’ I n t e g r a t i o nT ime ’

, 500)>> [ s o l s o l n ]= occon t (m, i n i t S t r u c t ) ;>> s o l n . v i o l a t i o nans =

1 0 0 0 . . . 00 0 0 0 . . . 00 0 0 0 . . . 00 0 0 0 . . . 0

>> i n i t S t r u c t=i n i t o c c o n t ( ’ boundary ’ ,m, ’ i n i t p o i n t ’ , 2 , 0 , s o l n ) ;>> [ s o l b s o l bn ]= occon t (m, i n i t S t r u c t ) ;>> m=s t o r e (m) ;>> m. o cRe s u l t sans =

BoundaryCurve : {[1 x1 occu r v e ]}

Page 47: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.127

Initialization for a boundary curve continuation

>> i n i t S t r u c t=i n i t o c c o n t ( ’ boundary ’ ,m, ’ i n i t p o i n t ’ ,VARCOORD,VARVAL,OCEXN) ;

• The signal word is boundary.

• The continuation is done by varying the coordinate VARCOORDto the value VARVAL.

• As an initial solution a non-admissible solution OCEXN has tobe provided (see remark of the previous slide).

Remark

From the violation field the correct arcid for thenon-admissible part is automatically detected. Then the newsolution is generated by adding a trivial arc, which is constant atthe violated point, and has switching time 0.

Page 48: Dieter Graß Lecture3: Higherdimensionalmodelsand constraints · 2010. 12. 15. · Dieter Graß General problem Outlook Coral reef model Analysis NOC Arcs of constraints Numeric analysis

Dieter Graß

Retrieving results

Non admissible

Slicemanifold

Testing

Admissibility

Negativity/Imaginary

Options

Default options

Set options

Retrieve options

Category: OCCONT

Continuation

Boundary curve

Initialization

Plotting

occurve object

3.128

Plotting of an occurve object

Remark

Since the plotting of an occurve in the time domain does ingeneral not make sense, only plotphase is implemented.

Remark

The additional property ’associatedsol’,’on’ for an occurve

can be provided in the plotphase command. The default settingis ’off’. This property allows the plotting of the trajectory storedin the associatedsol field of an occurve.

Remark

To change the line properties of the associatedsol trajectory, putthe signal word associatedsol in front of the usual property,e.g., ’associatedsolcontinuous’,’off’ plots different arcs ofthe trajectory in different colors, ...