Escolar Documentos
Profissional Documentos
Cultura Documentos
Project Two
Author:
Kristn Nanna rmannsdttir, s131163
Collaborator:
Harpa Baldursdttir, s131025
Teacher:
Niels Kjlstad Poulsen
Department of Mathematical Modelling and Computation
Technical University of Denmark
Project Two
Contents
Part 1: The Chain
Question 1 . . . .
Question 2 . . . .
Question 3 . . . .
Question 4 . . . .
.
.
.
.
2
3
5
8
10
14
16
18
18
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Project Two
L
N
m=
M
N
The shape of the chain is characterized by the position of the end point of each elements. If i is the
element number and ui and vi is the difference between start and end point of the chain in the z- and ydirection, respectively, then
z
z
u
=
+
y i+1
y i
v i
i = 0, 1, ....N 1
u2i + vi2 = l2
(1)
z
h
=
y N
0
In steady state the potential energy is minimal. The potential energy can be written as:
J=
N
1
X
i=0
mg
yi + yi+1
2
This expression do not follow the standard formation, but can be rephrased in several different ways.
One way is to rewrite the potential energy as:
J=
N
1
X
1
1
mgyi
mgy0 + mgyN +
2
2
i=1
Another way of rewriting (using the expression for yi+1 ) the potential energy is:
J=
N
1
X
i=0
1
mg(yi + vi )
2
The constraint in (1) can be respected by introducing the angle between the z-axis and the chain element
and using the fact
u
cos(i )
=l
v i
sin(i )
(2)
Project Two
Question 1
The problem is solved by using the relation in equation 2. First we determine the value of the costate
vector at the beginning of the chain and then the number of elements in the chain is increased and the
chain is plotted again.
In this case the N term in the performance index J is zero and the L term is L = mg(yi + 12 vi ). The
Hamiltonian function therefore is:
1
Hi = mg(yi + vi ) + (zi+1 , yi+1 )
2
= mg(yi +
z
cos(i )
+l
y i
sin(i )
1
l sin(i ) + zi+1 (zi + l cos(i )) + yi+1 (yi + l sin(i ))
2
The necessary condition is given by the Euler-Lagrange equations (for i = 0, ..., N 1).
State equation:
z
z
cos(i )
=
+l
y i+1
y i
sin(i )
Costate equations:
zi =
yi =
Hi = zi+1
z
Hi = mg + yi+1
y
Stationarity condition:
0=
1
Hi = m g l cos(i ) zi+1 l sin(i ) + yi+1 l cos(i )
h
z
=
y N
0
0.5 m g + yi+1
zi+1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Project Two
%The function that calculates the initial values and plots the chain.
function a=q1(l_0,x_0,h,L,M,N)
lz(1)=l_0(1);
ly(1)=l_0(2);
z(1)=x_0(1);
y(1)=x_0(2);
l=L/N;
m=M/N;
g=9.81;
for i=1:N
lz(1+i)=lz(i);
ly(i+1)=ly(i)m*g;
th(i)=atan((0.5*m*g+ly(1+i))/lz(i+1));
z(i+1)=z(i)+l*cos(th(i));
y(i+1)=y(i)+l*sin(th(i));
end
17
18
a=[z(N+1)h; y(N+1)];
19
20
21
22
1
2
3
4
5
6
plot(z,y);grid;title('The Chain')
xlabel('z axis')
ylabel('y axis')
7
8
9
10
11
The Chain
0
0.5
y axis
1.5
2.5
0
0.5
1.5
2
z axis
2.5
3.5
Project Two
boundary condition. The value of the initial costate vector forN = 6is:
z
20.2997
0
y =
0
68.6700
The Chain
0
0.5
y axis
1.5
2.5
3
0
0.5
1.5
2
z axis
2.5
3.5
Question 2
Next we solve the problem by using Pontryagins principle, i.e. by using the constraint in equation 1
directly.
The Hamiltonian function is:
1
Hi = mg(yi + vi ) + (zi+1 , yi+1 )
2
z
u
+
y i
v i
1
= mg(yi + vi ) + zi+1 (zi + ui ) + yi+1 (yi + vi )
2
1
y
= vi ( mg + i+1 ) + ui zi+1 + mgyi + yi+1 yi + zi+1 zi
2
Due to the lenght of each element we have the constraint:
u2i + vi2 = l2
For i = 0, ..., N 1, the necessary conditions are:
Project Two
State equation:
z
z
u
=
+
y i+1
y i
v i
Costate equations:
zi =
yi =
Optimality condition:
u
= arg
min
[Hi ] = arg
v i
ui Ui ,vi Vi
Hi = zi+1
z
Hi = mg + yi+1
y
min
ui Ui ,vi Vi
1
vi ( mg + yi+1 ) + ui zi+1 + mgyi + yi+1 yi + zi+1 zi )
2
xN
l
(zi+1 )2 + ( 21 mg + yi+1 )2
In Matlab, the chain is plotted for N = 6 and N = 100 and the value of the costate vector at the
beginning of the chain is determined by using the fsolve function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%The function that calculates the initial values and plots the chain.
function a=q2(l_0,x_0,h,L,M,N)
lz(1)=l_0(1);
ly(1)=l_0(2);
z(1)=x_0(1);
y(1)=x_0(2);
l=L/N;
m=M/N;
g=9.81;
for i=1:N
lz(1+i)=lz(i);
ly(i+1)=ly(i)m*g;
u(i)=lz(1+i)*l/((lz(1+i))^2+(0.5*m*g+ly(1+i))^2)^0.5;
v(i)=(0.5*m*g+ly(1+i))*(1/(lz(1+i))^2+(0.5*m*g+ly(1+i))^2)^0.5;
z(i+1)=z(i)+u(i);
y(i+1)=y(i)+v(i);
15
16
17
Project Two
end
18
19
a=[z(N+1)h; y(N+1)];
20
21
22
23
1
2
3
4
5
6
plot(z,y);grid;title('The Chain')
xlabel('z axis')
ylabel('y axis')
7
8
9
10
11
The Chain
0
500
1000
1500
y axis
2000
2500
3000
3500
4000
4500
5000
0
0.5
1.5
2
z axis
2.5
3.5
Project Two
The Chain
x 10
1
2
y axis
3
4
5
6
7
8
0
0.5
1.5
2
z axis
2.5
3.5
Question 3
Now the chain is considered as two symmetric half chains. The symmetry in the problem is utilized to
reduce the investigation to a problem just involving the one half of the chain. For simplicity N is assumed
even (i.e. N = 2n). In this case the potential energy is:
n1
J 12 =
X
1
1
mgyn +
mgyi + mgy0
2
2
i=1
Project Two
Costate equations:
zi =
Hi = zi+1
z
(3)
yi =
Hi = mg + yi+1
y
(4)
Stationarity condition:
0=
We have a simple partial end point constraint where only a part of the terminal state is fixed. We are
only considering one half of the chain and therefore zn = h/2 and yn is unknown.
The boundary conditions are:
z
0
=
0
y 0
" #
z
h/2
z
= =
yn
y n
y
n
zn = z
yn =
yn
(5)
n =
1
mg
2
(6)
yi+1
zi+1
In Matlab we plot the shape of the chain for N = 100 and determine the value of the costate vector at
the end of the chain. The input to the function is our fictional value of z = 1.
1
2
3
4
5
6
7
8
9
%The function that calculates the initial values and plots the chain.
function a=q3(vz,x_0,h,L,M,N)
n=N/2;
l=L/N;
m=M/N;
z(1)=x_0(1);
y(1)=x_0(2);
l=L/N;
g=9.81;
10
11
12
13
14
15
16
Project Two
lz=vz;
for i=1:n
ly(i+1)=m*g*(ni)+0.5*m*g
th(i)=atan((ly(i+1))/lz);
z(i+1)=z(i)+l*cos(th(i));
y(i+1)=y(i)+l*sin(th(i))
end
17
18
a=z(n+1)h/2; %error
19
20
21
22
1
2
3
4
5
6
plot(z,y);grid;title('The Chain')
xlabel('z axis')
ylabel('y axis')
7
8
9
10
11
The Chain
0
0.5
y axis
1.5
2.5
3
0
0.2
0.4
0.6
0.8
1
z axis
1.2
1.4
1.6
1.8
Question 4
Now we formulate and solve the problem as a continuous problem.
10
Project Two
Let s denote the distance along the wire and = M/L. The positions along the wire obey:
d zs
cos(s )
=
sin(s ) i
ds ys
with
z
0
=
y 0
0
z
h
=
y L
0
The potential energy (in equilibrium) is
ZL
J=
gys ds
0
[zs , ys ]
cos(s )
sin(s )
Hs ,
Hs ] = [0, g]
zs
ys
Hs = zs sin(s ) + ys cos(s )
s
or
tan(s ) =
ys
zs
s = arctan(
The boundary condition are:
=
zL h
1
=
yL 0 i
0
0
1
zL
h
0
=
yL
0
0
11
Project Two
z
0
=
y 0
0
We associate two Lagrangian multipliers, z and y , to each of the two terminal constraints:
[zL , yL ]
1
= [z , y ]
0
0
1
or
zL = z yL = y
Combined with the costate equations:
zs = z ys = y + g(L s)
and from the stationarity condition we get:
tan(s ) =
y + g(L s)
z
When determining z and y , its important that the end point constraints are met.
Matlab is used to plot the wire and determine the value of the costate vector at the beginning of the
wire. The input to the function is our fictional value of the Lagrange multipliers, z = 1 and y = 1.
1
2
3
4
5
6
7
8
function q4b
x_0=[0;0];
h=4;
L=7;
M=14;
g=9.81;
rho=M/L;
v_0=[1;1];
9
10
11
12
opt=optimset;
opt=optimset(opt,'Display','off');
[v,a]=fsolve('q4a',v_0,opt,L,rho,g,x_0,h);
13
14
[a,s,xs]=q4a(v,L,rho,g,x_0,h);
15
16
17
18
19
20
1
2
3
4
5
6
1
2
3
4
z=xs(:,1);
y=xs(:,2);
plot(z,y);grid;title('The wire');xlabel('z');ylabel('y')
s=0;
l=[v(1), v(2)+(Ls)*rho*g]'
function [a,s,xs]=q4a(v_0,L,rho,g,x_0,h)
range=0:0.01:L;
[s,xs]=ode45(@q4,range,x_0,[],v_0,L,rho,g);
zL=xs(end,1);
yL=xs(end,2);
a=[zLh, yL0];
function b=q4(s,x_0,v_0,L,rho,g)
vz=v_0(1);
vy=v_0(2);
l=[vz, vy+rho*g*(Ls)];
12
5
6
Project Two
th=atan(l(2)/l(1));
b=[cos(th);sin(th)];
The wire
0
0.5
1.5
2.5
3
0
0.5
1.5
2
z
2.5
3.5
function hamiltonian
x_0=[0;0];
h=4;
L=7;
M=14;
g=9.81;
rho=M/L;
v_0=[1;1];
9
10
11
12
13
14
15
range=0:0.1:L;
opt=optimset;
opt=optimset(opt,'Display','off');
[v,a]=fsolve('q4a',v_0,opt,L,rho,g,x_0,h);
[a,s,xs]=q4a(v,L,rho,g,x_0,h);
y=xs(:,2);
16
17
18
19
20
21
22
for i=1:length(s)
l=[v(1), v(2)+rho*g*(Ls(i))];
th=atan(l(2)/l(1));
ys=y(i);
H(i)=rho*g*ys+l(1)*cos(th)+l(2)*sin(th);
end
23
24
plot(s,H);grid;title('Hamiltonian function');xlabel('s');ylabel('H(s)')
13
Project Two
Hamiltonian function
71.6055
71.606
71.6065
71.607
H(s)
71.6075
71.608
71.6085
71.609
71.6095
71.61
0
Project Two
The following probabilities are estimated (and assumed to be correct). The total number of bookings on
day one is given by the following probabilities:
P1 (w1 |x1 ) =
0.2
0
0 w1 4
otherwise
or as
Table 1: The probabilities of the total bookings, 1 , on day one
x1 /1
0
0.2
1
0.2
2
0.2
3
0.2
4
0.2
The total number of booking applications and cancellations, 2 , in day two is given by the probabilities:
0.1
0.4
0.1
P2 (w2 |x2 ) =
0.05
0.7
0.05
x2 w2 < 3 x2
w2 = 3 x2
3 x2 < w2 6 x2
x2 w2 < 3 x2
w2 = 3 x2
3 x2 < w2 6 x2
x3 {0, 1}
x3 2
or as:
Table 2: Probabilites of w2 given x2
x2 /w2
0
1
2
3
4
5
6
-6
0.05
-5
-4
0.05
0.05
0.05
0.05
0.05
-3
-2
-1
0.05
0.05
0,05
0.7
0.05
0.05
0.05
0.7
0.05
0.1
0.05
0.05
0.7
0.05
0.05
0
0.1
0.1
0.05
0.7
0.05
0.05
1
0.1
0.1
0.7
0.05
0.05
0.05
2
0.1
0.4
0.05
0.05
0.05
3
0.4
0.1
0.05
0.05
4
0.1
0.1
0.05
5
0.1
0.1
6
0.1
0
0.7
P2 (w3 |x3 ) =
0.3
x3
0
w3 = 0
otherwise
w3 = 0
x3 w< 0
otherwise
x3 = 0
x3 > 0
or as:
15
Project Two
0.06
0.05
0.05
0.075
0.06
0.05
0.1
0.075
0.06
0.05
0.15
0.1
0.075
0.06
0.05
0.3
0.15
0.1
0.075
0.06
0.05
0
1
0.7
0.7
0.7
0.7
0.7
0.7
where x3 is the total number of bookings after the two days and 3 is the (signed) number of no-shows.
Question 5
Dynamic programming is used for solving the problem, i.e. for determining the optimal booking strategy
for day 1.
The performance index, J, is the average cost due to over booking and no-shows:
J = E{max(2000(3 x4 ), 250(x4 3))}
The Bellman function Vi :
Vi (xi ) = min Ei {Li (xi , ui , i ) + Vi+1 (xi+1 )}
ui
Vi (xi ) = min
ui
r
X
k=1
V4
6000
4000
2000
0
250
500
750
16
Project Two
Now we establish V3 (x3 ). The values are denoted as 31 , 32 , ..., 37 and the corresponding probabilities as
p13 , p23 , ..., p73 . In Table 3 , the seven possible values of 3 with corresponding probabilities can be seen.
V3 (x3 ) =
7
X
pk3 {V4 (x3 + 3k ) = p13 V4 (x3 + 31 ) + p23 V4 (x3 + 32 ) + ... + p73 V4 (x3 + 37 )
k=1
300
360
200
450
240
100
600
300
120
0
900
400
150
0
12.5
1800
600
200
0
15
25
0
6000
2800
1400
0
175
350
525
V3 (x3 )
6000
4600
2900
1200
1075
1085
1162.5
Next we establish the W2 (x2 , u2 ) function for each possible combination of x2 and u2 .
For i=1,2 we have:
xi+1 = xi + min(ui , i )
Therefore
W2 (x2 , u2 ) =
13
X
k=1
13
= p12 V3 (x2 +min(u2 +21 +p22 V3 (x2 +min(u2 +22 )+p32 V3 (x2 +min(u2 +23 )...+p13
2 V3 (x2 +min(u2 +2 )
In table 2 the thirteen values 2 can take with the corresponding probabilities are given. The values are
denoted with 21 , 22 , ..., 213 and the corresponding probabilities as p12 , p22 , ..., p13
2 .
In Table 6 the Bellman equation is performed on function W2 and the last two columns show the results.
The values of V2 (x2 ) are the minimal values of W2 for each x2 and u2 (x2 ) is the optimizing decision.
Table 6: Values of V2
W2
x2
0
1
2
3
4
5
6
0
6000
4740
3140
1695
1676.25
1677.25
1681.13
1
4740
3380
1695
1676.25
1677.25
1681.13
2
3380
2190
1676.25
1677.25
1681.13
u2
3
2190
2152.5
1677.25
1681.13
4
2152.5
2154.5
1681.13
5
2154.5
2162.25
6
2162.25
V2 (x2 )
u2 (x2 )
2152.5
2152.5
1676.25
1676.25
1676.25
1677.25
1681.13
4
3
2
1
0
0
0
There is no booking allowed before day one, i.e. x1 = 0. By applying this method we can iterate the
solution backward and find W1 function and therefore V1 (x1 ).
The results are shown in Table 7.
17
Project Two
Table 7: Values of V1
W1
x1
0
0
2,152.5
1
2,152.5
u1
2
1,866.75
3
1,866.75
4
1,866.75
V1 (x1 )
u1 (x1 )
1866.75
2,3,4
Now we know that the number of allowed bookings on day 1, is u1 = 2 4, making up the optimal
booking strategy for day 1 with expected cost of 1,866.75 DKK.
When there is one booking allowed after day one, i.e. x2 = 1, the limit on the number of allowed bookings
on day 2 is u2 = 3, with the expected cost of 2,152.5 DKK.
Question 6
The first pilot has got a special offer. He can book one seat in advance (i.e. before day one). It is assumed
that the probabilities from question 1 are valid. Lets now find the optimal strategy for day one.
To find V1 , we use the same method as in question 5. What has changed is that now we have the
additional possibility of having one booking before day one, i.e. x = 0 and x = 1.
The following Table 8 shows the results:
Table 8: Values of V1
W1
x1
0
1
0
2152.5
2152.5
1
2152.5
1771.5
u1
2
1866.75
1771.5
3
1886.75
1771.5
4
1866.75
1771.5
V1 (x1 )
u1 (x1 )
1866.75
1771.5
2,3,4
1,2,3
As before, when there is no seat booked in advance i.e x1 = 0, the limit on the number of allowed bookings
on day one, is u1 = 2 4 with the expected cost of 1,866.75 DKK.
When there is one seat booked in advance i.e. x1 = 1, the limit on the number of allowed bookings is
u1 = 1 3 and expected cost is 1,771.5 DKK.
The company will give the first pilot a discount. Lets calculate how much discount the company will give
the first pilot if the arrangement is to be neutral.
The possible discount is 1, 886.75 1771.5 = 95.25 DKK.
Question 7
The company is considering if it is profitable to make a more precise forecast for t . The (theoretical) best forecast is obtained, when the outcome of the process t is known precisely beforehand (i.e.
full information). If the booking process t is known beforehand overbooking can be avoided. Empty
seat situations can, however, not be avoided, due to the fact that x4 =0, 1 and 2 occurs with certain
probabilities.
Lets now determine an upper limit for the expected benefits from improving the information level.
Because overbooking is avoided as a result of an improved information level the values of V4 for x4 = 46
change to zero as shown in the following Table 9.
18
Project Two
V4
6000
4000
2000
0
0
0
0
As a result, we also get new values for V1 - V3 as can be seen in Tables 10 - 12.
Table 10: The values of V3 with improved information level
x3
0
1
2
3
4
5
6
V3
6000
4600
2900
1200
900
720
600
V2
2052
2052
1626
1626
1626
1626
1626
0
2052
1
2052
u1
2
1796.4
3
1796.4
4
1796.4
V1 (x1 )
u1 (x1 )
1796.4
2,3,4
The new optimal expected cost for day one is V1 = 1, 796.4 DKK for u1 =2, 3 or 4, compared to V1 =
1, 866.75 in Question 5.
The upper limit for the expected benefits from improving the information level is therefore
1, 866.75 1, 796.4 = 70.35 DKK
If the limit of number of bookings is u1 = 0 or 1, the upper limit is:
2, 152.5 2, 052 = 100.5 DKK
19