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 Comments

Even simplified, how to create a function handle for a function with 2 outputs :p
Cheers
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!
Jan
Jan on 2 Feb 2018
Edited: Jan on 2 Feb 2018
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.
Thank you both for your answers!
I will try to be a bit more specific, sorry.
I have a function, "revenue" which takes 1 input, and returns 2 outputs.
Those 2 outputs are to be used in another function, thus I need to handle them.
Example
Defining the revenue function
function [rev, p] = revenue(offer)
lambda = 10;
p = offer*2;
rev = lambda*p;
end
I will now calculate the profit using my two outputs from my revenue function.
c = 1;
profit = c*p - rev
I will have to pass the offer to my revenue function which will then give me the two outputs.
Hope this makes a little more sense. It could possible also be made by "only" returning lambda and p and the do the multiplication in the profit function
profit = c*p-lambda*p
Thank you for your help so far!
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
Hey Jan,
Thank you for noticing me.
Nice that someone has made a general question format for text and code, I will definitely take that into account next time.
Best
Fred

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 2 Feb 2018
Edited: Matt J on 2 Feb 2018
Nothing you've posted indicates why the approach wouldn't work. In my opinion, though, the code would be much clearer if revenue(cb) would return lambda and p. Then your objective function could be written, for the simple problem,
function fval=myObjective(cb)
[lambda,p]=revenue(cb);
fval=c-lambda*p;
end
and for the more complicated problem,
function fval=myObjective(cb)
[lambda,p]=revenue(cb);
fval=(c-lambda)*p;
end

1 Comment

I feel certain this will work!
Then I would just handle myObjective as profit(Cb) with one single output and one single optimisation variable "Cb".
I will try this when I get home!
Thank you all for your time.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!