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

📄 demo_cond.m

📁 DEMO_COND demonstrates the role of the condition number of a matrix (with respect to inversion)
💻 M
字号:
%  DEMO_COND  demonstrates the role of the condition%  number of a matrix (with respect to inversion)%  in the role of linear system solving.%%  Matthias Heinkenschloss%  Department of Computational and Applied Mathematics%  Rice University%  Feb 22, 2001%clear; clc;set(0, 'defaultaxesfontsize',18,'defaultaxeslinewidth',1.2,...       'defaultlinelinewidth',1.2,'defaultpatchlinewidth',1.2,...       'defaulttextfontsize',18);disp(' Demonstrate the role of the condition number of a matrix ')disp(' (with respect to inversion) in the accuracy of the computed')disp(' solution of a linear system ')disp('                                           ')disp(' Hit a key to continue '); pauseclear;clc;disp('  Example 1                                ')disp('  Linear System with Hilbert matrix        ')disp('                                           ')fprintf(1, '  n    cond_inf(H)    || x_ex - x ||_inf/ ||x_ex||_inf  \n' );n1 = 4;n2 = 10;for n = n1:n2    x_ex           = ones(n,1);    H              = hilb(n);    b              = H*x_ex;    c(n-n1+1)      = cond(H,inf);    x              = H\b;    relerr(n-n1+1) = norm(x-x_ex,inf)/norm(x_ex,inf);        fprintf(1, ' %2d   %12.6e     %12.6e \n', n,  c(n-n1+1), relerr(n-n1+1)  );endsemilogy((n1:n2), c, 'k--'); hold onsemilogy((n1:n2), relerr, 'r-'); hold offxlabel(' n ')legend('cond_inf(H)', '|| x_{ex} - x ||_inf/ ||x_{ex}||_inf')%print -depsc hilbert_cond.epsdisp('                                           ')disp(' Hit a key to continue '); pauseclear;clc;disp('  Example 2                                ')disp('  Linear System with Vandermonde matrix    ')disp('                                           ')fprintf(1, '  n      cond_2(A)    || x_ex - x ||_2/ ||x_ex||_2 \n' );n1 = 4;n2 = 30;for n = n1:n2    t              = -1 + (2/(n-1))*(0:n-1)';    A              = zeros(n,n);    for j = 1:n        A(:,j)     = t.^(j-1);    end    x_ex           = ones(n,1);    b              = A*x_ex;    c(n-n1+1)      = cond(A,2);    x              = A\b;    abserr(n-n1+1) = norm(x-x_ex,2);    relerr(n-n1+1) = abserr(n-n1+1)/norm(x_ex,2);        fprintf(1, ' %2d      %12.6e     %12.6e \n', n,  c(n-n1+1), relerr(n-n1+1)  );endsemilogy((n1:n2), c, 'k--'); hold onsemilogy((n1:n2), abserr, 'r:'); hold onsemilogy((n1:n2), relerr, 'b-'); hold offxlabel(' n ')legend('cond_2(A)', '|| x_{ex} - x ||_2', '|| x_{ex} - x ||_2/ ||x_{ex}||_2')%print -depsc vandermonde_cond.eps

⌨️ 快捷键说明

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