• Support PF! Buy your school textbooks, materials and every day products Here!

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

  • Thread starter irNewton
  • Start date
  • #1
17
0

Homework Statement



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.



Homework Equations



px= vx*t

py = 12m+vy*t

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

vi = [vx0 vy0] (matlab)

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';

v0=0:0.01:100;
t=0:0.01:3;

for r=1:length(v0);
v00=v0(r);
vxx=v0(r)*0.84;
vyy=v0(r)*0.54;

pxi=vxx.*t;

for j = 1:length(pxi);

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

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

else
fprintf('%s', k);

end;

j=j+1;

end;

end;

PLEASE help! I think my approach may be wrong. If anyone can provide some pseducode :/ I suck at matlab!
 

Answers and Replies

  • #2
17
0
So I realized that my inner loop will execute over over 3 million times...is there another way of approaching this? :/
 

Related Threads on Please help my for loop goes on forever (Matlab!) :/

  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
15
Views
5K
  • Last Post
Replies
3
Views
21K
  • Last Post
Replies
8
Views
1K
  • Last Post
Replies
22
Views
5K
Replies
1
Views
3K
  • Last Post
Replies
3
Views
1K
Replies
10
Views
11K
  • Last Post
Replies
0
Views
5K
Top