doubt regarding a for loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vinay Basagare
am 19 Dez. 2021
Kommentiert: Vinay Basagare
am 19 Dez. 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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Dez. 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()
R32 = randn()
O1O2 = randn(1,3)
O2O3 = randn(1,3)
%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]');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!