How to create several constrains with a for loop?(problem based approach)

Hi!
I am working on an equation problem that I solved in GAMS, but now I want to try in MatLab problem-based approuch.
I am working with non-linear contratins and from my understanding I have to use the function fcn2optimexpr(). My optimization variables are alredy defined as
U = optimvar("U",length(Nodes),"LowerBound",0.4,"UpperBound",UpperBound_Voltage);
Theta0 = optimvar("Theta0",length(Nodes),"LowerBound",0,"UpperBound",0);
Theta = optimvar("Theta",length(Nodes),"LowerBound",-pi/2,"UpperBound",pi/2);
Pkj = optimvar("Pkj",length(Nodes),length(Nodes));
Qkj = optimvar("Qkj",length(Nodes),length(Nodes));
PG = optimvar('PG',length(Nodes),"LowerBound",-1.1.*PGbounds,"UpperBound",1.1.*PGbounds);
QG = optimvar("QG",length(Nodes),"LowerBound",-1.1.*QGbounds,"UpperBound",1.1.*QGbounds);
So for example I create the following function that I express my non linear constrains.
% Converter_index,Controlled_V_index,C_scaling,K,XqMOT,XqGEN,S_machine,Non_converter_index are parameters, fixed.
function [Rotary_eq1,Rotary_eq2,Rotary_eq3, Rotary_eq4, Rotary_eq5] = constrains_func(Converter_index,Controlled_V_index,C_scaling,...
K,XqMOT,XqGEN,G,B,U,Theta,Theta0,Pkj,Qkj,PG,QG) %Both parameters and optimization variables are sent
% Machine equations, 5 contrains for each machine.
for t = 1:length(Converter_index)
Rotary_eq1(t) = Theta0(Converter_index(t));
Rotary_eq2(t) = (1/3)*atan(XqMOT(Converter_index(t)) * PG(Converter_index(t))) +...
atan((XqGEN(Converter_index(t)) * PG(Converter_index(t)))/(U(Converter_index(t))^2 + XqGEN(Converter_index(t))*QG(Converter_index(t))));
Rotary_eq3(t) = Theta0(Converter_index(t))-Psi(Converter_index(t));
Rotary_eq4(t) = sqrt(PG(Converter_index(t))^2 + QG(Converter_index(t))^2);
end
%voltages that are controlled
for tt = 1:length(Controlled_V_index)
for tt = 1:length(Converter_index)
Rotary_eq5(tt)= (1.1*U0(Controlled_V_index(tt))) - (C_scaling(Converter_index(tt))*K(Converter_index(tt)))*Qkj(Controlled_V_index(tt),Converter_index(tt));
end
end
So my question is how to use the fcn2optimexpr() such that it creates the total 10 constrains. Should it be after each iteration, or afterwards? If so, could you provide with an example?
Cheers!

Answers (0)

Products

Release

R2019a

Asked:

on 17 Jan 2020

Community Treasure Hunt

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

Start Hunting!