MATLAB Answers

Baseball trajectory with drag and wind

3 views (last 30 days)
david johnson
david johnson on 28 Jun 2020
Answered: John D'Errico on 29 Jun 2020
I am working on modelling the trajectory of a baseball considering the drag from the velocity of the baseball, as well as a headwind. I have the following to setup my ode function:
function dudt = wind(~,u)
vx = u(3);
vy = u(4);
vmag = sqrt((vwind - vx)^2+vy^2);
dudt = [vx;vy;-dr*vmag*(vwind-vx);-g - dr*vmag*vy];
(dr, vwind, g are constants)
and to solve
[times,solnw] = ode45(@wind,[tstart,tstop],u0);
I get the following error:
Warning: Failure at t=1.959253e+00. Unable to meet integration tolerances without reducing the step size below the smallest value
allowed (3.552714e-15) at time t.
My equations seem to be correct wrt my model but I'm sure I am doing something wrong with vy for it to be breaking.
Thanks for the help.

  1 Comment

Image Analyst
Image Analyst on 28 Jun 2020
I don't see a specific question, but perhaps this will help: debugging in MATLAB

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 29 Jun 2020
This is almost a classical problem, and the reason stiff ODE solvers were provided. Essentially, when you get that error using ODE45, the problem is probably stiff. You can do some reading here:
The stiff ODE solvers in MATLAB are ode15s and ode23s. Hint: The last character in the name is s. :)
Call it the same way as you did ode45, just change the name.


Sign in to comment.

Translated by