02.03.2016 Views

MATLAB by rudra pratap

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.5 Ordinary Differential Equations<br />

165<br />

5.5.6 Event location<br />

In solving initial value problems, usually the termination condition is specified in<br />

terms of the independent variable. As shown in the previous Lwo examples, the<br />

solution stops when the independent variable t reaches a prescribed value tfinal<br />

(specified as the second element of tspan). Thus, we obtain the solution for a<br />

certain time span. Sometimes, however, we need to stop the solution at a specified<br />

value of the dependent variable and we do not know when (at what value of t) the<br />

solution will reach there. For example, say we want to solve a projectile problem.<br />

We write the equations of motion (two ODEs for x and y), and we would like<br />

to solve the equations to find when the projectile hits the target. If we do not<br />

know tfinal apriori, what value of tfinal should we specify in tspan? One thing<br />

we know is that the solution should stop when the target (some specified location<br />

Xtarget or Ytarget) is hit, that is, when x or y reach a particular value. When the<br />

dependent variables (here x(t) or y(t)) reach some specified value, we call that an<br />

event, and the problem of finding the time of the event is called event location. Event<br />

location problems are solved <strong>by</strong> following the solution until the solution crosses the<br />

event, then backtracking to the time just before the event, and then taking smaller<br />

and suitably computed time steps to land exactly at the event. There are several<br />

strategies and algorithms for event location. In the literature, the event location<br />

problem is also referred to as integmting across discontinuities.<br />

Fortunately, the ODE solvers in <strong>MATLAB</strong> have built-in ability to solve event<br />

location problems. Let us take a simple example-a projectile is thrown with initial<br />

speed Vo at an angle e. We want to find out (i) the instant when the projectile<br />

hits the ground, (ii) the range, and (iii) the trajectory of the projectile. The ODEs<br />

governing the motion of the projectile are<br />

x 0<br />

ii -g<br />

The initial conditions are x(O) = y(O) = 0, x(O) = v0 cos (}, and y(O) = v0 sin 8.<br />

The equations of motion are to be integrated until y = 0 (the projectile hits the<br />

ground).<br />

Before we write a function to code our equations, we need to convert them into<br />

a set of first-order equations:<br />

Let x = x1,x = x2,Y = X;>, and y= X4, then x1 = x2,x2(= i) = O,::i:3 = X1 , and<br />

x4(= jj) = -g. In vector form:<br />

(5.5)<br />

Now, eqn. (5.5) is ready for coding in a function.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!