# The distance traveled by a ball falling in the air is given by the equation x = x_{0} + v_{0}*t + 1/2 * a * t ^ 2

16 views (last 30 days)

Show older comments

##### 6 Comments

Dyuman Joshi
on 21 Feb 2024

Edited: Dyuman Joshi
on 21 Feb 2024

You have calculated the displacement of the ball, but the question asks for position.

Now, how will you calculate position from the given value?

### Answers (2)

Sam Chak
on 21 Feb 2024

Hi @Felix Jim

It might be beneficial for you to explore how to utilize MATLAB for solving dynamical equations, particularly when dealing with systems where the states change over time. In your case, the dynamical equation for the falling ball with neglected air resistance can be expressed through this equation:

, with m and m/s.

By performing double integration, you can obtain an analytical solution, as you described in your question.

%% Unrealistic simulation of a falling ball by naively solving the ODE in pure math's way

tspan = [0 5];

y0 = [10, 15]; % initial values y = 10 m, v = 15 m/s

[t, y] = ode45(@falling, tspan, y0);

%% Plot results

figure

plot(t, y), grid on

legend('ball''s height', 'ball''s velocity')

title('Unrealistic simulation of a falling ball'), xlabel t

%% ball's height at the end of simulation

h = y(:,1);

h(end)

%% Slightly realistic simulation of a falling ball

options = odeset('RelTol', 1e-8, 'AbsTol', 1e-10, 'Events', @touchDownEventFcn);

[t, y] = ode45(@falling, tspan, y0, options);

%% Plot results

figure

plot(t, y), grid on

legend('ball''s height', 'ball''s velocity')

title('Slightly realistic simulation of a falling ball'), xlabel t

%% the time when ball touches the surface

t(end)

%% ---- Put local functions here -----

%% Function 1: Falling motion of a non-elastic solid ball when air resistance is neglected

function dydt = falling(t, y)

a = -9.81; % gravity

dydt(1,1) = y(2); %

dydt(2,1) = a;

end

%% Function 2: Stop simulation when the ball has touched the hard surface without deformation or bouncing

function [position, isterminal, direction] = touchDownEventFcn(t, y)

position = y(1); % The state variable that we want to be zero

isterminal = 1; % Halt integration

direction = -1; % The zero can be approached when x1 is decreasing

end

##### 1 Comment

Sam Chak
on 21 Feb 2024

@Felix Jim, you can also use MATLAB to solve this equation

to determine the time when the ball hits the ground.

help fzero

VBBV
on 21 Feb 2024

Here is another simple way to find the position

t = 0:0.01:10; % consider a time vector for ball displacement (say 10s)

x0 = 10;

v0 = 15;

a = -9.81; % acceleration

x = x0+v0*t+0.5*a*t.^2;

hold on

plot(t,x); ylim([-50 50])

idx = t == 5; % find the index of 5s in time vector

plot(t(idx),x(idx),'r+','MarkerSize',20,'Linewidth',2); xlabel('time [s]');ylabel('position'); grid

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!