Numerical Python
My experiments with Python continues on. This time it’s playing with the numerical and plotting capabilities of Python.
The shortest path between two points on a plane is the straight line connecting the two points. There’s a way to derive the equation of the shortest path using variational calculus. This experiment derives such an equation by doing a high dimensional gradient descent on the space of equations that satisfy the Euler-Lagrange equation.
We are looking for a curve that minimizes the arc length between the
two points. We define y(x) as the curve, y_x as the x differential
of y.
![I[y] = \int_a^b \sqrt{1 +(y_x(x))^2} dx I[y] = \int_a^b \sqrt{1 +(y_x(x))^2} dx](http://ergodicity.iamganesh.com/wp-content/latexrenderer/pictures/f8c178cb7f40eca36fd57864859c06d2.gif)
The corresponding Euler-Lagrange equation is

The plot below was generated by matplotlib, a plotting library that is almost exactly similar to the Matlab plotting interface. I was surprised at how close Python code can be to Matlab code. Nowhere in my code do I have to loop over the dimensions of the vectors. The numerical calls are passed over to high performance math routines written in Fortran. The initial condition was a sine wave and you can see that it eventually converges to the true solution.

Get the code here.
[...] a heavy user of the numerical capabilities of Python. I’ve written about my experiments before, but now I’m writing production quality code with numpy and [...]