Simulating Projectile with Matlab

3 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
thanks

Accepted Answer

James Tursa
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:
V(i+1)=V(i)+deltat*a;
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:
d(i+1)=d(i)+deltat*V(i);
And you would start d(1) at some appropriate initial height prior to loop entry. E.g.,
d=zeros(1,N); % Position
d(1)=d0;
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.
  4 Comments
Fares Espiro
Fares Espiro on 18 Mar 2022
Edited: Fares Espiro on 18 Mar 2022
Ohh now i see. You are a real hero thank you so much.
Just one last question i want to know the exact time the ball passes d = 8.38
i used this before
interp1(XData,YData,8.38)
but now its giving me an error saying "The grid vectors must contain unique points." how can i fix this?
Fares Espiro
Fares Espiro on 18 Mar 2022
Oh i just figured it out.
I used
[XData, index] = unique(XData);
interp1(XData,YData(index),8.38)
Thank you so much for your help again :)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!