How to call an external function in linprog optimization

Hi,
i want to run a simple and fast optimization example. My problem is the calculating of values in an external function. Example: x1 is the input value (in the range of 1 to 5) of a function called 'Master' x2 will be the output matrix of the function 'Master', which should be less or equal than 0.5 in each cell
1<=x1<=5
x2<=0.5
So i wrote
A = [1 0
-1 0
0 0.5
];
b = [5;-1;1];
Aeq = [1 0 %x1=inputvalue
0 1]; %x2=Master(x1)
beq = [ input
Master(input)
];
x=linprog(f,intcon,A,b,Aeq,beq);
After running this, there is the error: Undefined function or variable 'input'. Error in line ... beq=[input
How can i perform the optimization?

 采纳的回答

You cannot do so using linprog. That would effectively allow the constraint to be some general NONlinear constraint, something not solvable using linprog, a LINEAR programming tool. So you can't do it, never will, not using linprog.
It would be possible using some more general nonlinear optimizer (like fmincon), IF the constraint takes the form of a well-behaved differentiable function of the inputs.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by