forked from wedusk101/NumericalAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Derivative.txt
28 lines (20 loc) · 1.89 KB
/
Derivative.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#NumericalAnalysis
calcDerivative - Calculates the derivative of a function at a point. Non-symbolic as of now. We could consider
automatic differentiation or symbolic methods later on. One method which I am currently researching involves passing
a method as a parameter to this class/function. As we know, we don't have access to pointers to functions here.
We could use something like a Callable interface, although I suggest a different approach. Please let me know what you
guys think about it. So the basic structure of the method that I am working on right now is this.
public double calcDerivative(String func, String op, double var, double val);
This is the prototype of the method. Instead of passing the function method as a parameter, we parse the original
expression and generate string inputs for the calcDerivative method.For e.g. to find out the derivative of say a trigonometric
function, we first need to classify it as a triginometric function and identify the variable on which the function will be
operating. <String func> will contain the class of function like trigonometric, polynomial etc. <String op> will contain the
actual operation from among that class of function like sine, cosine etc. <double var> will have the variable with respect to
which we need to differentiate for e.g. x, y etc. Once we have the parameters we can further classify them and apply
first principles to calculate the derivative of the function at the required point given by <double val>.
For e.g. f(x) = 4x^3 + 3x^2 + 6 at x = 6. Here <double val> will contain x = 6.
We will have a variable delta with a very small value that will help us in calculating the derivative.
f(x + dx) - f(x)
The derivative: Lim dx -> 0 f'(x) = ----------------
dx
Again, please let me know what you guys think and update or add a different file with your changes here.