Deriving Max with fmincon when contraints differ
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Andrew Newell
el 4 de Mzo. de 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 comentarios
Andrew Newell
el 4 de Mzo. de 2011
What version of MATLAB do you have? Try getting rid of the options.
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!