15.11.2014 Views

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Initial Value Problems for ODEs and DAEs<br />

The equations for the bouncing ball are<br />

y′ 1 = y 2<br />

y′ 2 = – 9.8<br />

In this example, the event function is coded in a subfunction events<br />

[value,isterminal,direction] = events(t,y)<br />

which returns<br />

• A value <strong>of</strong> the event function<br />

• The information whether or not the integration should stop when value = 0<br />

(isterminal = 1 or 0, respectively)<br />

• The desired directionality <strong>of</strong> the zero crossings:<br />

-1 Detect zero crossings in the negative direction only<br />

0 Detect all zero crossings<br />

1 Detect zero crossings in the positive direction only<br />

The length <strong>of</strong> value, isterminal, and direction is the same as the number <strong>of</strong><br />

event functions. The ith element <strong>of</strong> each vector, corresponds to the ith event<br />

function. For an example <strong>of</strong> more advanced event location, see orbitode<br />

(“Example: Advanced Event Location” on page 5-32).<br />

In ballode, setting the Events property to @events causes the solver to stop the<br />

integration (isterminal = 1) when the ball hits the ground (the height y(1) is<br />

0) during its fall (direction = -1). The example then restarts the integration<br />

with initial conditions corresponding to a ball that bounced.<br />

To run this example, click on the example name, or type ballode at the<br />

command line.<br />

function ballode<br />

%BALLODE Run a demo <strong>of</strong> a bouncing ball.<br />

tstart = 0;<br />

tfinal = 30;<br />

y0 = [0; 20];<br />

5-29

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

Saved successfully!

Ooh no, something went wrong!