38
MONTE
CARLO
AND
GRID-BASED
TECHNIQUES
FOR
STOCHASTIC
SIMULATION
145
38
Monte
Carlo
and
Grid-Based
Techniques
for
Stochas
tic
Simulation
In
this
problem
you
will
compare
the
performance
of
random
vs.
regular
sampling
on
a
speciﬁc
stochastic
dynamics
problem.
Thesystemweare
cons
ider
ing
is
a
s
imple
rotary
mass,
controlled
by
a
motor:
Jφ
¨
=
τ
=
k
t
i,
where
J
is
the
mass
moment
of
inertia,
φ
is
its
angular
position,
τ
is
the
control
torque,
k
t
is
the
torque
constant
of
the
motor,
and
i
is
the
electrical
current
applied.
While
this
is
a
simple
control
design
problem
for
given
values
of
J
and
k
t
,
the
situation
we
study
here
is
when
these
are
each
only
known
within
a
range
of
values.
In
particular,
J
is
described
as
a
uniform
random
variable
in
the
range
[5
,
15]
kg
·
m
2
,and
k
t
is
a
uniform
random
variable
in
the
range
[4
,
6]
Nm/A
.
The
basic
question
we
ask
is:
if
the
control
system
is
designed
for
a
nominal
condition,
say
J
=10
kg
·
m
2
and
k
t
=5
Nm/A
,
how
will
the
closed-loop
system
vary
in
its
response,
for
all
the
possible
J
and
k
t
?
This
is
a
question
of
stochastic
simulation,
that
is,
ﬁnding
the
statistics
of
a
function
output,
given
the
statistics
of
its
input.
The
code
fragment
provided
below
applies
Monte
Carlo
and
grid-based
approaches
to
ﬁnd
the
mean
and
variance
of
the
function
cos(
y
),
when
y
is
uniformly
distributed
in
the
range
[2
,
5].
Try
running
this
a
few
times
and
notice
the
eﬀects
of
changing
N
.
The
grid-based
approach
is
clearly
giving
a
good
result
with
far
less
work
than
MC
- for
this
example
with
only
one
random
dimension.
In
general,
the
grid-based
methods
suﬀer
greatly
as
the
d
dimension
increases;
for
trapezoidal
integration,
the
error
goes
as
1
/N
2
/d
,
whereas
for
Monte
Carlo
it
is
simply
1
/N
1
/
2
for
any
d
!
1.
For
the
nominal
system
model
(as
above)
design
a
proportional-derivative
controller
so
that
the
closed-loop
step
response
reaches
the
commanded
angle
for
the
ﬁrst
time
in
about
one
second
and
the
maximum
overshoot
is
twenty
percent.
The
closed-loop
system
equation
is
Jφ
¨
=
k
t
(
−
k
p
(
φ
−
φ
desired
)
−
k
d
φ
˙
)
−→
Jφ
¨
+
k
t
k
d
φ
˙
+
k
t
k
p
φ
=
k
t
k
p
φ
desired
.
Remember
that
if
you
write
the
left-hand
side
of
the
equation
as
φ
¨
+2
ζω
n
+
ω
n
2
,you
can
tune
this
up
quite
easily
because
the
overshoot
scales
directly
with
damping
ratio
ζ
,
and
you
can
then
adjust
ω
n
to
get
the
right
rise
time.
Show
a
plot
of
the
step
response
and
list
your
two
gains
k
p
and
k