Simulating Projectile with Matlab

조회 수: 3 (최근 30일)
Fares Espiro
Fares Espiro 2022년 3월 18일
편집: Fares Espiro 2022년 3월 20일
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

채택된 답변

James Tursa
James Tursa 2022년 3월 18일
편집: James Tursa 2022년 3월 18일
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
Fares Espiro
Fares Espiro 2022년 3월 18일
편집: Fares Espiro 2022년 3월 18일
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 2022년 3월 18일
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 :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by