(a, b, q, r)
return k, p
Compute the discrete-time LQR controller.

    The optimal control input is `u = -k.dot(x)`.

    Parameters
    ----------
    a : np.array
    b : np.array
    q : np.array
    r : np.array

    Returns
    -------
    k : np.array
        Controller matrix
    p : np.array
        Cost to go matrix
Compute the discrete-time LQR controller.
Compute the discrete - time LQR controller .
def dlqr(a, b, q, r):
    """Compute the discrete-time LQR controller.

    The optimal control input is `u = -k.dot(x)`.

    Parameters
    ----------
    a : np.array
    b : np.array
    q : np.array
    r : np.array

    Returns
    -------
    k : np.array
        Controller matrix
    p : np.array
        Cost to go matrix
    """
    a, b, q, r = map(np.atleast_2d, (a, b, q, r))
    p = scipy.linalg.solve_discrete_are(a, b, q, r)

    # LQR gain
    # k = (b.T * p * b + r)^-1 * (b.T * p * a)
    bp = b.T.dot(p)
    tmp1 = bp.dot(b)
    tmp1 += r
    tmp2 = bp.dot(a)
    k = np.linalg.solve(tmp1, tmp2)

    return k, p
def dlqr ( a , b , q , r ) : a , b , q , r = map ( np . atleast_2d , ( a , b , q , r ) ) p = scipy . linalg . solve_discrete_are ( a , b , q , r ) # LQR gain # k = (b.T * p * b + r)^-1 * (b.T * p * a) bp = b . T . dot ( p ) tmp1 = bp . dot ( b ) tmp1 += r tmp2 = bp . dot ( a ) k = np . linalg . solve ( tmp1 , tmp2 ) return k , p