用多项式矩阵绘制系统的响应

时间:2014-03-09 23:23:03

标签: matlab control-theory

当系统,输入,输出矩阵是多项式时,如何绘制系统的时间响应?例如

A(x) = [0.59*x 1.67*x; 0.1 0.2]
B(x) = [2.3*x; 0.3]
C    = [1 0]
Operating region of x = [-2, 2]
Initial condition x(0) = [2 0]

如果矩阵不变,我可以使用sslsim来绘制它。但是,在这种情况下我该怎么做?我是Matlab和控制系统的新手。

1 个答案:

答案 0 :(得分:1)

使用您的示例,我将向您介绍MatLab中的一般ODE仿真的基本概念(在编程语言中非常相似)。

(首先,我假设你在A和B矩阵中写的x实际上是x1,因为你没有指定。我也从上下文假设你的状态向量是[x1 x2])。

创建一个接收

的函数
  • 当前时间,t_now
  • 当前状态向量,x_now
  • 完整输入数组,你
  • 全时阵列,t

并使用它们来计算状态导数(xdot)。正如您将看到的,仅需要全时数组(t)来索引控制输入(u)。基本上,它将是

的编码函数
xdot = f(t, x, u)

这是ODE的一般形式。

function xdot = myODE(t_now, x_now, u, t)

    A = [ 0.59*x_now(1), 1.67*x_now(1);
              0.1,            0.2      ] ;

    B = [ 2.3*x_now(1);
             0.3       ] ;

    u_now = interp1(t, u, t_now) ; % get u(t=t_now)

    xdot = A*x_now + B*u_now ;

end

接下来,使用像MatLab的ode45这样的ODE求解器创建一个运行模拟的脚本。如果您想知道这些求解器的工作原理,请阅读数值积分。 MatLab的ode45使用Runge-Kutta方法。

%// time range over which to compute simulation
t = [0 : 0.01 : 5] ;

%// define the input signal
%// why not make it zero to look at the natural response
u = zeros(1, length(t)) ;

%// initial condition
x0 = [2, -5] ;

%// call ode45
%// first argument: anonymous call to myODE that tells it which inputs to use
%// second argument: the time range for the simulation
%// third argument: the initial condition
%// first output: the sim time, may be more detailed than the original t
%// second output: the full output including all states
[t_out, response] = ode45(@(t_now, x_now) myODE(t_now, x_now, u, t), t, x0) ;

%// The response contains two column vectors: one for x1 and one for x2 at
%// every time in t. You can extract "the true output" which based on
%// your C matrix is x1.
y = response(:,1) ;

%// Plot results
plot(t, u, 'r--', t_out, y, 'k') ;
grid on ;
legend('input', 'output')
xlabel('time')
ylabel('value')

假设您没有将u作为预定义的输入信号,而是作为当前状态的函数。然后只需在myODE函数中修改u_now的计算。在最简单的情况下,u根本不是时间的函数,在这种情况下,你根本不需要将u或全时数组传递给myODE!例如,如果

u := -k*x1

然后您的ODE功能可以

function xdot = myODE(t_now, x_now)

    A = [ 0.59*x_now(1), 1.67*x_now(1);
              0.1,            0.2      ] ;

    B = [ 2.3*x_now(1);
             0.3       ] ;

    k = 5 ;
    u_now = -k*x_now(1) ;

    xdot = A*x_now + B*u_now ;

end

调用ode45

[t_out, response] = ode45(myODE(t_now, x_now), t, x0) ;

并且无需在脚本中定义u。

希望有所帮助!