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!

Homework Help: Please help my for loop goes on forever (Matlab!) :/

  1. Sep 19, 2012 #1
    1. The problem statement, all variables and given/known data

    Question: A ball is launched from a height of 12m. It should land in a pool that has a length of 22m and is 9m away from the wall. Find the minimum and maximum initial velocities for the ball to land in the pool. The ramp is angled at 1 radian such that vy = 0.54v and vx = 0.84v at time zero. The ball will not be airborned for more than 3 seconds.

    2. Relevant equations

    px= vx*t

    py = 12m+vy*t

    vy = vy0 – t *9.81 m/s^2

    vi = [vx0 vy0] (matlab)

    3. The attempt at a solution

    So I tried to write a loop for it. My nested for loop goes on forever...can someone please help?

    s= 'DEAD';

    k = 'ALIVE';


    for r=1:length(v0);


    for j = 1:length(pxi);

    if pxi(j)<9;
    fprintf('%s', s);

    elseif pxi(j)>31;
    fprintf('%s', s);

    fprintf('%s', k);





    PLEASE help! I think my approach may be wrong. If anyone can provide some pseducode :/ I suck at matlab!
  2. jcsd
  3. Sep 19, 2012 #2
    So I realized that my inner loop will execute over over 3 million times...is there another way of approaching this? :/
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook