I have the following objective function
t = 0:0.01:1;
v = 3.*t;
objective =@(t) (1 - b).*( a1.*v + a2.*v.^2); %where a1,a2 given constants
S = sum(objectivet(t));
t0 = 1;
But when applying the
[t,fval,exitflag,output] = fmincon(S,t0,A,b,Aeq,beq,ub,lb,constraints)
it gives an error using fmincon.
All values using the fmincon are well defined. How could I correct it?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Dic. de 2018

1 voto

t = 0:0.01:1;
so t is a vector.
v = 3.*t;
So v is a vector the same size as t.
objective =@(t) (1 - b).*( a1.*v + a2.*v.^2); %where a1,a2 given constants
Assuming that a1, a2, and b are scalars. then this would take an input locally named t, ignore the input, and return a vector the same size as v, which is the length of the original t . fmincon does not expect that.
We might suspect that you perhaps want
t = 0:0.01:1;
v = @(T) 3.*T;
objective = @(T) (1 - b).*( a1.*v(T) + a2.*v(T).^2); %where a1,a2 given constants
Here I use T to distinguish the current parameter from the vector of length 101.
S = sum(objectivet(t));
We could suspect that objectivet is the same as objective . But as far as we know, objective takes only a single parameter, so objective(t) would be a definite vector and sum(objective(t)) would be a definite value, not something that could be optimized.
So the next suspicion is that you want
t = 0:0.01:1;
v = @(T) 3.*T;
objective = @(T, b) (1 - b).*( a1.*v(T) + a2.*v(T).^2); %where a1,a2 given constants
S = @(b) sum(objective(t, b));
and that is something that could reasonably be optimized.
It turns out that this can be optimized down to the expression
S = @(b) -(303*(b - 1)*(100*a1 + 201*a2))/200
and you can demonstrate easily that the minima of this is either at b = +inf or b = -inf or at one of the constraint boundaries.

2 comentarios

Thalassia Nouni
Thalassia Nouni el 12 de Dic. de 2018
Thank you, it works perfectly. How could someone see the optimized expression of an objective like you wrote in the last line?
syms B
simplify(S(B))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 11 de Dic. de 2018

Comentada:

el 12 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by