How to save "y" and "dy" in the same vector A each time the loop WHILE is incremented?
Afficher commentaires plus anciens
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:');
teta=0;
passo=30;
n=1;
T(n)=teta;
j=1;
while(j<=N_i)
y=0;
dy=0;
teta=0;
T=0;
j
while(teta<=beta_i(j))
switch mov(j)
case 1
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;
case 2
y=L(j)*((teta/beta_i(j))-0.5*(pi^-1)*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;
case 3
y=0.5*L(j)*((1-cos(pi*teta/beta_i(j)))-0.25*(1-cos(2*pi*teta/beta_i(j))));
dy=0.5*pi*(L(j)/beta_i(j))*(sin(pi*teta/beta_i(j))-0.5*sin(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;
case 4
y=L(j)*(1-cos(0.5*pi*teta/beta_i(j)));
dy=((pi*L(j))/(2*beta_i(j)))*sin(0.5*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;
case 5
y=L(j)*sin(pi*0.5*teta/beta_i(j));
dy=0.5*pi*(L(j)/beta_i(j))*cos(0.5*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;
case 6
y=L(j)*((teta/beta_i(j))-(pi^-1)*sin(pi*(teta/beta_i(j))));
dy=(L(j)/beta_i(j))*(1-cos(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;
case 7
y=L(j)*((teta/beta_i(j))+(pi^-1)*sin(pi*(teta/beta_i(j))));
dy=(L(j)/beta_i(j))*(1+cos(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;
case 8
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;
case 9
y=L(j)*(1-(teta/beta_i(j))-0.5*(pi^-1)*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;
case 10
y=0.5*L(j)*((1+cos(pi*teta/beta_i(j)))-0.25*(1-cos(2*pi*teta/beta_i(j))));
dy=-0.5*pi*(L(j)/beta_i(j))*(sin(pi*teta/beta_i(j))+0.5*sin(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;
case 11
y=L(j)*(cos(0.5*pi*teta/beta_i(j)));
dy=-((pi*L(j))/(2*beta_i(j)))*sin(0.5*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;
case 12
y=L(j)*(1-sin(pi*0.5*teta/beta_i(j)));
dy=-0.5*pi*(L(j)/beta_i(j))*cos(0.5*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;
case 13
y=L(j)*(1-(teta/beta_i(j))+(pi^-1)*sin(pi*(teta/beta_i(j))));
dy=-(L(j)/beta_i(j))*(1-cos(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;
case 14
y=L(j)*(1-(teta/beta_i(j))-(pi^-1)*sin(pi*(teta/beta_i(j))));
dy=-(L(j)/beta_i(j))*(1+cos(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;
case 15
y=L(j);
dy=0;
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
end
A(n,:,j)=[y,dy,j]
P(n,:,j)=[u,v,j]
n=n+1;
teta=teta+passo;
end
figure
plot(T,A(:,1,j))
figure
plot(P(:,1,j),P(:,2,j))
j=j+1;
end
end
Given the following input:
N de intervalos:2
k =
1
Beta do intervalo:180
Lift do intervalo:2
Movimento do intervalo:1
k =
2
Beta do intervalo:180
Lift do intervalo:2
Movimento do intervalo:8
Raio base:0.025
I got as result for vector A:
A(:,:,1) =
0 0 1.0000
0.1340 0.0087 1.0000
0.5000 0.0151 1.0000
1.0000 0.0175 1.0000
1.5000 0.0151 1.0000
1.8660 0.0087 1.0000
2.0000 0.0000 1.0000
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
A(:,:,2) =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
2.0000 0 2.0000
1.8660 -0.0087 2.0000
1.5000 -0.0151 2.0000
1.0000 -0.0175 2.0000
0.5000 -0.0151 2.0000
0.1340 -0.0087 2.0000
0 -0.0000 2.0000
The problem is when j=2 (the second time the loop runs) the vector A seems to clear the values computed when j=1 (the first time the loop runs). How can I solve this problem?
I am just crashing into a wall over and over again.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!