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 件のコメント

Adam
Adam 2016 年 11 月 1 日
Well, for a start we have no idea what N_i is since it is a user input.
Miguel Viegas Leal
Miguel Viegas Leal 2016 年 11 月 1 日
Imagine N_i=2
Miguel Viegas Leal
Miguel Viegas Leal 2016 年 11 月 1 日
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 2016 年 11 月 1 日
Can you give typical numbers for all 5 user inputs, not just one, so we know what to enter and can try your code?
Miguel Viegas Leal
Miguel Viegas Leal 2016 年 11 月 1 日
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

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 1 日

1 投票

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.

1 件のコメント

Miguel Viegas Leal
Miguel Viegas Leal 2016 年 11 月 1 日
Thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 11 月 1 日

0 投票

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 件のコメント

Miguel Viegas Leal
Miguel Viegas Leal 2016 年 11 月 1 日
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
Image Analyst
Image Analyst 2016 年 11 月 1 日
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 2016 年 11 月 1 日
編集済み: Miguel Viegas Leal 2016 年 11 月 1 日
It doesn't compute vectors A and P for j=2...

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by