function maximization and different parameter values

2 views (last 30 days)
Hi
I'm a matlab beginner.
I'd like to try maximization in matlab.
This is the function: f=(x(1)^(1/m)+x(2)^(1/m))^m.
where m is a parameter,
and x(1)+x(2)=1, x(1)>=0, x(2)>=0.
I tried the following code, but it's not working.
if true
% code
clc;
f = @(x,m)(-(x(1)^(1/m)+x(2)^(1/m))^m)
m=1:0.1:1.4
for ii = 1:length(m)
[x(:,ii),fval]=fmincon(@(x)f(x,m(ii)),x0,[1,1],1,[],[],[0,0],[inf,inf])
plot(x(1,:)-x(2,:),f)
end
I want to show that only when x(1)=x(2), f is maximized,
and want to draw a single plot for functions with different parameter values like 1, 1.1, 1.2....
Btw the plot... its horizontal axis of the plot should be x(1)-x(2), and the vertical axis is f.
Can anyone please help me solve this problem?
Thank you in advance!

Accepted Answer

Matt J
Matt J on 22 Dec 2014
Edited: Matt J on 22 Dec 2014
Did you really mean the constraint x(1)+x(2)=1 to be an equality instead of an inequality? If so, you are calling fmincon with the wrong syntax. Also, your function behaves badly/non-differentiably for negative x and m>1, so you have to make sure the algorithm iterations never go there. Using the sqp algorithm and forcing f to return NaN for non-positive x(i) can help with this,
opts=optimoptions('Algorithm','sqp');
f=@(x,m)(-(x(1)^(1/m)+x(2)^(1/m))^m)/all(x>0);
...
[x(:,ii),fval]=fmincon(@(x)f(x,m(ii)),x0,[],[],[1,1],1,[0,0],[],[],opts);
...
  7 Comments
Lena
Lena on 24 Dec 2014
Edited: Lena on 24 Dec 2014
yes, with m=1, the curve would be just the horizontal line on the axis..so many different values for m=1. but with other m's >1, there should be concave curves. but i don't know how to replicate the graph.. nyway, thanks a lot, matt! your answer really helped me a lot!
Matt J
Matt J on 24 Dec 2014
Edited: Matt J on 24 Dec 2014
but with other m's >1, there should be concave curves
Nope. My remarks applied to general m. Your objective cannot be written as a function of x(1)-x(2) for any m.
nyway, thanks a lot, matt! your answer really helped me a lot!
You're welcome!

Sign in to comment.

More Answers (0)

Categories

Find more on Two y-axis 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!