You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: decorrel.m
    path of file: ./repos/nav_matlab/example/gps_spp_test/easysuite
    
    the code of the file until where you have to start completion: function [Q,Z,L,D,z] = decorrel (Q,a)
%DECORREL: Decorrelate a (co)variance matrix of ambiguities
%
% This routine creates a decorrelated Q-matrix, by finding the
% Z-matrix and performing the corresponding transformation.
%
% The method is described in:
% The routine is based on Fortran routines written by Paul de Jonge (TUD)
% and on Matlab-routines written by Kai Borre.
% The resulting Z-matrix can be used as follows:
% z = Zt * a; \hat(z) = Zt * \hat(a);
% Q_\hat(z) = Zt * Q_\hat(a) * Z
%
% Input arguments:
%   a: Original ambiguities
%   Q: Variance/covariance matrux of ambiguities (original)
%
% Output arguments:
%   Q: Decorrelated variance/covariance matrix
%   Z: Z-transformation matrix
%   L: L matrix (from LtDL-decomposition of Q, optional)
%   D: D matrix (from LtDL-decomposition of Q, optional)
%   z: Transformed ambiguities (optional)

% ----------------------------------------------------------------------
% Function.: decorrel
% Date.....: 19-MAY-1999
% Author...: Peter Joosten
%            Mathematical Geodesy and Positioning
%            Delft University of Technology
% ----------------------------------------------------------------------

% -----------------------
% --- Initialisations ---
% -----------------------

n    = size(Q,1);
Zti  = eye(n);
i1   = n - 1;
sw   = 1;


    
function [Q,Z,L,D,z] = decorrel (Q,a)
%DECORREL: Decorrelate a (co)variance matrix of ambiguities
%
% This routine creates a decorrelated Q-matrix, by finding the
% Z-matrix and performing the corresponding transformation.
%
% The method is described in:
% The routine is based on Fortran routines written by Paul de Jonge (TUD)
% and on Matlab-routines written by Kai Borre.
% The resulting Z-matrix can be used as follows:
% z = Zt * a; \hat(z) = Zt * \hat(a);
% Q_\hat(z) = Zt * Q_\hat(a) * Z
%
% Input arguments:
%   a: Original ambiguities
%   Q: Variance/covariance matrux of ambiguities (original)
%
% Output arguments:
%   Q: Decorrelated variance/covariance matrix
%   Z: Z-transformation matrix
%   L: L matrix (from LtDL-decomposition of Q, optional)
%   D: D matrix (from LtDL-decomposition of Q, optional)
%   z: Transformed ambiguities (optional)

% ----------------------------------------------------------------------
% Function.: decorrel
% Date.....: 19-MAY-1999
% Author...: Peter Joosten
%            Mathematical Geodesy and Positioning
%            Delft University of Technology
% ----------------------------------------------------------------------

% -----------------------
% --- Initialisations ---
% -----------------------

n    = size(Q,1);
Zti  = eye(n);
i1   = n - 1;
sw   = 1;

% --------------------------
% --- LtDL decomposition ---
% --------------------------

[L,D] = ldldecom (Q);

% ------------------------------------------
% --- The actual decorrelation procedure ---
% ------------------------------------------


while sw;

   i  = n;
   sw = 0;

   while ( ~sw ) && (i > 1)

      i = i - 1;
      if (i <= i1); 
      
         for j = i+1:n
            mu = round(L(j,i));
            if mu ~= 0
               L(j:n,i) = L(j:n,i) - mu * L(j:n,j);
               Zti(1:n,j) = Zti(1:n,j) + mu * Zti(1:n,i);
            end