HOW TO SLOVE ODE WITH AN CONTROL INPUT?

2 ビュー (過去 30 日間)
SRIJI SREENIVASAN
SRIJI SREENIVASAN 2018 年 8 月 5 日
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 件)

カテゴリ

Help Center および File ExchangeClassical Control Design についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by