Motivation: I am trying to learn how to use ode45 for fun after studying some math (because it seems engineering eventually makes you forget math and because I didn't have access to matlab in college many years ago).
Question: Given a differential equation with a discontinuity such as y'=y^2 at initial condition y(0)=3, how can I use ODE45 to approximate the solution before and after the discontinuity? I am able to get the right answer by restarting the integration at the discontunity with a new initial condition, but this requires me to know what the discontinuity looks (is it +inf or -inf taking the right hand limit)? Is there a way to use ODE45 that does not require this knowledge of the exact solution?
solution=ode45(f,[0,1/3],3);
plot(solution.x,solution.y); hold on
solution2=ode45(f,[1/3,10],-1000000);
plot(solution2.x,solution2.y); hold on
t=[t_l;transpose(t_l(end)+eps:0.1:10)];