联系我们: 手动添加方式: 微信>添加朋友>企业微信联系人>13262280223 或者 QQ: 1483266981
MTHM607 – Computational Modelling and Simulation
Optimisation Worksheet
1. In class we showed that the curve passing through two points (a, A) and b, B), producing a volume of revolution
(a.k.a. “bubble”) with the minimum surface area, is the catenary
y(x) = k cosh _x0012_ x + c
k
where the constants k and c must be found to match the boundary conditions
y(a) = A, y(b) = B.
Without loss of generality (by scaling and translating), we assume a = A = 1.
b > 1 and B > 0 will be variables in the following.
(a) Create computer code to find k and c for arbitrary given b and B.
(b) Explore what happens as b and/or B increase.
(c) Create an animated video showing the change in the bubble as b and/or B vary.
Relevant MATLAB functions: syms, vpasolve, cylinder, surf.
2. The deflection y(x) of a beam of length 1, clamped at both ends so that y(0) = 0, y(1) = 0, is an extremum
of the cost
I(y) = Z
0
1
p(x)y
0 (x)
2 + q(x)y(x)
2 2f (x)y(x)dx . (1)
Here q(x) is the cross-section of the beam, whilst p(x) and f (x) are applied stresses, and the cost penalises beam
deflections (y(x) functions) with high values of either y(x) or y
0 (x).
In this case, the Euler-Lagrange equation
F
y
d
dx _x0012_
y
F
0
= 0 (2)
becomes
d
dx p(x)
dy
dx + q(x)y = f (x) y(0) = y(1) = 0 . (3)
The second order equation (3) is a two point boundary value problem. So we cannot use finite-difference schemes
such as Runge-Kutta (not without some complicated “shooting method” approach). Instead we exploit the fact
that the solution we are seeking is an extremum of (1) and then look directly for approximate extrema 1
.
We consider a set of “basis functions”
{φi
, i = 1, … , n} satisfying φi(0) = φi(1) = 0, i = 1, … n .
and seek an approximate extremum
φ(x) =
nX
i=1
ciφi(x) (4)
by choosing the constants c1, … , cn so that I(φ) is minimised.
1For more information about the numerical solution of boundary value problems see ‘the excellent book by Burden and Faires’
(sung to the tune of ‘Scarborough Fair’)
1
(a) Show that φ(x) given by (4) is an extremum of I(φ) if
nX
j=1
Z 0
1
_xfffe_
p(x)φ
0i
(x)φ
0j
(x) + q(x)φi(x)φj(x)
dx cj =
Z
0
1
f (x)φi(x)dx, i = 1, … n . (5)
(b) The system of equations (5), by which the approximation is found, can be written in matrix-vector form as
finding c = [c1, … , cn]
T so that
Ac = b (6)
where
A = (aij), aij =
R 0
1
p(x)φ
0i
(x)φ
0j
(x) + q(x)φi(x)φj(x)
dx
b = [b1, … , bn]
T
, bi =
R 0
1
f (x)φi(x)dx
(7)
Find A and b in the case where the basis functions are “hat functions” described as follows:
First partition the interval [0, 1] according to
0 = x0 < x1 < ... < xn < xn+1 = 1
Next let hi = xi+1 xi
, i = 0, ... , n and define the hat-like basis functions by
φi(x) =
0 0 ≤ x ≤ xi 1,
(x xi 1)
hi 1
, xi 1 < x ≤ xi
,
(xi+1 x)
hi
, xi < x ≤ xi+1,
0, xi+1 < x ≤ 1 .
(8)
In this case:
φ
0i
(x) =
0 0 < x < xi 1,
1
hi 1
, xi 1 < x < xi
,
1
hi
, xi < x < xi+1,
0, xi+1 < x < 1 .
where we note that the hat-functions are not smooth at the partition points x1, ... , xn. But this does
not affect the integration calculations2
.
(c) Set up A and b in matlab in the case
p(x) = x, q(x) = 4, f (x) = 4x
2 8x + 1
with the partition x0 = 0, x1 = 0.2, x2 = 0.4, x3 = 0.6, x4 = 0.8 and x5 = 1 , and so find a piecewise linear
approximate solution of the second order differential equation
xy00 y
0 + 4y = 4x
2 8x + 1, 0 ≤ x ≤ 1, y(0) = y(1) = 0.
2We are not worried about the lack of smoothness of these hat functions because we can round off their corners with only negligible
impact on the calculations which will actually disappear as the rounding “goes to zero” – But please ask me about this if you need
reassurance!
2
3. Re-work the approach above but using cubic splines in place of the piecewise linear “hat functions”. This task
is deliberately left open. You need to
Read about cubic splines and adapt their usage to this type of variational problem;
Sep up the φi(x) as cubic splines that vanish outside an interval – like we did with the hat functions in Q2;
Create the corresponding A and b.
4. The differential equation
y
00 xy + (1 + x) sin(x), y(0) = y(π) = 0 , (9)
results from finding the extrema of
J(y) = Z
0
π
y
0 (x)
2 + xy(x)
2 2(1 + x) sin(x)y(x)dx, y(0) = y(π) = 0 .
As in Q2 we will find approximate solutions of the differential equation by finding approximations of the extrema.
This time we look for polynomial approximations
a0 + a1x + ... + anx
n
.
(a) Show that to satisfy the boundary conditions we can assume basis functions of the form
φi(x) = x(x π) x
(i 1)
, i = 1, 2, ... .
(b) Use symbolic computation in matlab to find A and b as given by (7) above for arbitrary order of approx imation (obviously for these polynomial basis functions, not the hat functions of Q2).
(c) Create a matlab script that, for a given n, finds a polynomial approximation yP(x):
yP(x) =
nX
i=1
ciφi(x) .
of the solution to the differential equation by solving the equation Ac = b for the coefficients c1, c2, ....
(d) Show that y(x) = sin(x) is the solution of the differential equation in (9) satisfying the given boundary
conditions.
(e) Use matlab to plot the exact solution and polynomial approximations of degrees 3, 5, 7, 9 and 11. Compare
these polynomial approximations to the standard Taylor polynomial approximations of sin(x) of degree
3, 5, 7, 9 and 11, i.e.
x
x
3
3! +
x
5
5! + ... + ( 1)m 1
x
2m 1
(2m 1)! ,
for m = 2, 3, 4, 5, 6 .
5. Time optimal control of the simple harmonic oscillator
y¨(t) + y(t) = u(t), |u(t)| ≤ 1 (10)
results in a so-called bang-bang control. The solution is characterised by a switching surface on which the control
switches between u = +1 and u = 1. Using Pontryagin’s Maximum principle, we argued that the switching
surface takes the form a “Loch Ness Monster”-like shape as depicted in Figure 1.
Task: Write matlab code to construct the parts of the switching surface corresponding to controls which switch
either once or twice.
Hints:
3
Figure 1: The switching surface for time optimal control of a harmonic oscillator.
From symmetry, we only need to find either the left (y ≤ 0) or the right (y ≥ 0) part. So focus on the left
part.
For one switch (from 1 to +1), focus on initial (y(0), ˙y(0)) on the red semi circle. For two switches
(from 1 to +1 and back to 1), focus on initial (y(0), ˙y(0)) on the blue semi circle.
In either case, think about how the optimal trajectory can end at (0, 0). This should involve piecing together
circular arcs centred on ( 1, 0) and (1, 0).
Turn this idea in to an algorithm which finds the optimal switching times and therefore also the correspond ing parts of the switching surface.
6. The damped harmonic oscillator
y¨(t) + ay˙(t) + by(t) = u(t)
is a model for the motion of a unit mass attached to a linear spring (with spring constant b), subject to damping
(with damping coefficient a) and under the influence of an applied force u(t).
The force has a maximum magnitude of 1 so that
|u(t)| ≤ 1, for all t ≥ 0 .
For given initial displacement y(0) and velocity ˙y(0), we seek the forcing function u(t) which drives the mass
to rest at y = 0 in minimum time. According to Pontryagin’s Maximum Principle, the time-optimal forcing
u(t) takes only values of +1 or 1 with the sign of u(t) matching that of the time-reversed complementary
function of the homogenous problem
¨w(t) + a ˙w(t) + bw(t) = 0 .
Task: Write matlab code to find the switching surface for the optimal control.
Hint: You will need to distinguish between different cases according to whether the auxilliary equation
s
2 + as + b = 0
has real or complex solutions.
4


发表回复