필터 지우기
필터 지우기

doubt regarding a for loop

조회 수: 3 (최근 30일)
Vinay Basagare
Vinay Basagare 2021년 12월 19일
댓글: Vinay Basagare 2021년 12월 19일
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.

채택된 답변

Walter Roberson
Walter Roberson 2021년 12월 19일
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
Vinay Basagare
Vinay Basagare 2021년 12월 19일
Thanks a lot. Really appreciate it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by