For the final project I plan to create an online graphing calculator.
The basic function is to draw the curve of the given function. I plan to create an array of points which store its own x-value, y-value, x-coordinate and y-coordinate. I need to use map() function to map its x-value to the x-coordinate. Then I just draw a point at each x and y coordinate. The points will form the curve of the function. So its draw() will be like this:
For the expression function I will use the Javascript math library which includes all the basic math functions. But the difficult part is how to convert user input into programming language. I will think about it later.
Since the curve is essentially an array of points. It can easily achieve some functions of a graphing calculator. I plan to add these several functions:
- Find the maxima and minima. The Math library itself includes min() and max() functions to find the minima and maxima among certain values. Then I find out there are functions that return the maxima and minima of an array: the getMaxOfArray() and getMinOfArray(). They seem to be the solution to my problem. I will read the reference and figure it out.
- Find the roots of a function. I will use Newton Method to find the roots. I’ll search for examples of its algorithm.
- Find its derivative at a point. I will use the definition of derivative. It is simply the slope of the line connecting two consecutive points.
- Find its integral over a range. I will use Riemann Integral. Its integral is the sum of areas of the rectangles between the curve and the line y=0.