% Random Quadratics
%
% This estimates the probability that the quadratic
% q(x) ax^2 + bx + c has two real roots given that the coefficients
% a, b, and c are randomly selected from the interval [-1,1]

N = 1000000; % the number of trials
count = 0;
for k=1:N
a = -1+2*rand;
b = -1+2*rand;
c = -1+2*rand;
d = b*b-4*a*c;
if d>=0
count = count+1;
end
end
prob = count/N;
fprintf('N = %1d Prob Estimate = %10.6f\n',N,prob)

% Modify so that the script estimates the probability that the roots are
% real and both to the right of the origin.

% Modify so that the script estimates the probability that the roots
% are real and that the magnitude of the larger root is greater that 1/10

% Modify so that the script estimates the probability that roots are
% real and opposite in sign.