% Recall the grade-school approximation to the number 𝜋.
p = 22/7

%%
format long
p

abs(p-pi)            % absolute accuracy
abs(p-pi)/pi         % relative accuracy
-log10(abs(p-pi)/pi)  % accurate digits

e = eps/2
(1.0 + e) - 1.0

1.0 + (e - 1.0)

c = [1,-3,3,-1]

function y = hornereval(c,x)
% HORNER   Evaluate a polynomial using Horner's rule. 
% Input:
%   c     Coefficients of polynomial, in descending order (vector)
%   x     Evaluation point (scalar)
% Output:
%   y     Value of the polynomial at x (scalar)

n = length(c);
y = c(1);
for k = 2:n
  y = x*y + c(k);
end
end

hornereval(c,1.6)

r = [-2.0,-1,1,1,3,6]
p = poly(r)

r_computed = sort(roots(p))

abs(r - r_computed')./r 

p_computed = poly(r_computed)

abs(p-p_computed)/p

a = 1.0;
b = -(1e6+1e-6);
c = 1.0;
x1 = (-b + sqrt(b*b-4*a*c)) / (2*a)

x2 = (-b - sqrt(b*b-4*a*c)) / (2*a)

-log10(abs(1e-6-x2)/1e-6 ) 

a = 1.0
b = -(1e6+1e-6)
c = 1.0

x1 = (-b + sqrt(b*b-4*a*c)) / (2*a)

x2 = c/(a*x1)
x2 - 1e-6


