Loading editor...

Using optimization to setup a problem quickly

Loading commands, almost done…

You are given a square with a point in it. It is situated at a distance of 1, 2 and 3 units respectively from vertices , and i.e. , and . What is angle ?

Instead of tediously calculating the values of and , we can use optimization to find a good enough approximation as a starting point.

Initial setup

These commands set up the loss function to minimize. We want the distances from to the vertices to match 1, 2, and 3. We do not know the length of each side of the square or the exact location of the point . We start with an initial guess:


Draw lines from to each vertex:


Using gradient-descent

We can use autograd and gradient-descent to find the optimal values for and .


Finally, define number of iterations and train using minimize command:

In less than a second, it finds close enough values for and point .


Verifying the result

Now let's highlight the key elements:


Moving on to the solution

The key intent of this article is to showcase a good application of gradient descent to quickly set up the premise of a geometric problem. It is not to provide the exact solution to it (which can be found here). So instead of providing a complete solution, we will skip over a few steps.


  • Rotate the triangle about by

It can be shown that are collinear, which leads to the solution: is equal to .


Numerical verification

It should be close enough to .