# v_dlyapsq

## PURPOSE

V_DLYAPSQ Solves the discrete Lyapunov equation AV'VA' - V'V + BB' = 0

## SYNOPSIS

function v=v_dlyapsq(a,b)

## DESCRIPTION

    V_DLYAPSQ Solves the discrete Lyapunov equation AV'VA' - V'V + BB' = 0
     V is upper triangular with real non-negative diagonal entries
     this is equivalent to v=chol(dlyap(a,b*b')) but better conditioned numerically

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function v=v_dlyapsq(a,b)
    0002 %V_DLYAPSQ Solves the discrete Lyapunov equation AV'VA' - V'V + BB' = 0
    0003 % V is upper triangular with real non-negative diagonal entries
    0004 % this is equivalent to v=chol(dlyap(a,b*b')) but better conditioned numerically
    0005
    0006 %      Copyright (C) Mike Brookes 2002
    0007 %      Version: $Id: v_dlyapsq.m 10865 2018-09-21 17:22:45Z dmb $
    0008 %
    0009 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0010 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0011 %
    0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0013 %   This program is free software; you can redistribute it and/or modify
    0014 %   it under the terms of the GNU Lesser General Public License as published by
    0015 %   the Free Software Foundation; either version 3 of the License, or
    0016 %   (at your option) any later version.
    0017 %
    0018 %   This program is distributed in the hope that it will be useful,
    0019 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0020 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0021 %   GNU Lesser General Public License for more details.
    0022 %
    0023 %   You can obtain a copy of the GNU Lesser General Public License from
    0024 %   https://www.gnu.org/licenses/ .
    0025 %
    0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0027
    0028 [q,s]=schur(a');
    0029 [q,s]=rsf2csf(q,s);
    0030 [qd,r]=qr(b'*q,0);
    0031 % save r for testing
    0032 r0=r;
    0033 [m,n]=size(r);
    0034 u=zeros(n,n);
    0035 if m==1
    0036    for i=1:n-1
    0037       in=i+1:n;
    0038       si=s(i,i);
    0039       aa=sqrt(1-si*si');
    0040       u(i,i)=r(1)/aa;
    0041       u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(2:end))/(eye(n-i)-si'*s(in,in));
    0042       r=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(2:end);
    0043    end
    0044    u(n,n)=r/sqrt(1-s(n,n)*s(n,n)');
    0045
    0046 else
    0047    w=zeros(m,1); w(m)=1;
    0048    em=eye(m);
    0049    for i=1:n-m
    0050       in=i+1:n;
    0051       si=s(i,i);
    0052       aa=sqrt(1-si*si');
    0053       u(i,i)=r(1,1)/aa;
    0054       u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(1,2:end))/(eye(n-i)-si'*s(in,in));
    0055       vv=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(1,2:end);
    0056       rr=zeros(m,n-i);
    0057       rr(1:m-1,:)=r(2:end,2:end);
    0058       [qq,r]=qrupdate(em,rr,w,vv');
    0059    end
    0060    for i=n-m+1:n-1
    0061       in=i+1:n;
    0062       si=s(i,i);
    0063       aa=sqrt(1-si*si');
    0064       u(i,i)=r(1,1)/aa;
    0065       u(i,in)=(u(i,i)*si'*s(i,in)+aa*r(1,2:end))/(eye(n-i)-si'*s(in,in));
    0066       vv=aa*(u(i,i)*s(i,in)+u(i,in)*s(in,in))-si*r(1,2:end);
    0067       rr=zeros(n-i+1,n-i);
    0068       rr(1:n-i,:)=r(2:end,2:end);
    0069       [qq,rr]=qrupdate(eye(n-i+1),rr,w(m-n+i:end),vv');
    0070       r=rr(1:n-i,:);
    0071    end
    0072
    0073    u(n,n)=r/sqrt(1-s(n,n)*s(n,n)');
    0074
    0075 end
    0076
    0077 v=triu(qr(u*q'));
    0078 dv=diag(v);
    0079 ix=dv~=0;
    0080 v(ix,:)=diag(abs(dv(ix))./dv(ix))*v(ix,:);
    0081 if isreal(a) & isreal(b)
    0082    v=real(v);
    0083 end