Conversion to double from optim.problemdef.OptimizationExpression is not possible.
Show older comments
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 Comments
Matt J
on 25 Jun 2018
What line is the error occurring at?
Sohaib Rafique
on 25 Jun 2018
natascia andrenacci
on 13 Nov 2020
I have the same error in a similar problem. Did you manage to solve it?
Answers (2)
Steven Lord
on 25 Jun 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
on 25 Jun 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 Comment
Sohaib Rafique
on 25 Jun 2018
Categories
Find more on Solver Outputs and Iterative Display 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!