Doing a PCA using an optimization

The thing about Optimization is that there are different methods to solve a problem, some of which can require extensive computation.  Your solution, given the constraints for B, is to use fmincon. Start by creating a file for the non-linear constraints: