02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.5 Ordinary Differential Equations<br />

167<br />

2. isterminal: a. vector of ones and zeros specifying whether occurrence<br />

of an event is terminal (stops the solution) or not. For each element in<br />

the vector value, a 0 or a 1 is required in the vector isterminal. In our<br />

example, we have only one clement in value (x(3) or y), therefore, we<br />

need just one element in ist erminal. Because we would like to stop the<br />

program at y = 0, the zero crossing of y is terminal. Therefore, we set<br />

isterminal=l.<br />

3. direction: a vector of the same length as value, specifying the direction<br />

of zero crossing for each element in value: a. -1 for negative value, a<br />

1 for positive value, and a 0 for I- don'l-care value. In our example,<br />

direction=-1 will imply that the zero crossing of y is a valid event only<br />

when the value of y is decreasing (y crosses zero with iJ < 0). As you<br />

can see, specification of direction prevents the solver from aborting the<br />

solution at the outset when y = 0 but iJ f:. 0.<br />

Of course, your function should provide the event information, in terms of<br />

these three vectors as output, but only when asked. Thus, your function<br />

should check the value of the flag and output the three vectors if the flag<br />

is set to events, otherwise it should output the usual derivative vector xdot.<br />

We can implement this conditional output using switch (you can do it using<br />

if-elseif construction too) , as shown in the following example function.<br />

function [value ,isterminal ,dircn] = proj (t ,z,flag) ;<br />

% PROJ : ODE for proj ectile motion with event detection<br />

g = 9.81;<br />

% specify constant g<br />

if nargin

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

Saved successfully!

Ooh no, something went wrong!