updated to use much less memory. removed equality constraint by changing equations to only use 1 var for Q