I'm trying to minimize an objective function that contains absolute terms including some of the variables. The target function looks like this (I'll only write down two terms, the actual problem contains between 500 and 5000, depending on other parameters):
min |f_11 * x_1 + f_21 * x_2 - y_1| + |f_12 * x_1 + f_22 * x_2 - y_2|
There can also be different types of constraints. Since I don't have the Symbolic Toolbox I have no clue how to put this into Matlab. I thought of interpreting this as a quadratic program, where I square each term and get the squareroot of it. With an anonymous function this would look like this I think:
f = @(X) sqrt((F*X - Y) .* (F*X - Y)) * ones(size(Y));
Where F and Y contain the values of f_ij and y_j. So in my case F ís of size ix2, Y is of size ix1 and X is of size 1x2.
The problem here is, I can't calculate the numerical hessian via the DERIVESTsuite (http://www.mathworks.com/matlabcentral/fileexchange/13490-adaptive-robust-numerical-differentiation). I'll get the error:
Error using *
Inner matrix dimensions must agree.
Error in calcHq>@(W)sqrt((F*W-Y).*(F*W-Y))*ones(size(Y)) (line 16)
f = @(W) sqrt((F*W - Y) .* (F*W - Y)) * ones(size(Y));
Error in hessdiag>@(xi)fun(swapelement(x0,ind,xi)) (line 60)
@(xi) fun(swapelement(x0,ind,xi)), ...
Error in derivest (line 337)
f_x0(j) = fun(x0(j));
Error in hessdiag (line 59)
[HD(ind),err(ind),finaldelta(ind)] = derivest( ...
Error in hessian2 (line 74)
[hess,err] = hessdiag(fun,x0);
I assume there is some problem with the elementwise multiplication, but I really can't figure out what I'm doing wrong.
Maybe someone can give me a hint on what I'm doing wrong.
F*Xand(...)*ones(...)the first vector is a row vector and the second is a column vector (of the same length, of course). The dimensions you wrote seem to suggest otherwise.f = @(W) sqrt((F*W - Y) .* (F*W - Y)) * ones(size(Y));, unless you have misinterpreted the function. However, for your own sake, you may want to start by callingfand make sure that you get output you expect. Do this by setting a breakpoint on the line afterfis assigned and do the function call in the command window, using some input.