Error in optimisation code (division by an OptimizationVariable not supported.in prob.objective)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 6 de Oct. de 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)
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!