HOW TO SLOVE ODE WITH AN CONTROL INPUT?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello I'm trying this Question :
dx/dt = 0.5*x + 10*u + 30*sin(t)
error signal e(t) = 3
if x>=e(t), u = -0.45*x
if x<e(t), 'u' retains its previous value
I've tried this code:
function dx=sys(t,x)
dx=0.5*x + 10*u + 30*sin(t)
end
Please save the above function in an MATLAB file and name is as sys.m
Then, in a separate MATLAB script file or in the command window, you can simulate the system by executing the following
>> u(0) = 0;
>> tspan = [0 10];
>> iniCon = [0]
>> [t, x] = ode45(@sys, tspan, iniCon);
>> for k=1:10
>> if x(k)>=et
>> u(k)=-0.45*x(k);
>> else
>> u(k)=u(k-1);
>> end
>> end
>> figure(1)
>> plot(t,x)
but I,m getting errors like :
"Subscript indices must either be real positive integers or logicals.
Error in firstplot (line 1) u(0) = 0;"
please help me out for solving this problem
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Classical Control Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!