Solving regularized least squares problems using Matlab optimization toolbox I am trying to solve a least squares problem where the objective function has a least squares term along with L1 and L2 norm regularization. I am unable to find which matlab function provides the ability to perform such an optimization in addition to specifying constraints. I looked into the MATLAB optimization toolbox which also does not provide too much freedom to specify own objective functions (although I hope I am wrong in this case!) in the case of leastSquares optimization problems. If anyone knows how to model such an optimization problem in matlab please do help me out. The optimization problem is as follows:

Here aj is an m X 1 vector and A is an mXn matrix , wj is an n x 1 vector. I don't know how to incorporate the two additional regularization terms into the optimization problems as they only accept 2 matrices and perform the least squares operation on them. I would like to know how to implement this objective function and pass it into matlab optimization toolbox leastSquares function. Any help would be appreciated.
 A: If you don't have the Statistics Toolbox or cannot use lasso for some reason, consider the following:
function myfun
load hald
A = [ones(13,1),ingredients];
fmincon(@(w) myobj(A,heat,w,1,0),rand(5,1),[],[],[],[],zeros(5,1))

function out = myobj(A,a,w,beta,lambda)
resid = a - A*w;
out = 0.5*norm(resid)^2 + (beta/2)*norm(w)^2 + lambda*sum(abs(w));

This formulates the problem as a general optimization problem rather than as least squares. The call to fmincon starts at random initial values and specifies zero as the lower bound for all coefficients. The first input is an invocation of the myobj subfunction with the w parameter allowed to vary but with the other variables set to the values shown.
I've run this on the Hald data from the Statistics Toolbox and created a design matrix that includes a constant. It may make sense to modify the objective function so that the intercept does not contribute to the L1 or L2 penalty. For example, use w(2:end) rather than w in the penalty terms.
I didn't understand your constraint on w(j,j) as I thought w was a vector.
