Title: Lecture 14: Calculus based techniques
1Lecture 14Calculus based techniques
- COMP155Computer Simulation
- November 3, 2008
-
2Basic Concepts of Calculus
- Derivative rate of change of a function
- Integral area under the curve of a function
3Derivative is the slope
Image from http//en.wikipedia.org/wiki/Derivative
4Example velocity and acceleration
- This curve represents velocity over time.What
does acceleration look like?
5Acceleration is slope of velocity
- Velocity is blue, acceleration is red
6Example 2 Velocity
7Example 2
- Velocity is blue, acceleration is red
8Example 3
- Green curve is distance, what is velocity?
9Example 3
- Green is position, blue is velocity
10Example 3
- What is happening to green curve when blue curve
crosses zero?
The derivative is zero when function is at a
local minimum or maximum
11Example 3
- Position (green), velocity (blue), acceleration
(red)
12Integral is the area
Image from http//en.wikipedia.org/wiki/Integral
13Example Integration
- Velocity is blue, acceleration is red
14Example Integration
- Red line is acceleration, what is velocity?
15Integration Requires Init Values
- Accumulated area gives shape, initial conditions
locate shape
These are both correct velocity curves, for
given acceleration curve
16Example 2 Integration
- position at t0 is 100,position at t25 is
150What is position at t50?
17Example 2 Integration
- position at t0 is 100,position at t25 is
150What is position at t50?
answer 200
This area must be 50.
This area is also 50.
18Fundamental Theorem of Calculus
- f is a continuous real-valued function defined on
a closed interval a, b, - F is an anti-derivative of f
- F f,
- the definite integral of f over that interval is
given by - differentiation is the reverse of integration
19Fundamental Theorem of Calculus
Whatever the shape of the velocity curve, we can
determine its area in some interval from the
position values at the ends of that
interval. green position blue velocity
20Calculus in Simulation
- Well commonly have a derivative of some
function(or instantaneous values of the
derivate)and need to construct values for the
function - Example We know velocity, need to compute
position - Example We know acceleration, need to compute
velocity and position
21Time Slicing
- Simulation is updated at regular interval in time
- dt time step/slice
- To approximate integration
- compute derivative at time steps
- make assumption about derivative value at other
times - accumulate area to approximate integration
22Time slice approximation
- dt 1, assume current value held for previous
time slice
blue correct derivative functionred
approximated derivative function
over-estimate of positive area
under-estimate of positive area
under-estimate of negative area
over-estimate of negative area
23Time slice approximation
dt 1 green correct positionred
approximated position
24Time slice approximation
dt 1 green correct positionred
approximated position
25Smaller dt ? better approximation
dt 1
dt 0.5
dt 0.1
dt 0.01
26Smaller dt ? better approximation
This is similar to the limit in the definition of
a derivative The time slice is h.As it
gets smaller, we get closer to the true value
of the derivative.
dt 1
dt 0.1
27Time slice approximation
Weve rewritten to get (actually, were
using)
dt 1
dt 0.1
28Eulers Method
- Taylor Seriesas dt ? 0, the higher order
terms quickly approach 0, giving our
approximation - The higher order terms are the error in the
approximation
29Instantaneous Derivative Values
- In interactive simulations, we often do not have
a function for the derivative, rather we have
instantaneous values for the derivative - Example driving simulationacceleration value is
set by drivers joystick - Eulers method can still be applied (twice)to
compute velocity and position - assume that current value of acceleration was
constant through previous time step
30Example Vehicle Dynamics
- Acceleration is set by user
- Function updates velocity, then position
void Vehicleupdate(double elapsed_time)
double dt elapsed_time/1000.0 velocity
accelerationdt double vx velocitysin(headin
g) double vy velocitycos(heading) double
x position.getX() vxdt double y
position.getY() vydt position.moveTo(Point(x
,y))