How to perform the absolute value function on the output of an optimisation expression?

8 views (last 30 days)
% Create Optimisation expressions
j = length(x); % is a double array
Tk = optimexpr(j);
Uk = optimexpr(j);
energyCost = optimexpr(j);
thermalCost = optimexpr(j);
%Initialise optimisation expressions
Tk(1,1) = 22;
Uk(1,1) = Tk(1,1)*K; % K=0.6
energyCost(1,1) = Uk(1,1)*abs(x(1,1));
thermalCost(1,1) = abs(Tk(1,1)-nominal_T); % THIS WHERE THE PROBLEM IS
% The last line always produces an error... "Undefined function 'abs' for input arguments of type 'optim.problemdef.OptimizationExpression'"
% How can I get round this?
  4 Comments
dpb
dpb on 17 Jul 2019
Edited: dpb on 17 Jul 2019
That'll be under however the TB does constrained optimization, then, but certainly that wouldn't be done by calling abs() on the optimization object but has to be internal.
I'm not that familiar with the app; I've only used the direct user-called routines so not sure exactly how to set it up.
Boy, this seems to be a rat's nest of complexity to wend one's way through...but, try
and related links and see if can figure out how it's all supposed to work together.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 22 Jul 2019
Edited: Matt J on 22 Jul 2019
Without seeing your complete problem, it is hard to be certain, but you might find minL1lin (File Exchange download) applicable to this case. You need to enter the data into minL1lin in solver-based form, but you can still use prob2struct to extract all the relevant constraint matrices from your current problem-based code.
  11 Comments
Matt J
Matt J on 23 Jul 2019
Should this line not be
energyCost(i,1) = Uk(i,1)*abs(x(i,1));
Without the abs, it could surely explain why the cost could be driven to -Inf.
Akinkunmi Adegbenro
Akinkunmi Adegbenro on 23 Jul 2019
Edited: Akinkunmi Adegbenro on 23 Jul 2019
Well spotted Matt! It was indeed the problem, it works now. Thank you very much for your help.

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!