Based on what is said in the comments it appears you are solving an under-determined system. That is because the number of samples $N$ is smaller than your number of features $D_1$. Because of this issue one will be always faced with rank deficiency of the design matrix; the thread What is rank deficiency, and how to deal with it? gives more information on the matter.
Notation-wise, as discussed is will be better if one uses standard notation where the number of samples $N$ represent the number of rows rather than the number of columns in the design matrix used. As mentioned the general idea one needs to remember when making this change is that $(AB)^T = B^TA^T$.
As mentioned both by me and @Matthew Drury you should seriously avoid using pinv
unless it is explicitly stated in the algorithm you use (so the authors say something like "taking the Moore-Penrose pseudoinverse"). You should use mldivide
( linspace
is also an option but it is redundant in your scenario, the Computational Science SE on what differences are between linsolve and mldivide?what differences are between linsolve and mldivide? can offer more clarificaitons on the matter).