Problem 42891. Differential equation and events
You have to solve the non-linear time variant differential equation:
(cos(y)+2)*y''+atan(y)*sin(0.01*t)^2+y*sin(0.5*t)=0
with initial condition as input of the function
[y(0);y'(0)]=[a,b]
and return the time 'te' when 'y' crosses zero from the negatives values to the positive values.
te=zero_crossing(a,b)
tip: use the 'Events' option in odeset to detect the crossing, stop integration and get the time 'te'. See how to use it here : http://www.mathworks.com/help/matlab/math/ode-event-location.html?searchHighlight=ballode
Additional info:
- in the test case, the solver ode45 is used, with options 'RelTol'=1e-8 and 'AbsTol'=1e-10.
- because you don't know in advance the final time of the crossing, you can solve again further in time if no crossing is detected, starting from the point of the final time of previous integration.
Solution Stats
Problem Comments
-
2 Comments
Tim
on 14 Jun 2016
It looks like [y;y']=[a,b] would mean y(0)=a and y'(0)=b, but a first order differential equation should have one initial condition y(t0)=y0.
hubert andre
on 14 Jun 2016
Thanks Tim, yes, I did a mistake in the equation, its a 2nd order.
Solution Comments
Show commentsGroup

The Prime Directive
- 14 Problems
- 36 Finishers
- Find the nearest prime number
- Extra safe primes
- Prime factor digits
- Twin Primes
- Twins in a Window
- The Goldbach Conjecture
- The Goldbach Conjecture, Part 2
- Goldbach's marginal conjecture - Write integer as sum of three primes
- Sophie Germain prime
- Mersenne Primes vs. All Primes
- Circular Primes (based on Project Euler, problem 35)
- Numbers spiral diagonals (Part 2)
- Pernicious Anniversary Problem
- Prime Ladders
Problem Recent Solvers18
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!