How can i add a distance to time plot in Matlab

23 views (last 30 days)
I have a school project to simulate free fall of an object with air resistance. I'm just having trouble figuring out how to plot a distance / time graph. I dont have any distance variable in my code, do i have to add one or is there maybe some kind of work around?
clear all;
V0=0; % initial speed
m=5; % mass in kg
g=9.81; % gravity acceleration kg/m3
rho=1.2; % Air density
A=0.09; % Object area
cw=0.4; % Numerical drag coefficient
k=0.5*cw*rho*A; % Coefficient
N=200; % Time step
V=zeros(1,N); % Speed
V(1)=V0;
deltat=0.2;
for i=1:N-1
V(i+1)=V(i)+deltat*(g-(k/m)*V(i)^2);
end
t=(0:N-1)*deltat;
plot(t,V);
xlabel('time in sec');
ylabel('velocity in m/s');
legend ('Euler Method','location','south');

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Feb 2022
You have velocity. Has your teacher taught you how to use time and velocity to get distance yet?
  7 Comments
Fares Espiro
Fares Espiro on 8 Feb 2022
Edited: Fares Espiro on 9 Feb 2022

My project was to calculate how long it would take a falling abject(Basketball) to reach the ground from a specefic height in this case 8m.
I think I found why I had decreasing derivatives it was because i had a minus after the 8 in :
d=8- V(i+1)*t + 0.5*(g-(k/m)*V(i)^2)*t.*t
I dont know if im thinking right but this is what I have now

clear all;
V0=0; % initial speed
m=0.62369; % mass in kg
g=9.82; % gravity acceleration kg/m3
rho=1.225; % Air density
A=0.18/4; % Object area
cw=0.6; % Numerical drag coefficient
k=0.5*cw*rho*A; % Coefficient
N=8; % Time step
V=zeros(1,N); % Speed
V(1)=V0;
deltat=0.15;
for i=1:N-1
V(i+1)=V(i)+deltat*(g-(k/m)*V(i)^2); % velocity
t=(0:N-1)*deltat; %Time
d=V(i+1)*t + 0.5*(g-(k/m)*V(i)^2)*t.*t % Distance that the Basketball have fallen
end
plot(t,d);
xlabel('time in sec');
ylabel('Distande in m');
legend ('Euler Method','location','south');
Now im getting that it takes the Ball around 0.7s secound to reach the ground from a height of 8m --> x = 0.7 when Y = 8
when we experimented in school the time was around 0.9s
Have I done anything wrong in my calculations?
I really appreciate your help

Cris LaPierre
Cris LaPierre on 8 Feb 2022
Edited: Cris LaPierre on 21 Mar 2022
EDIT: OP's response:
My project was to calculate how long it would take a falling abject(Basketball) to reach the ground from a specefic height in this case 8m.
I think I found why I had decreasing derivatives it was because i had a minus after the 8 in :
d=8- V(i+1)*t + 0.5*(g-(k/m)*V(i)^2)*t.*t
I dont know if im thinking right but this is what I have now
clear all;
V0=0; % initial speed
m=0.62369; % mass in kg
g=9.82; % gravity acceleration kg/m3
rho=1.225; % Air density
A=0.18/4; % Object area
cw=0.6; % Numerical drag coefficient
k=0.5*cw*rho*A; % Coefficient
N=8; % Time step
V=zeros(1,N); % Speed
V(1)=V0;
deltat=0.15;
for i=1:N-1
V(i+1)=V(i)+deltat*(g-(k/m)*V(i)^2); % velocity
t=(0:N-1)*deltat; %Time
d=V(i+1)*t + 0.5*(g-(k/m)*V(i)^2)*t.*t % Distance that the Basketball have fallen
end
plot(t,d);
xlabel('time in sec');
ylabel('Distande in m');
legend ('Euler Method','location','south');
Now im getting that it takes the Ball around 0.7s secound to reach the ground from a height of 8m --> x = 0.7 when Y = 8
when we experimented in school the time was around 0.9s
Have I done anything wrong in my calculations?
I really appreciate your help
REPLY:
It depends what you want d to be. If it is the current height, then the proper equation is d=8-...
If you just want to know the distance the ball has traveled, then d=V... will give you that.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots 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!