⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmuddu.m

📁 GPS TOOLBOX包含以下内容: 1、GPS相关常量和转换因子; 2、角度变换; 3、坐标系转换: &#61656 点变换; &#61656 矩阵变换; &#61656 向量变换
💻 M
字号:
%                             xmuddu.m
%  Scope:   This MATLAB program executes the decomposition and reconstruction 
%           of a real symmetric positive (semi)definite matrix into and from 
%           its U-D factors.
%  Usage:   xmuddu
%  Inputs:  - name of the output file if selected (the default is the screen)
%           - dimension of state vector  n, n >= 2
%           - elements of the input matrix A, real array of length  n*(n+1)/2, 
%             only the upper triangular part, columnwise, is stored
%           - computation accuracy (tolerance), selected default is machine
%             dependent accuracy  eps
%  Outputs: - input/output data stored into the specified output file or
%             displayed on screen
%  External Matlab macros used:  mcud, msc2f, mudc2f, mudd
%  Last update:  07/21/00
%  Copyright (C) 1996-00 by LL Consulting. All Rights Reserved.

clear
yes = 'y';
answer2 = yes;

%  Specify the input data

disp('  ');
answer1 = input('Do you want to save the results? (y/n)[n] --> ','s');
if isempty(answer1)
   answer1 = 'n';
end   
disp('  ');
if (strcmp(answer1,yes) == 1)
   f2 = input('Specify the output filename  -->  ','s');
   disp('  ');
else
   f2 = 1;      %  output to the screen
end

while (strcmp(answer2,yes) == 1)

   answer3 = input('Do you want to enter data from keyboard? (y/n)[y] --> ','s');
   disp('  ');
   if  isempty(answer3)
      answer3 = yes;
   end
   if (strcmp(answer3,yes) ~= 1)
   
%     Read the input data file (all data stored columnwise)

      clear  a
      f1 = input('Specify the input filename (with extension) --> ','s');
      disp('  ');
      a = load(f1);
      [nrow,ncol] = size(a);
      n = 0.5 * (sqrt(1. + 8. * nrow) - 1);
      nn1 = nrow;

   else

%     Enter data from keyboard

      n = input('Specify the dimension of the matrix, n --> ');
      disp('  ');
      nn1 = n * (n + 1) / 2;
      disp('Specify the input matrix  A, n*(n+1)/2  elements  ');
      disp('Enter upper triangular part only, columnwise, element-by-element --> ');
      disp('  ');
      for k = 1:nn1
         a(k) = input('  ');
      end
      disp('  ');
   end
   meps = eps;

%  Save or display the input data

   afull = msc2f(n,a);
   fprintf(f2,'*****   Input data   *****  \n');
   fprintf(f2,'\n     Full symmetric matrix \n');
   for k = 1:n
      for kk = 1:n
         fprintf(f2,'%14.4e  ',afull(k,kk));
      end
      fprintf(f2,'\n');
   end   
   fprintf(f2,'\n     Tolerance, eps = %8.4e \n\n',meps);
   
%  Decompose the input matrix in U-D factors by using macro  mudd

   [ud,ier] = mudd(n,a,meps);
   fprintf(f2,'*****   Results from macro  mudd  (U-D decomposition)  *****\n\n');
   fprintf(f2,'Index of error, ier =  %3.0f \n\n',ier);

   if ier == 0
      [ufull,dfull] = mudc2f(n,ud);
      fprintf(f2,'     U  matrix (output) - unit upper triangular matrix \n');
      for k = 1:n
         for kk = 1:n
            fprintf(f2,'%14.4e  ',ufull(k,kk));
         end
         fprintf(f2,'\n');
      end   
      fprintf(f2,'\n');
      fprintf(f2,'     D  matrix (output) - diagonal matrix \n');
      for k = 1:n
         for kk = 1:n
            fprintf(f2,'%14.4e  ',dfull(k,kk));
         end
         fprintf(f2,'\n');
      end   
      fprintf(f2,'\n');
      
%     Reconstruct the matrix from its U-D factors by using macro  mcud

      p = mcud(n,ud);
      fprintf(f2,'*****   Results from macro  mcud  (without overwriting)');
      fprintf(f2,'   *****  \n');
      fprintf(f2,'     Reconstruction of symmetric matrix from its U-D factors\n');
      pfull = msc2f(n,p);
      for k = 1:n
         for kk = 1:n
            fprintf(f2,'%14.4e  ',pfull(k,kk));
         end
         fprintf(f2,'\n');
      end   
      fprintf(f2,'\n');
     
%     Reconstruct the matrix from its U-D factors when the input matrix 
%     is overwritten by the resultant matrix

      ud = mcud(n,ud);
      fprintf(f2,'*****   Results from macro  mcud  (with overwriting)');
      fprintf(f2,'   *****  \n');
      fprintf(f2,'     Reconstruction of symmetric matrix from its U-D factors\n');
      pfull = msc2f(n,ud);
      for k = 1:n
         for kk = 1:n
            fprintf(f2,'%14.4e  ',pfull(k,kk));
         end
         fprintf(f2,'\n');
      end   
      fprintf(f2,'\n');
      
   end

%  Select another computation, if desired

   answer2 = input('Do you want another computation? (y/n)[n] --> ','s'); 
   if  isempty(answer2)
      answer2 = 'n';
   end
   fprintf(f2,'\n**************************************************************\n');
   disp('  ');

end

disp('End of the program XMUDDU');
disp('  ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -