% construct an ill-conditioned linear system A = eye(10) for k = 2:10 A(k-1,k) = 10; end; b = A*ones(10,1); % Try to solve the equation A*x=b, got correct solution format long; x = A\b % Try to create a nearby problem d = b + rand(10,1)*0.000001 % solution of a nearby problem y = A\d % Another nearby problem A*z = g g = b/3; z = A\g % Backward error disp("backward error") norm(A*z-g) disp("forward error") norm(ones(10,1)/3-z) disp("condition number") cond(A) % % Demo for solving polynomial equations with multiple zeros % create a polynomial of given roots % p = poly([1 1 1 1 1 2 2]) % % try to find roots % z = roots(p)