Title: Slope Fields and Numerical Solutions
1Slope Fields and Numerical Solutions
2First-Order Differential Equations
- Form of DE 1st order
- Ideal goal find functions y(t) that satisfy the
differential equation - Last class slope fields give rough shape of
curves - Can we connect the dots to make a curve?
3Temperature Example
- Return to heating and cooling example
- Look at particular k, Te values
4Slope Field
5Wait isn't this easy???
6Continued
Always check your answer against the original DE!
7Modeling
- Writing down model DEs can be almost trivial is
some cases - See some assignment problems
- Solving those same DEs to find an exact formula
for y(t) prediction can be difficult or
impossible (no closed form) - Today, we find numerical approximations to the
exact y(t) functions
8Back to Slope Fields
- Slope fields give us an idea for a computer-based
approximation strategy - Computer can compute slopes at any (t,y)
- Why not approximate curved solution by straight
line segments, based on calculated slopes?
9Euler's method
- Pick starting point, (t, y), and step size, delta
x - Find slope there
- sub (t, y) into dy/dt formula
- Follow that slope for delta x
- Treat new point as new starting point
- Repeat
10Graphically
11Slope Field vs Estimated Curve
- Both use dy/dt . formula
- For slope field, compute slopes on a grid to see
overall shape of solution family - For Euler's method, compute slopes only along a
path to estimate a particular solution
12Euler's method limitations
- Accuracy of estimate depends on step size
- smaller steps means more accurate
- but longer to compute
- Euler's method needs very small steps to be
accurate - Can be generalized to more efficient algorithms
- Runge-Kutta (Section 2.6)
- We'll jump straight to the good stuff!
13Adaptive Runge-Kutta Solvers
- MATLAB has many built in ODE 'solvers'
- don't give formulas, just give a predicted curve
based on DE and a starting point - predicted solution still has numerical errors in
addition to any assumptions, simplifications in
model - We'll use ode45 (general-purpose solver)
14Using ode45
- You need
- a function that represents the f(t,y) in
- an initial y value, y0 where you'll start the
solution - an interval of time you want to predict over,
t0, tn - an error tolerance you'll accept in the estimated
final y value, y(tn)
15Example
y0 30 t0 0 tn 48 Define the function
dy/dt f _at_(t, y) -0.05(y5) run the
solver to generate approximate temperature
curve t, y ode45(f, t0, tn, y0, 1e-5)
the actual predicted points, and lines connecting
them plot(t, y, '.-k', 'markersize',
15) title('ODE 45 Prediction for Temp DE')
16Graph over Slope Field
17Numerical Solutions (the good)
- Single solution curve is easy to generate
- relatively simple MATLAB coding required
- syntax is very picky don't expect to guess at it
and have it work - Can generate multiple curves by looping over
different starting points - We'll see how same approach works with more than
just single 1st order DEs
18Numerical Solutions (the not so good)
- Solution found is not general
- can only pick one starting point, not find
general family of solutions - Solution is not a function
- it's a list of points that approximate the
function - can't take limits, derivatives, modify
parameters - Still, numerical solutions are
- relatively easy to generate
- way better than nothing
19Before next week
- Try that solving technique on some of the DEs you
create in the assignment, to see if - can generalize MATLAB to other examples
- predictions make sense in the problem
- creating DEs is easy
- numerical solving is easy (with MATLAB), but
limited - Rest of the course solving analytically