[問題] 程式錯誤,不知道這是怎樣QQ已回收

看板MATLAB作者 (saber.c)時間14年前 (2010/04/12 17:08), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
小弟初學MATLAB,照著老師的例子改成我自己的函式,可是一執行就出現一堆錯誤QQ 以下是程式碼 xd=80; for k=1:1000 tspan = dt*[(k-1) (k-0.5) k] ; e=x0(1)-xd; %此次輸出與期望輸出的誤差 e_dot=e-e0;%這次誤差 和上次誤差比較 s=e_dot+lunda*e; %sliding surface Ueq=1.5*e_dot.^2*cos(3.*x0(1))-20.*e_dot Uhit=(0.5*e_dot.^2*abs(cos(3.*x0(1)))+0.1)*sign(s); u=Ueq+Uhit; fprintf('sign(s)=%f\n',sign(s)); fprintf('x=%f xd=%f s=%f uh=%f ueq=%f u=%f\n',x,xd,s,Uhit,Ueq,u); [t,x]=ode23('ztwoorder',tspan,x0); x0=x(3, :); e0=e; end plot(t,x) function SIGN_FUN=sign_fun(s) if s>=0 SIGN_FUN=1; else SIGN_FUN=-1; end ---------------分隔線---------------------------- function xdot=ztwoorder(t,x) global u xdot=[x(2); -1.5*x(2).^2*cos(3.*x(1))+u ]; -------------------------------------------------- 執行後出現 ??? Attempted to access x(2); index out of bounds because numel(x)=1. Error in ==> ztwoorder at 10 xdot=[x(2); Error in ==> funfun\private\odearguments at 110 f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0. Error in ==> ode23 at 172 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ... Error in ==> slotine at 44 [t,x]=ode23('ztwoorder',tspan,x0); 這個錯誤 我實在不懂??? Q_Q 請大大解說一下好嗎>< ps.小弟因突然需要一些控制理論才練習matlab 之前是寫晶片程式,所以C這邊看的懂 但是這邊的錯誤,實在沒辦法理解!!>< 拜託各位了!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.130.22.88

04/13 10:40, , 1F
請注意錯誤的訊息
04/13 10:40, 1F

04/13 10:41, , 2F
attemped to access x(2) 是說你的X(2)這個值是不存在的
04/13 10:41, 2F

04/13 13:24, , 3F
可是我看書上範例下去改的qq 書上也是這種形式q_q
04/13 13:24, 3F

04/13 13:24, , 4F
我的原本函式 X''=1.5X'^2COS3X+U
04/13 13:24, 4F

04/13 13:50, , 5F
檢查了一下 發現是錯在Ode那段 但是無從下手Q_Q
04/13 13:50, 5F
文章代碼(AID): #1BmkC0-0 (MATLAB)