Energy minimization errors

Answered here: Erorr in energy minimization - #4 by jalemkul

Please do not spam with duplicate topics.