absolute value in equality constraints
2 views (last 30 days)
Show older comments
Housam
on 26 Sep 2021
Answered: Walter Roberson
on 26 Sep 2021
i would like to know how to write the absolute value in equality constraints.
var10(i) = var10(i-1) + (0.5/4500) * (ABS ( 0.25*var7(i) ) ) / var9(i)
my Input(i) is a vector with the length of 350*1 with positive integer values, that are measurements of a continuous variable.
prob = optimproblem;
% equality constrainst
prob.Constraints.econs6 = optimconstr(N); %Non linear with absoulte
prob.Constraints.econs6(1) = var10(1) == (0.5*(1/4500) * abs((var7(1) *0.25))) ./ var9(1);
prob.Constraints.econs6(2:N)= var10(2:N) == var10(1:N-1) + (0.5*(1/4500) * abs((var7(2:N)*0.25))) ./ var9(2:N);
x0.var7 = zeros(size(N));
x0.var9 = zeros(size(N));
x0.var10 = zeros(size(N));
[values,fval,exitflag,output] = solve(prob,x0,'Options',options);
thanks in advance for hints.
0 Comments
Accepted Answer
Walter Roberson
on 26 Sep 2021
N = 5;
var10 = optimvar('var10', N);
var9 = optimvar('var9', N);
var7 = optimvar('var7', N);
prob = optimproblem;
ABS = @(x) sqrt(x.^2);
% equality constrainst
prob.Constraints.econs6 = optimconstr(N); %Non linear with absoulte
thisconstraint = var10(1) == (0.5*(1/4500) * ABS((var7(1) *0.25))) ./ var9(1)
prob.Constraints.econs6(1) = thisconstraint
prob.Constraints.econs6(2:N)= var10(2:N) == var10(1:N-1) + (0.5*(1/4500) * ABS((var7(2:N)*0.25))) ./ var9(2:N);
x0.var7 = zeros(N,1);
x0.var9 = zeros(N,1);
x0.var10 = zeros(N,1);
[values, fval, exitflag, output] = solve(prob, x0);
0 Comments
More Answers (0)
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!