Optimisation with function handle
显示 更早的评论
Hi guys!
I have a non-convex optimisation problem which possibly can be solved using function handle and fmincon.
Lets start with the simple example
c = 5;
min c - lambda*p
ST: cb >= 0
I already have an "inner" function which is called revenue that computes the product of lambda and p (lambda*p) and takes the input (cb)
Thus,I am just creating a function handle,
revenue = @revenue;
And re-formulate my problem as
min c + revenue(cb)
ST: cb >= 0
This works, which is great!
However, as my problem is slightly different...
min c*p - lambda*p
ST: cb >= 0
p is now multiplied to the c as well.
My first thought was just to modify the revenue function in such way that it would return the p itself as well.
function [revenue,p] = revenue(cb)
and then make a function handle as
[revenue,p] = @revenue;
However, this is not working :/
Any help, ideas or suggestions are highly appreciated.
Cheers Fred
6 个评论
Frederik Skøtt
2018-2-2
Adam
2018-2-2
In general you do it just like any other function handle - e.g.
>> f = @min
f =
function_handle with value:
@min
>> [m, i] = f( [3 4] )
m =
3
i =
1
Just saying something is 'not working' if not much use to people aiming to help though - it doesn't tell us anything!
revenue = @revenue;
This is a bad idea, even if it works. You see, that the confusion is perfect, if you replace the handle of a function by a variable which is called like the function. I do not have an idea, what the purpose of this line is:
[revenue,p] = @revenue;
Do you mean:
fcn = @(x), revenue(x, p)
?
Please explain "this is not working" with any details. It is easier to solve a problem than to guess, what the problem is.
Frederik Skøtt
2018-2-2
编辑:Frederik Skøtt
2018-2-2
Jan
2018-2-2
Your notation is hard to read. Please use the standard formatting for text and code, see http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Frederik Skøtt
2018-2-2
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!