function geppUnstableExampleDemo(n)
% demo the very rare example of GEPP being unstable
fprintf(‘n = %d\n’, n);
A = geppUnstableExample(n);
Copyright By PowCoder代写 加微信 powcoder
if n <= 10
if n <= 20
fprintf('n may be too small to see the instability. try n>=30\n’)
% fix solution in advance and use this to define b
xsol = randn(n);
b = A*xsol;
% solve Ax=b using backslash, which uses GEPP
resid_norm = norm(b – A*x);
error_norm = norm(x – xsol);
fprintf(‘solving Ax=b using the rare example gives\n’);
fprintf(‘ resid_norm = %g, error norm = %g\n’, resid_norm, error_norm’);
% now make a small perturbation to A and run the experiment again
fprintf(‘hit any key to continue’)
A = A + 1e-10*randn(n);
b = A*xsol; % leave xsol unchanged
resid_norm = norm(b – A*x);
error_norm = norm(x – xsol);
fprintf(‘making tiny perturbation to A and solving again\n’);
fprintf(‘ resid_norm = %g, error norm = %g\n’, resid_norm, error_norm’);
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com