% QUADRATIC_DEMO generates quadratic equations and displays real roots.
% 
%  This script uses the functions:
%  * quadratic random ( )
%  * quadratic_roots_real ( )
%  * quadratic_evaluate ( )
%
for k = 1 : 10

  [ a, b, c ] = quadratic_random ( );
  r = quadratic_roots_real ( a, b, c );
  n = length ( r );

  if ( n == 2 )

    r_min = min ( r );
    r_max = max ( r );

    x = linspace ( r_min-1, r_max+1, 100 );
    y = quadratic_evaluate ( a, b, c, x );

    plot ( x, y, ...
           x, 0*y,':k', ...
           r_min, 0, 'or', ...
           r_max, 0, 'or', ... 'Linewidth', 3 )

    shg       % <- Bring graphics window to front!
    pause(2)  % <-Wait a few seconds.

  end

end

