Effacer les filtres
Effacer les filtres

Deriving Max with fmincon when contraints differ

2 vues (au cours des 30 derniers jours)
Joon Jeon
Joon Jeon le 28 Fév 2011
I am about to derive maximum values under linear contraint. Exactly describing
Target function is
function f = utility(x) f = (0.7*x(1)^2 + 0.3*x(2)^2)^0.5
And then
Aeq = [1 1]
beq = 100
So, using fmincon
[x, fval] = fmincon(@utility, x0, [], [], Aeq, beq);
I actually derived the result.
HOWEVER, what I REALLY want to do is to change Aeq = [i 1] (i=1~10) and finally get a 10*3 matrix with i and x. Thru this, I could get a plot of x(:,2) against x(:,3).
So, I used FOR such as below. (I also changed initial guessing values X()
=======================
Aeq = zeros(10,2);
Aeq(:,1) = 1:1:10;Aeq(:,2)=1;
X = zeros(10,2);
X(:,1) = 100:-8:28;X(:,2)=100:-8:28;
for i=1:10 beq = 100;
[x] = fmincon(@utility, X(i,:), [], [], Aeq(i,:), beq);
S = [Aeq(i) x];
end
==========================
Result doesn't give me what i WANT. What is wrong with these lines?
Please, help me.
Thanks in advance.

Réponse acceptée

Andrew Newell
Andrew Newell le 4 Mar 2011
If I understand your request, you want the matrix S to have two columns containing the values of Aeq and two columns containing the values of x(2) and x(3) for each case. This should do it:
f = @(x) (0.7*x(1)^2 + 0.3*x(2)^2)^0.5;
Aeq = ones(10,2); Aeq(:,1) = 1:10;
X = [100:-8:28; 100:-8:28]';
beq = 100;
options = optimset('fmincon');
options = optimset(options,'Algorithm','sqp');
S = [Aeq zeros(10,2)];
for i=1:10
S(i,3:4) = fmincon(f, X(i,:), [], [], Aeq(i,:), beq, [], [], [], options);
end
The options settings eliminated some warnings.
  2 commentaires
Joon Jeon
Joon Jeon le 4 Mar 2011
It results some error such as followings.
??? Error using ==> optimset at 242
Invalid value for OPTIONS parameter Algorithm:
must be 'active-set', 'trust-region-reflective', 'interior-point',
'levenberg-marquardt', 'trust-region-dogleg', or 'lm-line-search'.
Error in ==> minmin at 7
options = optimset(options,'Algorithm','sqp');
I thought that 'Algorithm' should be substituted to one of the options in the warning message such as 'active-set'. So I tried but it still gives a error message
Andrew Newell
Andrew Newell le 4 Mar 2011
What version of MATLAB do you have? Try getting rid of the options.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by