Calculating the large-N phase transition in gauge and matrix models