Conversion to double from optim.problemdef.OptimizationExpression is not possible.
Mostrar comentarios más antiguos
Can anyone please help!!! I am trying to solve an optimization problem using MILP (problem-based approach)
'r' and 'q' are optimization variables
The following error occurred converting from optim.problemdef.OptimizationExpression to double: Conversion to double from optim.problemdef.OptimizationExpression is not possible.
How can I fix it????
nt = 24;
nh= 20;
Pbcd = 5*ones(nt,1);
Eb = 5*ones(nt,1);
Ebinv = (1/98)*ones(nt,1);
Pbc = q.*Pbcd.*Ebinv;
Pbd = r.*Pbcd.*Ebinv;
socb = zeros(nt,1);
socb(1,1) = 1;
for i= 2:nt
socb(i,1) = socb(i-1,1) + Pbc(i,1) - Pbd(i,1);
end
3 comentarios
Matt J
el 25 de Jun. de 2018
What line is the error occurring at?
Sohaib Rafique
el 25 de Jun. de 2018
natascia andrenacci
el 13 de Nov. de 2020
I have the same error in a similar problem. Did you manage to solve it?
Respuestas (2)
Steven Lord
el 25 de Jun. de 2018
Please add these lines immediately before the start of your for loop then run your code and show us what gets displayed. It will show us the types of your variables and make sure you haven't accidentally shadowed the built-in ones function with a version that performs some optimization calculations.
which -all ones
whos
Alan Weiss
el 25 de Jun. de 2018
If you intend socb to be an optimization expression, then initialize it that way.
socb = optimexpr(nt,1); % Not zeros(nt,1)
socb(1,1) = 1;
Alan Weiss
MATLAB mathematical toolbox documentation
1 comentario
Sohaib Rafique
el 25 de Jun. de 2018
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!