replicating excel solver using optimization linprog

10 次查看(过去 30 天)
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.

采纳的回答

Alan Weiss
Alan Weiss 2021-10-13
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 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by