MATLAB: Different Solution for “quadprog” and “lsqlin” in R2017a when using dense matrices

densedifferentlsqlinMATLABquadprogr2017asolutionssparse

I am getting a different solution when I use "quadprog" and "lsqlin" in R2017a and later than the one I obtain in earlier releases. I am using dense matrices as input. How can I fix this?

Best Answer

In R2017a, there were changes to an internal algorithm used in both "quadprog" and "lsqlin" that can improve performance for both functions when used with dense matrix inputs. One consequence is that solutions may differ slightly than before.
To obtain the same solution as in previous releases, pass the matrix in sparse form.
For more details about these changes, see the Optimization Toolbox Release Notes: