필터 지우기
필터 지우기

absolute value in equality constraints

조회 수: 4 (최근 30일)
Housam
Housam 2021년 9월 26일
답변: Walter Roberson 2021년 9월 26일
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.

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 26일
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)
thisconstraint =
Nonlinear OptimizationEquality var10(1) == ((0.00011111 .* sqrt((var7(1) .* 0.25).^2)) ./ var9(1))
prob.Constraints.econs6(1) = thisconstraint
prob =
OptimizationProblem with properties: Description: '' ObjectiveSense: 'minimize' Variables: [1×1 struct] containing 3 OptimizationVariables Objective: [0×0 OptimizationExpression] Constraints: [1×1 struct] containing 1 OptimizationConstraint See problem formulation with show.
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);
Solving problem using fmincon.
Error using optim.problemdef.OptimizationProblem/solve
Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by