Solving optimization problem with matrix variable

I get a non-conformable array error

Error in dr(Xdr1) - d : non-conformable arrays

which is odd because there's no Xdr1 in namespace. Could you post your code in the form of a reprex (see the FAQ), please?