数学建模社区-数学中国

标题: 帮忙看下程序 [打印本页]

作者: deven1985    时间: 2011-9-2 14:02
标题: 帮忙看下程序
下面这个程序是在x=[x;diff(x)],u=I的条件下的滑模变结构控制,要想把其更改为在x=[x;y;diff(x);diff(y)],u=[Ix;Iy]条件下的话,这个程序应该如何修改?谢谢大家了!
8 g' c' Z: Y1 I) O) u5 t$ K3 Uclear all;
7 d8 q0 N# u) Tclose all;
% P2 q0 r: s" [a=25;b=133;. n5 M8 ?1 {' V. K  Z+ X
ts=0.001;- J# p" k" a/ d4 L4 A6 Y$ A9 E- C
A1=[0,1;0,-a];
4 r4 M5 s5 |) h# u* g" z+ SB1=[0;b];) Z+ E% S5 l- D$ b% \4 x( e+ h
C1=[1,0];
' S0 y5 w% }5 L/ o$ w* nD1=0;+ V. p. ^  e! o0 U
[A,B,C,D]=c2dm(A1,B1,C1,D1,ts,'z');
6 a" \1 A5 m& jx=[-0.8;-0.5];) ~3 a6 I: Y" w- z" b/ o3 F. P
r_1=0;r_2=0;
! t9 u$ p2 S; Dc=20;5 g3 i8 ]/ W9 Z! d$ b0 z, I
eq=5;# _; d' h' {. E. y9 M
q=30;
' O; _; z4 ]4 f% k. R8 n/ @Ce=[c,1];+ A$ ^1 X! i; l# B  C
for k=1:1:2000
; w2 J9 g6 ]6 G/ h9 \& U9 _- ]time(k)=k*ts;
9 f5 A3 d2 f: D6 V* M6 g. Z   r(k)=1.0;
$ e' L( j9 h" z   
& A6 m1 q$ [3 L   %Using Waitui method   4 e/ {( t1 N  h5 V6 J
   dr(k)=(r(k)-r_1)/ts;
% v- c* J3 Z. w% _   dr_1=(r_1-r_2)/ts;
7 j& p  h8 Y1 t9 I   r1(k)=2*r(k)-r_1;' `' y7 p3 D; L; q0 f( l5 ^
   dr1(k)=2*dr(k)-dr_1;
4 t" C. a, V0 U3 r  
$ P/ c3 o( g9 k$ S" C$ z: s# b& l   R=[r(k);dr(k)];" c  x/ o0 J2 Q) @* E
   R1=[r1(k);dr1(k)];
- g9 T( D1 H1 f2 m4 H' ]3 t   
' R3 N  [6 b& G7 x5 b   E=R-x;. ?- N4 s" [, ~2 W8 M
   e(k)=E(1);
0 @+ A  n6 [2 }5 ^   de(k)=E(2);0 W# I' [& c6 f7 t. E
   
' w( w3 A4 ]! d# U/ u   s(k)=Ce*E;
) Q1 |* h0 U  K9 p1 _+ N+ i) J+ `   8 x1 i) w7 x% n" C# ^) |
   X1=abs(e(k))+abs(de(k));
7 a) A# l/ q# |6 D/ ~  n: W# ^   4 Y6 B7 B0 E1 D7 Y1 P' b, V; ^
M=3;   
# y( `8 j1 e/ t; m$ nif M==1             %EXP reaching law8 n/ R5 d9 Y) ?( t$ c
   ds(k)=-eq*ts*sign(s(k))-q*ts*s(k);
: J- {6 o6 o0 \9 i( x   u(k)=inv(Ce*B)*(Ce*R1-Ce*A*x-s(k)-ds(k));# p: M) x  G* z9 O5 K3 v
elseif M==2         %Variable rate reachine law4 G0 W5 a7 a3 K( K9 y5 X; `
   ds(k)=-eq*ts*X1*sign(s(k));2 }7 d0 q: u: M
   u(k)=inv(Ce*B)*(Ce*R1-Ce*A*x-s(k)-ds(k));
$ K6 f7 r( n2 u# d. felseif M==3         %Coposite reaching law1 s) u) o/ O; F7 V9 a  h, S$ X" G
   k0=0.60;
; w/ u" c4 |2 ?' y- W/ A- h   if X1>k0          %EXP reachine law
# ]: c0 h( ]8 A' ~; z' p5 o% i+ L    ds(k)=-eq*ts*sign(s(k))-q*ts*s(k);6 P% d* C) u, ]1 O& m4 F! }" P: _9 x
    u(k)=inv(Ce*B)*(Ce*R1-Ce*A*x-s(k)-ds(k));9 b' Q: f* D9 t+ B, P6 K& Q
   elseif X1<=k0     %Variable rate reachine law
; w! M- W- z2 H1 i% j' l   ds(k)=-eq*ts*X1*sign(s(k));' y* T/ L- K. A- ]2 l
   u(k)=inv(Ce*B)*(Ce*R1-Ce*A*x-s(k)-ds(k));
1 N9 K/ {+ H( \; ]( C   end
" H+ g+ R, ?, V5 b3 uend: g( t& c% i7 [- \; y7 I4 j
if u(k)>=10
- z/ U) X" r) L# |   u(k)=10;
) A7 ]4 f6 ]' Iend
; N- K- J$ s% q4 i9 |; @if u(k)<=-10
# t& R5 C6 @7 B, X3 L   u(k)=-10;
9 j5 I4 G  Q( o3 L1 V. cend) r% E& ]) O' D& _8 D9 ~1 N
x=A*x+B*u(k);
. c' M2 v) B  O  R0 Iy(k)=x(1);- d9 g4 c2 G6 v, h' X# ]
%Update Parameters
. ^# g0 X/ M  O+ `# [3 f$ b8 r- q7 er_2=r_1;
* Y2 ]( ~- f) [9 U$ D" Ar_1=r(k);
* h* U7 }: P# ^# ?end& P  x& w8 s3 l1 W0 S1 J' T' I: V% ~
figure(1)
1 Y, Z, i" n6 H/ |plot(time,r,'r',time,y,'b');
4 n3 p* ?; |/ r5 q* |xlabel('Time(second)');ylabel('Position tracking');
0 {! D( H' @2 d8 E' s& |figure(2)) [/ @1 Y8 M# ^/ }1 q) _
plot(time,s,'r');
) c" M! W- O3 R6 y& X2 s: Yxlabel('Time(second)');ylabel('Switch function s');; {! a( c7 Y2 `1 N' E2 P. l" P$ Q0 X% Z
figure(3)1 K  M- V& b( `7 r2 \
plot(e,de,'r',e,-c*e,'b');
4 i% T4 R% ?$ Gaxis([0,0.0001,-0.001,0]);
9 X1 [$ Z( O7 [+ jxlabel('e');ylabel('de');: M5 l9 M! W; k- N& R7 W  g
figure(4)- y4 w: X( s( Z; N# d- [: j
plot(time,u,'r');3 I1 e0 ~3 N5 D3 Z# t2 t
xlabel('Time(second)');ylabel('u');/ F+ a# p1 R0 m% G* |
2 P  Y6 f# J8 ]) k, |& Q

作者: alair006    时间: 2012-2-7 16:30
我一天不来数学中国社区就不爽~~~~6476978636346710
作者: 守粮仓的鼠    时间: 2012-8-2 20:03





欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5