replicating excel solver using optimization linprog
조회 수: 3 (최근 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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!