function cam()
clc
clear all
close all
N_i = input('N de intervalos:');
k=1;
while(k<=N_i)
k
beta_i(k) = input('Beta do intervalo:');
L(k) = input('Lift do intervalo:');
mov(k) = input('Movimento do intervalo:');
k=k+1;
end
R_0 = input('Raio base:');
tb_i=0;
tb_f=1;
teta=0;
passo=1;
n=1;
T(n)=teta;
j=1;
while(j<=N_i)
j
switch mov(j)
case 1
while(teta<=beta_i(j))
y=0.5*L(j)*(1-cos(pi*teta/beta_i(j)));
dy=((pi*L(j))/(2*beta_i(j)))*sin(pi*teta/beta_i(j));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:,j)=[y,dy,j]
P(n,:,j)=[u,v,j]
n=n+1;
teta=teta+passo;
end
case 2
while(teta<=beta_i(j))
y=L(j)*((teta/beta_i(j))-sin(2*pi*(teta/beta_i(j))));
dy=(L(j)/beta_i(j))*(1-cos(2*pi*(teta/beta_i(j))));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:,j)=[y,dy,j]
P(n,:,j)=[u,v,j]
n=n+1;
teta=teta+passo;
end
end
j=j+1;
end
end
Why the "while(j<=N_i)" loop only computes A and P for j=1 and doesn't advance after that? Can't understand...

5 comentarios

Adam
Adam el 1 de Nov. de 2016
Well, for a start we have no idea what N_i is since it is a user input.
Miguel Viegas Leal
Miguel Viegas Leal el 1 de Nov. de 2016
Imagine N_i=2
Miguel Viegas Leal
Miguel Viegas Leal el 1 de Nov. de 2016
For example when N_i=2 it only computes for j=1 but not for j=2 and I wonder why.
Image Analyst
Image Analyst el 1 de Nov. de 2016
Can you give typical numbers for all 5 user inputs, not just one, so we know what to enter and can try your code?
Try this:
N de intervalos:2
k =
1
Beta do intervalo:180
Lift do intervalo:3
Movimento do intervalo:1
k =
2
Beta do intervalo:90
Lift do intervalo:2
Movimento do intervalo:2
Raio base:0.025

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Nov. de 2016

1 voto

I notice that you do not initialize teta between the two iterations of the while loop. Your while test is based upon teta which is going to continue to have the value it had after the first iteration of the loop, so the end condition might already be satisfied.

Más respuestas (1)

Image Analyst
Image Analyst el 1 de Nov. de 2016
It worked for me:
N de intervalos:2
k =
1
Beta do intervalo:3
Lift do intervalo:3
Movimento do intervalo:4
k =
2
Beta do intervalo:5
Lift do intervalo:6
Movimento do intervalo:7
Raio base:0
j =
1
j =
2

3 comentarios

Try with this inputs instead:
N de intervalos:2
k =
1
Beta do intervalo:180
Lift do intervalo:3
Movimento do intervalo:1
k =
2
Beta do intervalo:90
Lift do intervalo:2
Movimento do intervalo:2
Raio base:0.025
That also does both j. Look:
N de intervalos:2
k =
1
Beta do intervalo:180
Lift do intervalo:3
Movimento do intervalo:1
k =
2
Beta do intervalo:90
Lift do intervalo:2
Movimento do intervalo:2
Raio base:0.025
j =
1
j =
2
Miguel Viegas Leal
Miguel Viegas Leal el 1 de Nov. de 2016
Editada: Miguel Viegas Leal el 1 de Nov. de 2016
It doesn't compute vectors A and P for j=2...

Iniciar sesión para comentar.

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by