a131.m

来自「matlab算法集 matlab算法集」· M 代码 · 共 36 行

M
36
字号
       %----------------------------------------------------------------
       % Example a1.3.1: Linear Algebraic Systems
       %----------------------------------------------------------------

       % Initialize

       clc                      % clear command window  
       clear                    % clear variables
       randinit(1000)           % select random sequence
       n = 5;                   % number of variables
       m = 250;                 % maximum iterations
       tol = 1.e-6;             % error tolerance
       alpha = 1.5;             % relaxation parameter 
       B = randu (n,n,-1,1);
       b = randu (n,1,-1,1);
       A = B'*B;

       % Solve system

       fprintf ('Example a1.3.1: Linear Algebraic Systems\n');
       show ('A',A)
       show ('b',b)
       show ('det(A)',det(A))
       show ('inv(A)',inv(A))
       show ('K(A)',condnum(A,0))
       x = gauss (A,b);
       show ('Gaussian elimination solution',x)
       show ('||r||',residual(A,b,x))
       x = zeros(n,1); 
       [x,k] = sr (x,A,b,alpha,tol,m);
       show ('Number of iterations',k);
       show ('Successive relaxation solution',x)
       show ('||r||',residual(A,b,x))
       %----------------------------------------------------------------

⌨️ 快捷键说明

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