How can I illustrate the objective function and their constraints in function file?
Show older comments

Constraint:

How can I write the objective function and their constraints in the "function file" in MATLAB?
In this case: C=5, S=3 and N=6
and Xcsn, Pcsn, Rcsn are the binary decision variables while initialYardcs is the parameters that have value in their matrix for example InitialYardcs=[1,0,0;0,0,0 ... ]
Thanks you for your help and your attention!!!
6 Comments
Binh
on 14 Dec 2023
Torsten
on 14 Dec 2023
Choose P_csn = 0 for all c,s and n and R_csn = X_csn. Then you get the minimum value for the objective function, namely 0.
Binh
on 14 Dec 2023
John D'Errico
on 14 Dec 2023
It sounds like you are looking for a complete tutorial on how to use MATLAB, how to build matrices and work with them, and how to write functions. For us to write that would be a waste of time, since there are tutorials existing on how to use MATLAB, and we would want to spend a lot of time teaching you things, some of which you may already know. Essentially, you need to learn MATLAB.
Start with the MATLAB Onramp tutorials.
Binh
on 14 Dec 2023
Answers (1)
I'm sure you can use a loop to define the constraints, and I'm sure you will find out how.
C = 5;
S = 3;
N = 6;
prob = optimproblem;
P = optimvar('P',[C,S,N],'Type','integer','LowerBound',0,'UpperBound',1);
R = optimvar('R',[C,S,N],'Type','integer','LowerBound',0,'UpperBound',1);
X = optimvar('X',[C,S,N],'Type','integer','LowerBound',0,'UpperBound',1);
prob.Objective = sum(P,'All');
Xstart = randi(2,C,S,1)-1
prob.Constraints.c1 = X(:,:,1)-Xstart-P(:,:,1)+R(:,:,1)==0 ;
prob.Constraints.c2 = X(:,:,2)-X(:,:,1)-P(:,:,2)+R(:,:,2)==0 ;
prob.Constraints.c3 = X(:,:,3)-X(:,:,2)-P(:,:,3)+R(:,:,3)==0 ;
prob.Constraints.c4 = X(:,:,4)-X(:,:,3)-P(:,:,4)+R(:,:,4)==0 ;
prob.Constraints.c5 = X(:,:,5)-X(:,:,4)-P(:,:,5)+R(:,:,5)==0 ;
prob.Constraints.c6 = X(:,:,6)-X(:,:,5)-P(:,:,6)+R(:,:,6)==0 ;
sol = solve(prob)
sol.P
sol.R
sol.X
Categories
Find more on Model Predictive Control Toolbox 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!