[問題] 程式錯誤,不知道這是怎樣QQ已回收
小弟初學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
04/13 10:41, 2F
→
04/13 13:24, , 3F
04/13 13:24, 3F
→
04/13 13:24, , 4F
04/13 13:24, 4F
→
04/13 13:50, , 5F
04/13 13:50, 5F