Home > . > lyapunov_symm.m

lyapunov_symm

PURPOSE ^

solves x-a*x*a'=b for b (and then x) symmetrical

SYNOPSIS ^

function [x,ns_var]=lyapunov_symm(a,b)

DESCRIPTION ^

 solves x-a*x*a'=b for b (and then x) symmetrical

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % solves x-a*x*a'=b for b (and then x) symmetrical
0002 function [x,ns_var]=lyapunov_symm(a,b)
0003   global options_ 
0004   
0005   info = 0;
0006   if size(a,1) == 1
0007     x=b/(1-a*a);
0008     return
0009   end
0010   [u,t] = schur(a);
0011   if exist('ordeig','builtin')
0012     e1 = abs(ordeig(t)) > 2-options_.qz_criterium;
0013   else
0014     e1 = abs(my_ordeig(t)) > 2-options_.qz_criterium;
0015   end
0016   k = sum(e1);
0017   if exist('ordschur','builtin')
0018     % selects stable roots
0019     [u,t] = ordschur(u,t,e1); 
0020     n = length(e1)-k;
0021     b=u(:,k+1:end)'*b*u(:,k+1:end);
0022     t = t(k+1:end,k+1:end);
0023   elseif k > 0
0024     % problem for Matlab version that don't have ordschur
0025     error(['lyapunov_sym: you need a Matlab version > 6.5 to handle models' ...
0026        ' with unit roots'])
0027   else
0028     % no unit root
0029     n = length(e1);
0030     b=u'*b*u;
0031   end
0032   x=zeros(n,n);
0033   for i=n:-1:2
0034     if t(i,i-1) == 0
0035       if i == n
0036     c = zeros(n,1);
0037       else
0038     c = t(1:i,:)*(x(:,i+1:end)*t(i,i+1:end)')+...
0039         t(i,i)*t(1:i,i+1:end)*x(i+1:end,i);
0040       end
0041       q = eye(i)-t(1:i,1:i)*t(i,i);
0042       x(1:i,i) = q\(b(1:i,i)+c);
0043       x(i,1:i-1) = x(1:i-1,i)';
0044     else
0045       if i == n
0046     c = zeros(n,1);
0047     c1 = zeros(n,1);
0048       else
0049     c = t(1:i,:)*(x(:,i+1:end)*t(i,i+1:end)')+...
0050         t(i,i)*t(1:i,i+1:end)*x(i+1:end,i)+...
0051         t(i,i-1)*t(1:i,i+1:end)*x(i+1:end,i-1);
0052     c1 = t(1:i,:)*(x(:,i+1:end)*t(i-1,i+1:end)')+...
0053          t(i-1,i-1)*t(1:i,i+1:end)*x(i+1:end,i-1)+...
0054          t(i-1,i)*t(1:i,i+1:end)*x(i+1:end,i);
0055       end
0056       q = [eye(i)-t(1:i,1:i)*t(i,i) -t(1:i,1:i)*t(i,i-1);...
0057        -t(1:i,1:i)*t(i-1,i) eye(i)-t(1:i,1:i)*t(i-1,i-1)];
0058       z =  q\[b(1:i,i)+c;b(1:i,i-1)+c1];
0059       x(1:i,i) = z(1:i);
0060       x(1:i,i-1) = z(i+1:end);
0061       x(i,1:i-1)=x(1:i-1,i)';
0062       x(i-1,1:i-2)=x(1:i-2,i-1)';
0063       i = i - 1;
0064     end
0065   end
0066   if i == 2
0067     c = t(1,:)*(x(:,2:end)*t(1,2:end)')+t(1,1)*t(1,2:end)*x(2:end,1);
0068     x(1,1)=(b(1,1)+c)/(1-t(1,1)*t(1,1));
0069   end
0070   x=u(:,k+1:end)*x*u(:,k+1:end)';
0071   ns_var = [];
0072   ns_var = find(any(abs(u(:,1:k)) > 1e-8,2));

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003