#MonthOfJulia Day 20: Calculus
Mathematica is the de facto standard for symbolic differentiation and integration. But many other languages also have great facilities for Calculus. For example, R has the
deriv() function in the base
stats package as well as the numDeriv, Deriv and Ryacas packages. Python has NumPy and SymPy.
Let’s check out what Julia has to offer.
First load the Calculus package.
The derivative() function will evaluate the numerical derivative at a specific point.
There’s also a prime notation which will do the same thing (but neatly handle higher order derivatives).
Symbolic differentiation works for univariate and multivariate functions expressed as strings.
It also works for expressions.
Have a look at the JuliaDiff project which is aggregating resources for differentiation in Julia.
Numerical integration is a snap.
Compare that with the analytical result. Nice.
Revisiting the same definite integral from above we find that we now have an analytical expression as the result.
To perform symbolic integration we need to first define a symbolic object using
There’s more to be said about symbolic objects (they are the basis of pretty much everything in SymPy), but we are just going to jump ahead to constructing a function and integrating it.
What about an integral with constant parameters? No problem.
We have really only grazed the surface of SymPy. The capabilities of this package are deep and broad. Seriously worthwhile checking out the documentation if you are interested in symbolic computation.
I’m not ready to throw away my dated version of Mathematica just yet, but I’ll definitely be using this functionality often. Come back tomorrow when I’ll take a look at solving differential equations with Julia.