control of a script
조회 수: 11 (최근 30일)
이전 댓글 표시
hi! I wrote this script but i'm not sure if the response can be true, what do you think about it?
clc
clear all
dt=0.4;
[t,a]=ode45(@Law,[0 0+dt],[0;0;0;0]);
where
function [ da ] = Law( t,a )
[Ks,cs,I,m,g,L,K0,Kc,Icw,c0,cc,T0,r,alfa,mcw,lc,lcw,ls]=deal(1.0e+07,133.58,7.3777e-04,0.105795,9.78,0.0709444,0.37,1.0e+06,2.7195e-05,9.3e-05,24.22,0.12,0.028284,pi/4,0.11887,0.12,0.010528,0.09);
A=400;
w=1257;
h=0.003;
yl=lc*tan(a(1));
dyl=lc*a(3)/(cos(a(1)))^2;
yc=r*(sin(alfa)-sin(alfa-a(1)));
dyc=r*a(4)*cos(alfa-a(2));
yu=lc*tan(a(1))+h/cos(a(1));
dyu=((lc+h*sin(a(1)))*a(3))/(cos(a(1)))^2;
%value of Fs
if a(1)>=0
Fs=0;
else
Fs=-Ks*ls*a(1)-cs*ls*a(3);
end
%value of R
if yc<yl
R=lc/cos(a(1));
elseif (yl<yc) && (yc<yu)
R=0;
elseif (yl==yc) && (yc==yu)
R=0;
elseif (yl==yc) && (yc<yu)
R=0;
elseif (yl<yc) && (yc==yu)
R=0;
elseif yc>yu
R=lc/cos(a(1))+h*tan(a(1));
end
%value of Fr
if yc<yl
Fr=Kc*(yl-yc)*cos(a(1))+cc*(dyl-dyc)*cos(a(1))-(yl-yc)*a(3)*sin(a(1));
elseif (yl<yc) && (yc<yu)
Fr=0;
elseif (yl==yc) && (yc==yu)
Fr=0;
elseif (yl==yc) && (yc<yu)
Fr=0;
elseif (yl<yc) && (yc==yu)
Fr=0;
elseif yc>yu
Fr=Kc*(yu-yc)*cos(a(1))+cc*(dyu-dyc)*cos(a(1))-(yu-yc)*a(3)*sin(a(1));
end
%law
da=[a(3);a(4);Fs*ls/I-(R*Fr)/(I)-(m*g*A*L*sin(w*t)*cos(a(1)))/I;-K0*a(2)/Icw-c0*a(4)/Icw-T0/Icw+Fr*r*cos(a(1))*cos(alfa-a(2))/Icw+(mcw*g*lcw*(A*sin(w*t)*cos(a(2))+sin(a(2))))/Icw];
end
thanks in advance!
댓글 수: 0
채택된 답변
Walter Roberson
2015년 7월 8일
When you have two values that are computed through different paths and the two values mathematically should represent the same quantities, then often the two values will not compare equal with == . This is due to floating point round off. For example, ((10/3)*3) might not compare exactly equal to 10.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!