Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use matlab to model the following: Model a ball being tossed in the air using ti

ID: 3566511 • Letter: U

Question

Use matlab to model the following:

Model a ball being tossed in the air using time stepping method

Next Value = Current Value + Change Value

VARIABLE DICTIONARY BALL THROW:

% --------------------------------------------------------------------

% g        :   gravitational acceleration (-9.81 m/sec^2)

% dt       :   time step for the simulation

% t(1)     :   initial time (s)

% h(1)     :   initial height (m) 0

% v(1)     :   initial velocity (m/sec) 30 m/sec

% t(i)     :   time(s)    (during simulation)

% h(i)     :   height(m)   (during simulation)

% v(i)     :   velocity (m/sec) (during simulation)

% t(i+1)   :   Next time -> Current Time + Change in time (time step)

% h(i+1)   :   Next Height -> Current Height + Change in height (v*dt)

% v(i+1)   :   Next Velocity -> Current Velocity + Change in v (acc*dt)

% ---------------------------------------------------------------------

% Acceleration due to gravity

g = -9.81;               

% set time interval and number of computational steps

to = 0;   %0 seconds: Initial time

tf = 10;   %10 seconds: Arbitrary Final Time for Simulation

N = 1000; %1000 loops    

dt = (tf-to)/N; % length of time step (.01sec)

% set the initial values for t, v, and h

t = to;         

v = 30; %30 m/s upward           

h = 0;

% Complete the for loop to calculate the height of the ball. First,

% calculate the next value of height based on the previous height, velocity,

% and the time step. Then calculate the next velocity based on the previous

% velocity, acceleration, and the time step. Then calculate the next time

% using the current time and the change in time: the time step, dt.

for i = 1:N    

    % ENTER CODE HERE FOR CALCULATION            

end

Explanation / Answer

% g : gravitational acceleration (-9.81 m/sec^2)

% dt : time step for the simulation

% t(1) : initial time (s)

% h(1) : initial height (m) 0

% v(1) : initial velocity (m/sec) 30 m/sec

% t(i) : time(s) (during simulation)

% h(i) : height(m) (during simulation)

% v(i) : velocity (m/sec) (during simulation)

% t(i+1) : Next time -> Current Time + Change in time (time step)

% h(i+1) : Next Height -> Current Height + Change in height (v*dt)

% v(i+1) : Next Velocity -> Current Velocity + Change in v (acc*dt)

% ---------------------------------------------------------------------

% Acceleration due to gravity

g = -9.81;   

% set time interval and number of computational steps

to = 0; %0 seconds: Initial time

tf = 10; %10 seconds: Arbitrary Final Time for Simulation

N = 1000; %1000 loops

dt = (tf-to)/N; % length of time step (.01sec)

% set the initial values for t, v, and h

t = to;   

v = 30; %30 m/s upward   

h = 0;

% Complete the for loop to calculate the height of the ball. First,

% calculate the next value of height based on the previous height, velocity,

% and the time step. Then calculate the next velocity based on the previous

% velocity, acceleration, and the time step. Then calculate the next time

% using the current time and the change in time: the time step, dt.

for i = 1:N
t(i+1)= t(i)+dt;
h(i+1)= h(i)+v(i)*dt;
v(i+1)= v(i)+g*dt;


end