Assignment title: Information


Question MZB126 Semester

Q Over the last few weeks we have been investigating different techniques for solving differential equations, and for writing algorithms in MATLAB. This week we will

finally combine the two, and talk about numerical solution methods for ODEs. The most basic numerical method for solving first-order ODEs is Euler's Method. If we take the ODE: y0 = f(t; y); Euler's Method has the form: y(t + h)  y(t) + hf(t; y(t)):

In other words, it uses the derivative of y (which is f(t; y)) to approximate how much

it will change over a distance h. For example, if we take the ODE:

y0 = 2yt; y(1) = 1; we can approximate y(1:5) by: y(1:5)  y(1) + 0:5  (2y(1)  1):

y(1:5)  1 + 0:5  2  2: We can use this process to repeatedly 'step' our solution forward in time, getting a solution to the ODE. In the ODE above calculate y(2) using Euler's Method with h = 0:5:

Discuss  What happens to this approximation as h gets smaller?

 What is the trade-off on using a smaller h?

ODE45

While it is important to understand how numerical methods work, in application we rarely write our own. In MATLAB, a commonly used ODE solver is called ODE45. ODE45 using the syntax:

Numerical Solvers and ODE Systems MZB126 Semester 1 2015 Workshop 6 [tout; yout] = ode45(@func; [StartTime; EndTime]; y0);

The outputs from this are a vector of the solution yout and a vector of the times tout that the solution was generated at. func is a function file, that takes inputs t; y (in that order) and returns the RHS function f(y; t). The@symbol is a function handle, that allows the function to be called

by ode45 Questions

 Implement the solution for the ODE from the previous question into ODE45. Systems of ODEs One application of numerical solvers is to investigate systems of ODEs. These

can appear naturally in systems with many linked variables. A good example of this is in electrical circuits. There are five basic rules in electrical circuits which link the behaviour of voltage (V ), current (I), resistance (R), capacitance (C) and inductance (L). They are:

 Over a resistor: V = IR (Ohm's Law)  Over an inductor: V = LdI

dt  Over a capacitor: C dV dt = I

 Over the whole system: Pn i=1 Vi = 0 (Kirchoff's Voltage Law)  Across any point in the system:

P Ij = 0 (Kirchoff's Current Law) We use these laws to build up equations for calculating unknown voltages and currents within a circuit. Consider the system in figure 1. From Kirchoff's current and voltage laws we have: Vin(t) = V1(t) + V2(t) + V3(t); Numerical Solvers and ODE Systems

MZB126 Semester 1 2015 Workshop 6 Figure 1: A three component circuit I1(t) = I2(t) = I3(t): Now we consider each component in the system separately. Across the resistor: V1(t) = I1(t)R: Across the capacitor:

C

dV2 dt = I2; and finally across the inductor: V3 = L dI3 dt : By making rearrangments, we can reduce these into two ODEs for V2 and I3 (the only two variables with derivatives in the above equations). Doing this we arrive at: dV2

dt = 1

C I3; dI3 dt =

1 L (Vin(t) 􀀀 RI3(t) 􀀀 V2(t)) :

This is a system of two ODEs. For initial conditions we can assume V2(0) = I3(0) = 0. This is the same as assuming the capacitor starts with no charge, and that the system is only switched on at t = 0.

Numerical Solvers and ODE Systems MZB126 Semester 1 2015 Workshop 6 Figure 2: A four component circuit.

Questions

 Solve this ODE with ode45, using R = 3, L = 4, Vin = 12, C = 2. Discuss  What is the long term behaviour of the system? What do V2 and I3 tend to as t gets large?

 For a variable input Vin(t) what should the voltage V2 tend to over long time? Assessment  Consider the electrical circuit in figure 2. Derive the ODE that results from

this system.  Solve the system using ode45, with no initial current, and an uncharged capacitor.  For Vin = 12e􀀀0:5t volts, produce plots of the current in the system and voltage across the capacitor.