Baseball trajectory with drag and wind
Afficher commentaires plus anciens
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];
end
(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 commentaire
Image Analyst
le 28 Juin 2020
I don't see a specific question, but perhaps this will help: debugging in MATLAB
Réponses (1)
John D'Errico
le 29 Juin 2020
0 votes
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.
Catégories
En savoir plus sur Assembly dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!