Improving the program
There is a slight improvement that we will leave as an exercise to the reader. If you run the program as it is presented here, you will note that it runs rather slowly. The reason for this is that we approximate the gradient. This is computationally costly since it involves multiple evaluations of the Sammon error function. We could do better than this. We can implement the gradient calculation ourselves. The formula to calculate the gradient is given in the equation here.
The notation in the equation is the same as earlier. The equation will calculate the value of the gradient at the kth coordinate of the ith vector of the approximation. Keep in mind that, since the stress function in our case is 300-dimensional, it means that to approximate the derivative you will need to evaluate the function at least 600 times (if the simplest method for approximating derivatives is used); that is, if you choose to approximate the derivative. We can implement the calculation of the...