Least square problems can be modeled like any other problem with TomSym. The following is an L2-norm solution:

% Least square example from YALMIP wiki.

x = [1 2 3 4 5 6]';
t = (0:0.02:2*pi)';
a = [sin(t) sin(2*t) sin(3*t) sin(4*t) sin(5*t) sin(6*t)];
e = (-4+8*rand(length(a),1));
e(100:115) = 30;
y = a*x+e;

%Define the variable we are looking for
toms 6x1 x_hat

%By using x_hat and the regressors a, we can define the residuals
residuals = y-a*x_hat;

%The L2 problem is easily solved as a QP problem without any constraints.
solution = ezsolve(residuals'*residuals,[]);