How to solve absolute problem in optimization

10 ビュー (過去 30 日間)
Jayachandra Malavatu
Jayachandra Malavatu 2023 年 6 月 8 日
コメント済み: Torsten 2023 年 6 月 8 日
Hello, i want to solve a quadratic optimization problem (prob.Objective =sum((PgridV).^2);), in constrains i have a one variable where i need to find the absolute value of (Pb1dc). so i introduce a variable called 'K' . where -K<=Pb1dc<=K;
  • FYI: i have used absoulte value in the following constrains (prob.Constraints.loadBalanceAC=Pb1==Pb1dc-(0.05*K);)
MATLAB solution showing exactely whati want . its working well.
However, when i want to chage the objective function with little modifcation (prob.Objective =sum((PgridV-M).^2);) where M is a reference signal (mean of Pload), when i run the simulation
absolute vaules (K) are not getting exactley what mean for. its showing random values ( K = absolute ((Pb1dc))
clc
clear all
Pload=[0;1;3;4;2;6;9;10;2;4]; % load
N=10;
M=mean(Pload)+zeros(N,1);
Einit1=0.5; % initial energy
E=zeros(N,1);
Emin1 = 0; % mini energy
Emax1 = 3;
dt=1;
prob = optimproblem;
PgridV = optimvar('PgridV',N,'LowerBound',0,'UpperBound',20); % grid power
Pb1= optimvar('Pb1',N,'LowerBound',-1,'UpperBound',1); % ac power
Pb1dc= optimvar('Pb1dc',N,'LowerBound',-1,'UpperBound',1); % dc power
K=optimvar('K',N,'LowerBound',0);% absolute of (Pb1dc)
EbattV1 = optimvar('EbattV1',N,'LowerBound',Emin1,'UpperBound',Emax1); % energy
prob.ObjectiveSense = 'minimize';
% prob.Objective =sum(K.^2);
%prob.Objective =sum((PgridV).^2);
prob.Objective =sum((PgridV-M).^2);
% 1 constrains
prob.Constraints.energyBalance = optimconstr(N);
prob.Constraints.energyBalance(1) = EbattV1(1) == Einit1-Pb1dc(1)*dt; %Its Ploss is constanat
prob.Constraints.energyBalance(2:N-1) = EbattV1(2:N-1) == EbattV1(1:N-2)-Pb1dc(2:N-1)*dt;
prob.Constraints.energyBalance(N) = EbattV1(N) ==Einit1;
% K constrain for Pb1dc modulous
prob.Constraints.kbalance1=optimconstr(N);
prob.Constraints.kbalance1(1:N)=-K(1:N)<=Pb1dc(1:N);
prob.Constraints.kbalance2=optimconstr(N);
prob.Constraints.kbalance2(1:N)=Pb1dc(1:N)<=K(1:N);
% load Balance
prob.Constraints.loadBalance=PgridV+Pb1==Pload;
% loss term
prob.Constraints.loadBalanceAC=Pb1==Pb1dc-(0.05*K);
options = optimoptions(prob.optimoptions,'Display','final');
% options = optimoptions(prob.optimoptions,'Algorithm','interior-point');
[values,fval,exitflag] = solve(prob,'Options',options)
Solving problem using lsqlin. Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
values = struct with fields:
EbattV1: [10×1 double] K: [10×1 double] Pb1: [10×1 double] Pb1dc: [10×1 double] PgridV: [10×1 double]
fval = 57.4575
exitflag =
OptimalSolution
% Parse optmization results
if exitflag <= 0
PgridV = zeros(N,1);
Pb1 = zeros(N,1);
Pb1dc = zeros(N,1);
EbattV1 = zeros(N,1);
K = zeros(N,1);
else
PgridV = values.PgridV ;
Pb1 = values.Pb1;
Pb1dc = values.Pb1dc
EbattV1 = values.EbattV1;
K = values.K
end
Pb1dc = 10×1
-0.6434 -0.6204 -0.6701 0.1224 -0.6886 1.0000 1.0000 1.0000 -0.8624 -0.0018
K = 10×1
7.1327 7.5914 6.5986 4.4490 6.2283 1.0000 1.0000 1.0000 2.7522 1.9640
.
  4 件のコメント
Jayachandra Malavatu
Jayachandra Malavatu 2023 年 6 月 8 日
The K values : which are absolute values of (Pb1dc)
Torsten
Torsten 2023 年 6 月 8 日
編集済み: Torsten 2023 年 6 月 8 日
What's wrong with the K values listed above ?
They are not defined as the absolute values of Pb1dc in your constraints.
Your constraint is abs(Pb1dc) <= K.

サインインしてコメントする。

回答 (1 件)

Jayachandra Malavatu
Jayachandra Malavatu 2023 年 6 月 8 日
  15 件のコメント
Jayachandra Malavatu
Jayachandra Malavatu 2023 年 6 月 8 日
i am using MATLAB 20222a, is this reason why it is used fimncon rather than lsqnonlin?
Torsten
Torsten 2023 年 6 月 8 日
Yes. Nonlinear constraints in lsqnonlin were introduced recently.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by