Error in optimisation code (division by an OptimizationVariable not supported.in prob.objective)
Show older comments
I am currently building a basic optimisation code to maximise d and t within specific constraints. Once the code works I will develop ity further but for now I am stuck with the error Division by an OptimizationVariable not supported. After reviewing this on the forums I am still no closer to working out what I am doing wrong. Any advice would be appreciated. Thank you.
%% Clear workspace
clear;
clc;
%% Input Variables
l=14830; % Member length (mm)
k=1; % Effective length factor
%% Equations
prob = optimproblem('ObjectiveSense','max');
d = optimvar('d', 1,'LowerBound',0);
t = optimvar('t',1,'LowerBound',0);
prob.Objective= (d/t) + ((k*l)/r);
%% Variables
din=d-(2*t); % Member inner diameter
a=3.1415/4 * ((d^2)-(din^2)); % Member cross sectional area
i=3.1415/64 * ((d^4)-(din^4)); % Member second moment of inertia
r=(a/i)^0.5; % Member radius of gyration
%% Constraints
cons1 = d>=0;
cons2 = d<=3000;
cons3 = t>=0;
cons4 = t<=100;
cons5 = d/t<=30;
cons6 = k*l/r<=40;
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
prob.Constraints.cons3 = cons3;
prob.Constraints.cons4 = cons4;
prob.Constraints.cons5 = cons5;
prob.Constraints.cons6 = cons6;
show(prob)
sol = solve(prob);
sol.d
sol.t
The error I am getting is:
Error using optim.internal.problemdef.Rdivide.getRdivideOperator
Division by an OptimizationVariable not supported.
Error in /
Error in optimizejacketframe (line 15)
prob.Objective= (d/t) + ((k*l)/r);
3 Comments
Jeffrey Clark
on 6 Oct 2022
Edited: Jeffrey Clark
on 6 Oct 2022
@Maximilian, both d and t have optimvar LowerBound set to 0 (same as cons1 and cons3), cons5 = d/t<=30 and prob.Objective= (d/t) + ((k*l)/r) seem to set up a condition to divide by zero t. Perhaps not limiting t to be greater than zero can be the cause of the error and would likely be an issue anyway?
Walter Roberson
on 6 Oct 2022
r is not defined.
In current MATLAB versions, if you define r with a definite numeric value, the code is accepted.
I notice the poster is using R2018b; it might be necessary to upgrade in order to use division by an optimization variable (even one constrained to be non-zero)
Maximilian
on 6 Oct 2022
Answers (0)
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!