필터 지우기
필터 지우기

Why does my red lines on the graph stop?

조회 수: 2 (최근 30일)
Charles Steyn
Charles Steyn 2020년 6월 16일
댓글: Charles Steyn 2020년 6월 19일
For code, the red lines (vl and rvr) on the graph need to reach a certain point, which I have defined as 50, then it should remain constant. When I get the graph, the red lines stop when it reaches 50 instead of continuing constantly for the remainder of the time. How can I get the lines to show that it is constant until the end?
Any help would be greatly appreciated.
%Constants
m = 300
rw = 0.356
Iw = 2.7
N = m*9.81
Td1 = 1.134826021738053e+03
Td2 = 1200
%Magic Formula
B_1 = 10
C_1 = 1.9
D_1 = 1
E_1 = 0.97
t = [0:0.1:10]
al1= NaN(1,length(t));%empty acceleration vector
al2= NaN(1,length(t));%empty acceleration vector
vl1= NaN(1,length(t));%empty velocity vector
vl2= NaN(1,length(t));%empty velocity vector
rar1= NaN(1,length(t));%empty acceleration vector
rar2= NaN(1,length(t));%empty acceleration vector
rvr1= NaN(1,length(t));%empty velocity vector
rvr2= NaN(1,length(t));%empty velocity vector
slip1 = NaN(1,length(t));
slip2 = NaN(1,length(t));
CF_1 = NaN(1,length(t));
CF_2 = NaN(1,length(t));
vl1(1) = 0
vl2(1) = 0
rvr1(1) = 0
rvr2(1) = 0
slip1(1) = 0.16
slip2(1) = 0.16
for i = 2:100
CF_1(i) = D_1*sin(C_1*atan(B_1*slip1(i-1)-E_1*(B_1*slip1(i-1)-atan(B_1*slip1(i-1)))))
CF_2(i) = D_1*sin(C_1*atan(B_1*slip2(i-1)-E_1*(B_1*slip2(i-1)-atan(B_1*slip2(i-1)))))
al1(i) = (1/m)*(CF_1(i)*N)
al2(i) = (1/m)*(CF_2(i)*N)
vl1(i)=vl1(i-1)+al1(i)*0.1;
vl2(i)=vl2(i-1)+al2(i)*0.1;
rar1(i) = (1/Iw)*(Td1-(CF_1(i)*N*rw))*rw;
rar2(i) = (1/Iw)*(Td2-(CF_2(i)*N*rw))*rw;
rvr1(i)=rvr1(i-1)+rar1(i)*0.1;
rvr2(i)=rvr2(i-1)+rar2(i)*0.1;
if rar1(i)<0
rar1(i)=0
end
if vl1(i)>50
al1(i) = 0
vl1(i) = vl1(i-1)
rar1(i) = 0
rvr1(i) = rvr1(i-1)
end
slip1(i) = (rar1(i)-al1(i))/rar1(i)
slip2(i) = (rar2(i)-al2(i))/rar2(i)
end
figure,plot(t,vl1,'r',t,rvr1,'r',t,vl2,'b',t,rvr2,'b')
% figure,plot(t,rar1)
% figure,plot(t,slip)
% figure,plot(t,CF_1)
  댓글 수: 2
KSSV
KSSV 2020년 6월 16일
It is because, vl1 is taking a value NaN. You should recheck your code.
Charles Steyn
Charles Steyn 2020년 6월 16일
How would I then get vl1(i) to be vl1(i-1) for every loop? In this way vl1 would remain constant and not take on the value NaN

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

채택된 답변

Karthik Malisetty
Karthik Malisetty 2020년 6월 18일
Hi Charles Steyn,
My understanding is that in the ‘if’ section, you are setting the values of al1(i) and rar1(i) to zero.
if vl1(i)>50
al1(i) = 0
vl1(i) = vl1(i-1)
rar1(i) = 0
rvr1(i) = rvr1(i-1)
end
This would make the expression
slip1(i) = (rar1(i)-al1(i))/rar1(i)
as 0/0 which is NaN’ in Matlab.
So, slip1(i) is set to NaN (precisely at i=53) which in turn will set vl1(i) = ‘NaN’ (at i=54). So, the if condition fails at i = 54.
Therefore, the values of vl1 will remain as NaN for i=55 to 100. These NaN values cant be reflected in plot.
Hence, the red line plots in the graph are stopped.
Removing the lines al1(i)=0 and rar1(i)=0 would give you those horizontal lines. Although, you should check that it wouldn’t effect any other program (if any)
  댓글 수: 1
Charles Steyn
Charles Steyn 2020년 6월 19일
Thank you so much. This makes total sense!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by