%
% 改进的平方根法求解 Hilbert 线性方程组
%
clear all; 
close all;

n = 16;
H = hilb(n);
xtrue = ones(n,1);
b = H*xtrue;

% 计算 LDL^T 分解
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%  这里是你的代码  %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 解方程 Ly = b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%  这里是你的代码  %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 解方程 D L^T x = y
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%  这里是你的代码  %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 输出结果
fprintf('相对残量为: %.4e\n', norm(b-H*x)/norm(b));
fprintf('相对误差为: %.4e\n', norm(x-xtrue)/norm(xtrue));
plot(1:n,x,'+', 1:n,xtrue,'o');
legend('数值解', '精确解');


