How to make three successive "for" loops and start the next loop from the end of the previous one?

1 view (last 30 days)
Hello everybody; hope you all are doing well :)
look i have a code that suppose to make 3 successive loops but i can't make actually 3 things:
1- only one for loop contain the 3 loops together instead of separating each alone..
2- i state a condition for the first loop to stop and so the second loop suppose to start but i want to now at what iteration it will stop ,, ex: i stated a condition to stop this loop and start the new one when the value of y(i+1)<=0 but i want to know when? at Y(150) or what? because i want the loops to be successive and start from the end point of the first..
hope my question is clear... here is the code
if true
% code
clc,clear, close all
% Variables
% P= ball force % (u,v) velocity of ball in (X,y)= distanve/time --> (dx/dt) % u=dx/dt , v=dy/dt
%force of the ball in the x and Y direction % Px=-mzu Px= m. du/dt % Py=-mzv Py-mg = m. dv/dt
% z= air resistance (proportional to the square of the speed and ball radius) % z = const*(u.^2+v.^2) % z=CR^2/m *(sqrt(u.^2 + v.^2))
% angle of kick: Cos(x)= u/sqrt(u.^2+v.^2)
% Variables % R= ball raduis % m= mass of ball % g= gravity % w= angle of the kick % h= Choose a value h for the size of every step % OH: Object hight --> OHx, OHy % D1: distance from the player to the object % D2: distance from the object to the goal
% Intial conditions (Constants) R= 0.11; %unit in meter m= 0.4; % unit in kg g= 9.8; D1= 5; % unit in meters D2= 2.5; % unit in meters
% variable values w(1)= 45; % unit in degree u(1)= 100*cosd(w); v(1)= 100*sind(w); x(1)=0; y(1)=0;
% using Euler method; %n= v(1);
% first step size h1=0.005; t1=1000; % unit in sec w1= 45; % unit in degree u1(1)= 100*cosd(w1); v1(1)= 100*sind(w1); x1(1)=0; y1(1)=0;
for i=1:t1;
% position of the ball
y1(i+1)=y1(i)+(h1*v1(i));
x1(i+1)=x1(i)+(h1*u1(i));
if y1(i+1)>0
z1(i)= ((50*R.^2)/m) *(sqrt(u1(i).^2 + v1(i).^2));
v1(i+1)=v1(i)-(h1*(g+(z1(i))*v1(i)));
u1(i+1)=u1(i)-(h1*z1(i)*(u1(i)));
else
% second step size
w2= 30; % unit in degree (suppose to be the reflected angle)
u2(1)= 0.7*100*cosd(w2); % sppose to be 70% of the force that hit the ground
v2(1)= 0.7*100*sind(w2);
% the step i stopped at ? how to find?
x2(31)=x1(30);
y2(31)=y1(30);
% position of the ball
x2(i+1)=x(i)+(h1*u2(i));
y2(i+1)=y(i)+(h1*v2(i));
z2(i)= ((50*R.^2)/m) *(sqrt(u2(i).^2 + v2(i).^2));
v2(i+1)=v2(i)-(h2*(g+(z2(i))*v2(i)));
u2(i+1)=u2(i)-(h2*z2(i)*(u2(i)));
end
end
% third step size
h3=0.1;
t3=5; % unit in 30
w3= 15; % unit in degree
u3(1)= 100*cosd(w3);
v3(1)= 100*sind(w3);
x3(1)=x2(15);
y3(1)=y2(15);
for i=1:t3
% if x(i)=t1 ;
% n=x(i);
%end
% position of the ball
x3(i+1)=x3(i)+(h3*u3(i));
y3(i+1)=y3(i)+(h3*v3(i));
z3(i)= ((50*R.^2)/m) *(sqrt(u3(i).^2 + v3(i).^2));
v3(i+1)=v3(i)-(h3*(g+(z3(i))*v3(i)));
u3(i+1)=u3(i)-(h3*z3(i)*(u3(i)));
end
end

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!