%% BETA_CDF_ROOT seeks a roof of function BETA_CDF(X) - 0.7 = 0
%
clf

x = linspace ( 0, 1, 100 );
y = betacdf ( x, 0.45, 0.5 );
plot ( x, y, 'b-', 'LineWidth', 2 );
hold on

plot ( [0,1], [0.7,0.7], 'k-' );

a = 0.0
fa = betacdf ( a, 0.45, 0.5 );
plot ( a, fa, 'r*' )
fprintf ( 1, '  F(%f) = %f\n', a, fa );

b = 1.0
fb = betacdf ( b, 0.45, 0.5 );
plot ( b, fb, 'r*' );
fprintf ( 1, '  F(%f) = %f\n', b, fb );

while ( 1 )

  c = 0.5 * ( a + b );
  fc = betacdf ( c, 0.45, 0.5 );
  plot ( c, fc, 'r*', 'MarkerSize', 10 )
  plot ( [c,c], [0,fc], 'r-' );

  if ( fc - 0.7 < 0.0 )
    a = c;
  else
    b = c;
  end

  fprintf ( 1, '  F(%f) = %f\n', c, fc );

  if ( abs ( fc - 0.7 ) < 0.00001 )
    break
  end

end

xlabel ( 'X' )
ylabel ( 'CDF(X)' )
title ( 'Find CDF(X) = 0.7 using bisection' )


