CS3343/3341
 Analysis of Algorithms 
Spring 2012
  Graph of log2(x)   
and Approx. Poly.

Graphs. Below are graphs of y = log2(x) (drawn in black), and of the following cubic equation (drawn in red) that approximates it to within 0.0015 on the interval 1 <= x <= 2.

public double approx(double x) {
   double a0 = -2.1718276908;
   double a1 =  3.0858266589;
   double a2 = -1.0780415294;
   double a3 =  0.1640425613;
   return a0 + a1*x + a2*x*x + a3*x*x*x;
}

This polynomial was chosen so that it had the same values and the same slopes as log2x at x=1 and x=2. Then it was still not as close as I wanted so I subtracted a very shallow additional parabola.


Revision date: 2012-04-06. (Please use ISO 8601, the International Standard Date and Time Notation.)