# Matlab help to designing a program of a falling object

1. Feb 20, 2013

### e_brock123

1. The problem statement, all variables and given/known data
I'm currently new to Matlab and have just started trying to solve a few problems with it. So I have to make a program that will display the results of height and velocity of a falling object, as well as plotting the overall function.

My main concern is I am using an array for t = [0:0.1:20] seconds were I would rather have time go on till h=0. For these equations:
h = (-0.5*g*t.^2 + u*t) + h0
v = u + g*t

So I was just wondering how I can make my script end time when the ball has reached the ground? I am guessing it will be some kind of if/for loop but still a bit unsure.

2. Relevant equations

3. The attempt at a solution
This is the script I have wrote so far, any help will be greatly appreciated.

% Script file: Position_velocity_ball.m

% constants
g = 9.81; % Acceleration due to gravity
t = 0:0.1:20;

% Get the initial height from the user
h0 = input('Enter the initial height (m):');

% Get the initial velocity from the user
u = input ('Enter the initial velocity (m/s):');

% Calculate the current height of the ball
h = (-0.5*g*t.^2 + u*t) + h0;
disp(['The height of the ball is ' num2str(h) 'm.']);

% Calculate the current velocity
v = u + g*t;
disp(['The velocity of the ball is ' num2str(v) 'm/s']);

% plot the result
plot(v,h);
xlabel('velocity');
ylabel('height');
title('Height versus Velocity');
grid on;
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution