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 个)

类别

Help CenterFile Exchange 中查找有关 Classical Control Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by