Title: Ordinary Differential Equations
1Ordinary Differential Equations
Slides borrowed from Ronen Barzel http//www.ense
ignement.polytechnique.fr/profs/informatique/Ronen
.Barzel/
2What is an ODE?
- Ordinary Differential Equation
- Relates value of a function to its derivatives
- Ordinary function of one variable
- Partial Differential Equation (PDE) more
variables
3Standard ODE
- Generic form for first-order ODE
- Note
- typically t is time
- sometimes use Y instead of X, sometimes x instead
of t - names sometimes confusing often
4Why do we care?
- Differential equations describe (almost)
everything in the world - physics
- chemistry
- engineering
- ecology
- economy
- weather
-
- Also useful for animation!
- ODEs are fundamental. PDEs build on ODEs
5Solving differential equations
- Analytic solutions to differential equations
- Many standard forms, e.g.
- But most cant be solved analytically
- 3-body problem
6Numerical solutions to ODEs
- Given a function f(X,t) compute X(t)
- Typically, initial value problems
- Given values X(t0)X0
- Find values X(t) for t gt t0
- Also, boundary value problems, constrained
problems,
7Solving ODEs for animation
- For animation, want a series of values
- samples of the continuous function X(t)
- i.e., frames of an animation
8Path through a field
- f(X,t) is a vector field defined everywhere
- it may change based on t
9Path through a field
- f(X,t) is a vector field defined everywhere
- X(t) is a path through the field
X0
10Higher order ODEs
- E.g., Mechanics has 2nd order ODE (FmA)
- Express as 1st order ODE by defining v(t)
11E.g., for a 3D particle
- We have a 6 dimension ODE problem
12For a collection of 3D particles
13Still, a path through a field
- X(t) maybe path in multi-body phase space
- For ODE, its an array of numbers.
14Intuitive solution take steps
- Current state X
- Examine f(X,t) at (or near) current state
- Take a step to new value of X
- Most solvers do some form of this
15Aside Integral equation
- Note, differential equation
-
- is equivalent to integral equation
16Eulers method
- Simplest and most intuitive.
- Define step size h
- Given X0X(t0), take step
- Piecewise-linear approximation to the curve
17Step size controls accuracy
- Smaller steps more closely follow curve
- For animation, may need to take many small steps
per frame
18Eulers method inaccurate
- Moves along tangent can leave curve, e.g.
- Exact solution is circle
- Eulers spirals outwardno matter how small h
is
19Eulers method unstable
- Exact solution is decaying exponential
- Limited step size
- If k is big, h must be small
20Analysis Taylor series
- Expand exact solution X(t)
- Eulers method approximates
- First-order method Accuracy varies with h
- To get 100x better accuracy need 100x more steps
212nd-order methods
- Midpoint
- ½ Euler step
- evaluate fm
- full step using fm
- Trapezoid
- Euler step
- evaluate f1
- full step using f1
- average (a) and (c)
Midpoint method
22Runge-Kutta method
- Follow same derivation for higher order
- 4th order
- This is what most people use most often
23Adaptive step size
- How do you pick the step size?
- Want large as possible given acceptable error.
- Best step size might change along path
- harder and easier parts of the path
- decrease/increase step size as needed
- Automatic adaptive step size control
24Adaptive step size
- Given h, take step and estimate error
- if error is too large, try again with smaller h
- if error is small, accept step and maybe increase
h - Estimate error compute X(t0h) two ways
- compute Xa by taking one step using h
- compute Xb by taking two steps using h/2
- estimated error err Xa Xb
25Step size for animation
- Want values at regular frame times
- Can make sure not to step past next frame
- OK if h ltlt df
- Can step past frame, then interpolate back
- OK if h df
- Need interpolation anyway when doing collisions
26Is there a solution?
- The function f(X,t) must be smooth
- None of these solvers handle discontinuity
- Adaptive step size may drop to smallest h
- Sometimes desired solution has discontinuity
- Rigid-body collisions have discontinuous v
- ODE solver cant step across discontinuity.
27Which solver to choose?
- Many more kinds of ODE solvers
- predictor-corrector, boundary-value problems,
semi-implicit, differential-algebraic equations,
- Multi-step methods keep history of previous
values - Adaptive-order methods
- For hard problems, need to understand theory
- lots of theory!
- Runge-Kutta (4th order) is a standard workhorse
- Try to avoid stiff equations!
- Often need to experiment and see what works
28For animation
- Dont need to be accurate, just look good.
- Eulers method w/fixed step size
- Always a bad idea.
- Unless it works for you!
29Particle motion
- mass m, position x, velocity v
- equations of motion
- ODE
30Mass-spring systems
- Basically same as a particle system
- Structured, rather than free form
- Mass points part of model
- no generators, no lifetime, no aging
- Use spring forces to connect masses
- all forces no longer apply to all points
- Each force object knows which points it acts on
31Mass spring systems
- Connect points in 1D line
- used for hair, springs, etc
- Connect points in 2D mesh
- used for cloth
- Connect points in 3D lattice
- semi-rigid structures
- used for flesh/muscle motion
- e.g. Jurassic park dinosaurs
32Spring to fixed point
- Basic Hookes-law spring force
- Attracts mass to point x0
- Causes oscillation
33Damped spring
- Spring and dashpot
- like a car suspension
- only damps motion in direction of spring
34Damped spring
- Relationship between ks and kd determines
- underdamping, critical damping, overdamping
- (in isolation)
- Always want some damping.
35Constructions with springs
- connect mass points to make objects
- shapes can kink, shear, or collapse
- add extra supports
- can still be tricky to get desired behavior
36Multiple springs
- Each spring tries to achieve E0
- Competition between multiple forces
- Result is compromise when stable E?0
- To guarantee result, need constraints
37Rigid body state
- Same as points
- m is the total mass
- x is the position of the center of mass
- v is the velocity of the center of mass
- Plus new terms
- I is the rotational inertia tensor (scalar in
2Dmatrix in 3D) - ? is the orientation (angle in 2D messy in 3D)
- ? is the angular velocity (scalar in 2D vector
in 3D) - Body coordinates
- origin at x, orientation ? relative to World
- for any shape, m and I completely describe
response
38Rigid body equation of motion
- Equation of motion has extra terms
- T is torque
39Torque
- Each force f acts at a point on body
- r is vector from center of mass to point of
action - Torque causes body to spin
- if force acts at center of mass, no torque
(gravity) - if force points towards center of mass, torque0
- f at r and f at r give net torque but no net
force
40Collisions
- Collisions between two bodies
- Need point of collision, and normal vector
- many algorithms
- For body-particle collision
- transform to body coordinates
- see if particle is inside body shape
- compute collision normal in body coordinates
- compute relative velocity in body coordinates
- compute impulse in body coordinates
- transform back to world and apply
41Whats a constraint?
- A restriction on the position of a body
- A relationship between one or more bodies
- Permanent constraints
- holonomic expressed by equation C()0
- Joints between bodies
- Transient constraints
- nonholonomic expressed by equation C()?0
- contact
- joint limits
42Constraint forces
- First compute non-constraint forces
- gravity, springs, etc
- Then compute force due to constraint
- takes into account effect of non-constraint
forces. - Can have multiple constraints
- each constraint must take into account the others
- simultaneous equation
- Add constraint forces to non-constraint forces
- Simulate normally.