필터 지우기
필터 지우기

replicating excel solver using optimization linprog

조회 수: 1 (최근 30일)
Purvi Chandrakar
Purvi Chandrakar 2021년 10월 13일
답변: Alan Weiss 2021년 10월 13일
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에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by