Function Analyzer

?

Click Evaluate to plot a function over a given x interval, and find its minimum, maximum, and area.
Results are generated using recursive numerical integration and differentiation algorithms implemented in JavaScript.

 

Function of x:


Enter a mathematical JavaScript expression using variable x.


Interval: to

The range of x to evaluate over.


Tolerance:   

The desired degree of accuracy. A smaller value like 0.00001 gives more precise results, and calculates more points.

Function Analyzer is like plot mode in a graphing calculator.

— project 1

It draws the plot of a function. Calculations are done in JavaScript (See the code on GitHub) using bare bones numerical methods — it only uses addition, subtraction, multiplication, and division operations to do calculus.

It finds the function's minimum value, maximum value, inflection points, and area using a combination of recursive algorithms.

1) scout(); — It starts with a recursive algorithm that adaptively calculates the area of the function using a form of adaptive quadrature. Less calculations are done when the function doesn't vary much. So, simple functions like f(x) = x2 + 2 don't cost much to plot. I'm using Simpson's rule to calculate each subinterval's area. You control the degree of accuracy. It stops when the next area minus the current area is less than the given tolerance.

The points from the area calculation are then used to find inflection points (where the derivative is equal to 0). The inflection points are calculated using two steps:

2) forage(); — It does a quick global scan over all the resulting points from #1 to find the intervals that contain inflection points (where the derivative is equal to 0). I'm calculating the slope for an interval, and the slope of its adjacent interval, then mulitplying them together. If it's negative, that means the slope changed direction and the derivative must be zero at somepoint in the range of both intervals. The inflection points are somewhere inside them, not sure exactly where yet.

3) capture(); — It does slower local calculations inside the intervals that contain inflection points. It recursively divides these intervals into smaller chunks to narrow in on the inflection points. You decide the degree of accuracy. It stops when the interval is smaller than the given tolerance. I'm using 5 point difference methods at this step to get very precise derivate values as the chunks get smaller and smaller.

4) sortMergeData(); getMinMax(); displayResults(); plotPoints(); — Finally, the array of inflection points is sorted by the f(x) values, from smallest to largest. The first element is the global minimum value, and the last element is the global maximum value. The plot is drawn using Google Charts.

These algorithms are based on my final project for my Numerical Analysis class back in college timez.

— Grayson