Conversion to double from optim.problemdef.OptimizationExpression is not possible.
Ältere Kommentare anzeigen
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 Kommentare
Matt J
am 25 Jun. 2018
What line is the error occurring at?
Sohaib Rafique
am 25 Jun. 2018
natascia andrenacci
am 13 Nov. 2020
I have the same error in a similar problem. Did you manage to solve it?
Antworten (2)
Steven Lord
am 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
am 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 Kommentar
Sohaib Rafique
am 25 Jun. 2018
Kategorien
Mehr zu Solver Outputs and Iterative Display finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!