1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab help to designing a program of a falling object

  1. Feb 20, 2013 #1
    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
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Matlab help to designing a program of a falling object
  1. HELP MATLAB program (Replies: 2)

Loading...