So is A given, or do you also need to solve for A? If it’s given, the optimal solution for x (i.e., x*) w.r.t. to the mean squared error is x* =y times pinv(A). where pinv is the pseudo inverse. Also y is a colum stack matrix of all y, and so is A.