replicating excel solver using optimization linprog
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Purvi Chandrakar
le 13 Oct 2021
Réponse apportée : Alan Weiss
le 13 Oct 2021
I need to minimize the maximum value of buffer. Where Buffer(i)=buffer(i-1)+(gen-demand). Demand is given as a row matrix [10 1 5 2]. We need to vary the generation data (x) and initial value of buffer (y) under some linear inequality constraints ,to minimize the maximum value of buffer. I tried the below code, with [v] matrix as my initial guess of x and y: (i have not introduced constraints yet)
v=[0 0 0 0 1];
a=linprog(objective_fun(x,y) ,v);
function output=objective_fun (x,y)
demand=[10 1 5 2];
gen=ones(1,4)*x;
mis=gen-demand;
buffer=zeros(1,4);
buffer(1,1)=y;
for i=2:4
buffer(i)=buffer(i-1)+mis(i);
end
output=max(buffer);
end
I am getting error of not enough input. Please help.
0 commentaires
Réponse acceptée
Alan Weiss
le 13 Oct 2021
I think that you would probably have an easier time formulating your problem by using the Problem-Based Optimization Workflow.
But to answer your specific question, the syntax for linprog requires objective_fun to be a vector, not a function of two variables as you have stated:
a=linprog(objective_fun(x,y) ,v); % objective_fun(x,y) looks like an error
I recommend again that you try the problem-based approach. It is much easier to user and less error-prone.
Alan Weiss
MATLAB mathematical toolbox documentation
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!