Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Full State Feedback in MATLAB

  1. Aug 16, 2008 #1
    Hi everyone,

    I have a small MATLAB problem which arose while trying to solve a full state feedback problem in control theory.

    I have a system in state variable form

    [tex]\dot{x} = Ax + Bu[/tex]
    [tex]y = Cx[/tex]

    where [itex]u = -Kx[/itex], so the system reduces to

    [tex]\dot{x} = (A-BK)x[/tex]

    The solution is

    [tex]x(t) = exp((A-BK)t)x(0)[/tex]

    I know [itex]x(0)[/itex], A, B and K and want to plot

    [tex]y(t) = Cexp((A-BK)t)x(0)[/tex]

    as a function of time t.

    This is the code I used to compute the state transition matrix

    Code (Text):

    function [phi] = statetrans(A)
      t = sym('t');
      phi = expm(A * t);
    And here is the code to compute y

    Code (Text):

    A = [0, 1, 0, 0;4.4537,0,0,0;0,0,0,1;-0.5809,0,0,0];
    B = [0;-0.3947;0;0.9211];
    C = [0,0,1,0];
    K = place(A,B,[-3,-2,-2+j,-2-j]); % this is used to determine the feedback gain after placing closed loop zeros at the desired location

    x0 = [0.01;0.01;0.1;0.1]; % initial state

    % The real code starts below
    phi = statetrans((A-B*K));
    x   = phi*x0;
    y   = C*x;
    The problem is that y is a symbolic function of t. How can I plot y as a function of t for t in some range (using something like t = 0:0.01:10)?

    Code (Text):

    >> t = 0:0.01:10;
    >> plot(t,y);
    ??? Error using ==> plot
    Conversion to double from sym is not possible.
    Thanks in advance.

  2. jcsd
  3. Aug 16, 2008 #2
    Got it, can use ezplot.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook