File Exchange

image thumbnail

Bouncing-Ball: Tutorial for ode45 events.

version (104 KB) by Matthew Kelly
Tutorial for event detection in Matlab - simulation of ball bouncing over hilly terrain.


Updated 22 Aug 2017

From GitHub

View Version History

View license on GitHub

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Simulation of a ball bouncing over hilly terrain in 2D. Designed as a tutorial for event detection in Matlab.

Cite As

Matthew Kelly (2021). Bouncing-Ball: Tutorial for ode45 events. (, GitHub. Retrieved .

Comments and Ratings (7)

E. Cheynet

Matthew Kelly

Hi Mohamed, the code for the interactive graphics was written by Jira Doke at Mathworks, which he provides in the comments on the bottom of Pick of the Week page:

Mohamed Moselhy

Is it possible to send me the updated code with the interactive part demonstrated in the video here

My email is
Thank you, much appreciated!

Matthew Kelly

Thanks! I made the ground a set of smooth analytic functions so that the root-solving in the event detection would behave nicely, and so I didn't have to worry about the domain of the function. That being said, as long as ground height is a valid smooth function it the code should run fine.

I could imagine a new implementation of the groundHeight() function that uses a cubic spline to interpolate a set of discrete data, rather than using sine waves. I don't have time to code it up now, but I'm happy to look at pull requests to the GitHub repo if you end up adding that feature.


Excellent! Why not update the function 'groundHeight' so that you can deal with discrete data of ground?(I'm looking forward to an 'interpolation' of every kind of ground :D).

LY Cao

Matthew Sheen

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!