# replicating excel solver using optimization linprog

6 views (last 30 days)
Purvi Chandrakar on 13 Oct 2021
Answered: Alan Weiss on 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

Alan Weiss on 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

R2021b

### Community Treasure Hunt

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

Start Hunting!