Optimisation with function handle
Show older comments
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 Comments
Frederik Skøtt
on 2 Feb 2018
Adam
on 2 Feb 2018
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
on 2 Feb 2018
Edited: Frederik Skøtt
on 2 Feb 2018
Jan
on 2 Feb 2018
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
on 2 Feb 2018
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!