Simulating Projectile with Matlab
22 views (last 30 days)
I have a school project where I have to simulate free fall for a basketball from a height of 20m
I have done all the work but when I tried to solve the problem without air resistance (s = (v0 + at ^ 2) / 2) I get that (t =1.3). witch means that the time for the simulation with air resistance is less than the time without air resistance. I dont make sense so I think I have done something wrong with my program but I cant find it. would appreciate the help
James Tursa on 18 Mar 2022
Edited: James Tursa on 18 Mar 2022
You don't show us both methods (with and without drag) so we can't compare them. I presume you simply set k=0 for the case without drag? That being said, consider these lines:
t=(0:N-1)*deltat; % <-- move this out of the loop. It doesn't belong inside the loop.
d=V(i+1)*t + 0.5*a*t.*t % 8 is the starting height
We don't know what your assignment instructions are, but the velocity update you have is an Euler update. If you are supposed to code up Euler, then I would have expected the position update to look similar, e.g. something like this instead of what you have:
And you would start d(1) at some appropriate initial height prior to loop entry. E.g.,
d=zeros(1,N); % Position
As an aside, note that your drag equation only works if the object is always falling down. If it could be going up (e.g., tossed into the air) then the V(i)^2 would have to be replaced with abs(V(i))*V(i). I.e., the sign of the drag effect can change direction depending on which way the ball is moving.
Finally, you should always label all of your constants with units in physical problems like this. It makes it much easier to debug and spot unit problems. Every line that has an explicit number on it should also have the explicit units listed in a comment off to the side.