Tutorial 8: Numerical Methods Writing higher-order ODEs as a first-order system 1. Write the following ODEs as first-order systems. (a) θ ′′ + g L sin θ = 0 (Pendulum). (b) y ′′ − µ(1 − y 2 )y ′ + y = 0, µ > 0 constant (Van der Pol oscillator). 2 d y dy 2 2 (c) x2 dx 2 + x dx + (x − ν )y = 0, ν ∈ R (Bessel equation). Euler’s Method To approximate the solution to y ′ = f (t, y), y(t0 ) = y0 , Euler’s method approximates the solution y(t) by y(tn ) with tn = t0 + nh and y0 = y(t0 ), yn+1 = yn + hf (tn , yn ). 2. Set up the recursion formulas for Euler’s method for each system found above with the specified initial condition. (a) θ ′′ + g L sin θ = 0, θ(0) = 0, θ ′ (0) = 1. (b) y ′′ − µ(1 − y 2 )y ′ + y = 0, y(0) = 2, y ′ (0) = 1. 1 2 dy d y 2 2 ′ (c) x2 dx 2 + x dx + (x − ν )y = 0, y(0) = 1, y (0) = 0. 3. The first iterate of Euler’s method for y ′ = y, y(0) = 1 and x′ = x(1 − x), x(0) = 0.8 are plotted below with h = 0.5. Complete the sketches (no calculations needed). 8 1 Euler Exact 4 x y 6 0.9 Euler Exact 2 0 0.8 0 0.5 1 t 1.5 2 0 0.5 1 t 1.5 2 (a) What can you conclude about the error in Euler’s method when the solution is concave up or concave down? Do you over- or under-estimate the solution? (b) How does the Improved Euler method address this issue? Computer time 1. Use Matlab (or similar) to implement Euler’s method for y ′ = −10y, y(0) = 1. What happens for different choices of the time step h? 2. Use Matlab (or similar) to implement Euler’s method for y ′′ − µ(1 − y 2 )y ′ + y = 0, y(0) = 2, y ′ (0) = 1. What happens for different choices of the time step h? What happens for different choices of µ? Try µ = 1 and µ = 100. 3. If you’re annoyed with how unstable Euler’s method is, try the Backward Euler Method. For an ODE y ′ = f (t, y), y(t0 ) = y0 , the Backward Euler Method computes approximations using y0 = y(t0 ), yn+1 = yn + hf (tn+1 , yn+1 ). That is, during each time step, the (possibly nonlinear) equation yn+1 − hf (tn+1 , yn+1 ) = yn must be solved for yn+1 . Do you know a method that you can use to solve nonlinear equations? 2