doubt regarding a for loop

11 vues (au cours des 30 derniers jours)
Vinay Basagare
Vinay Basagare le 19 Déc 2021
Commenté : Vinay Basagare le 19 Déc 2021
k11=28.21;
k21=-4.23;
k12=-18.133;
k22=2.59;
k13=20.815;
k23=-2.97;
for i=1:5
tdot1=k11+2*k21*t(i);
tdot2=k12+2*k22*t(i);
tdot3=k13+2*k23*t(i);
w1=[0;0;tdot1*2*pi/360];
w2=R21*w1+[0;0;tdot2*2*pi/360];
w3=R32*w2+[0;0;tdot3*2*pi/360];
uW1(i)=w1(3,1);
uW2(i)=w2(3,1);
uW3(i)=w3(3,1);
v2=R21*cross(w1,O1O2);
v3=R32*(v2+cross(w2,O2O3));
uV2(i)=norm(v2);
uV3(i)=norm(v3);
hold on
figure(1)
plot(t,uW1,'*')
xlabel('time[s]');
ylabel('w1[rad/s]');
figure(2)
plot(t,uW2,'*')
xlabel('time[s]');
ylabel('w2[rad/s]');
figure(3)
plot(t,uW3,'*')
xlabel('time[s]');
ylabel('w3[rad/s]');
figure(4)
plot(t,uV2,'.')
xlabel('time[s]');
ylabel('v2[m/s]');
figure(5)
plot(t,uV3,'.')
xlabel('time[s]');
ylabel('v3[m/s]');
end
I want to understand this code. I am unable to get how can i define t(i) in order to get the code to work. Please help me.

Réponse acceptée

Walter Roberson
Walter Roberson le 19 Déc 2021
k11=28.21;
k21=-4.23;
k12=-18.133;
k22=2.59;
k13=20.815;
k23=-2.97;
%some variables were left undefined
R21 = randn()
R21 = 1.2025
R32 = randn()
R32 = -0.8773
O1O2 = randn(1,3)
O1O2 = 1×3
-0.0390 -0.7938 -0.8864
O2O3 = randn(1,3)
O2O3 = 1×3
1.5511 -0.5591 -1.2109
%end of undefined variables
t = 0:.1:3;
num_t = length(t);
for i=1:num_t
tdot1=k11+2*k21*t(i);
tdot2=k12+2*k22*t(i);
tdot3=k13+2*k23*t(i);
w1=[0;0;tdot1*2*pi/360];
w2=R21*w1+[0;0;tdot2*2*pi/360];
w3=R32*w2+[0;0;tdot3*2*pi/360];
uW1(i)=w1(3,1);
uW2(i)=w2(3,1);
uW3(i)=w3(3,1);
v2=R21*cross(w1,O1O2);
v3=R32*(v2+cross(w2,O2O3));
uV2(i)=norm(v2);
uV3(i)=norm(v3);
end
hold on
figure(1)
plot(t,uW1,'-*')
xlabel('time[s]');
ylabel('w1[rad/s]');
figure(2)
plot(t,uW2,'-*')
xlabel('time[s]');
ylabel('w2[rad/s]');
figure(3)
plot(t,uW3,'-*')
xlabel('time[s]');
ylabel('w3[rad/s]');
figure(4)
plot(t,uV2,'-.')
xlabel('time[s]');
ylabel('v2[m/s]');
figure(5)
plot(t,uV3,'-.')
xlabel('time[s]');
ylabel('v3[m/s]');
  1 commentaire
Vinay Basagare
Vinay Basagare le 19 Déc 2021
Thanks a lot. Really appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by