# Derivative Calculator

### v1

This Derivative Calculator is mainly a build up of functions that come together to find the derivative of an input mathematical expression. The main principle of this project was to build everything from scratch, as a challenge, not only to develop my proficiency in python but also to attempt to build something useful to me in my studies. As a result, there are many parts of this script that already exist in a much cleaner fashion in other Python modules, for example the scipy.misc.derivative function, which can find the derivative of an expression at any given point.

The script works on the basis of slicing and replacing strings; all inputs from the user are strings, or lists of strings. This means that the most basic functions in the code include replacing specific instances of a substring within a string, or iterating through the string to return all numeric digits. The whole calculator essentially works on this basis; it has steps in logic based on what can be expected in a mathematical expression, for example:

• Checking the "function" type in the expression (sin, cos, natural log)
• Checking for powers in the expression (e2x, x4)
• Checking the coefficient of the expression
• Evaluating the necessary steps of differentiation based on what is present

The current build stage of the code is working on quotient differentiation (fractions), while also cleaning and finalising product differentiation (multiple functions or variables in an expression, e.g. x2e5x). Functions for division already exist within the script, along with functions for multiplication, but these have not been incorporated for quotients yet.

The calculator started life as an attempt at building a Maclaurin expander, to approximate complicated functions for physics. After realising that derivatives of functions would be necessary, that was decided as a good place to start.

The logic in the script works on the basis of separating jobs in such way that they can be concatenated at the end. For example, the function "funcmult" will take any list of string inputs and only multiply the expressions it recognises to contain functions (e.g. ln, sin, cos). However, this doesn't restrict the input to these options. For example, an input of ["x2exsinx","lnxcosx"] will multiply in the function to return "sinxcosx". This, in conjunction with multiplicative functions ("varimult","emult",etc.) allow each separate part of the multiplication to be evaluated and then simply concatenated at the end, leading to a shorthand function "multiply" which is essentially just the concatenation stage.

Functions work in this sense for multiplication, division and differentiation, which are separated out in the script. This project is certainly the most in-depth Python project I have ever worked on, using all sorts of mechanisms from lambda functions to dictionaries to raising exceptions. Comprising of more than 1300 lines of code, the testing section has been included so that the user can experiment for themselves and have some idea of how the script works.

### Click the image below to download the Derivative Calculator: 