MATLAB Answers

Quadratic Constraints/Optimization error in Matlab 2020b but not Matlab 2020a

3 views (last 30 days)
S on 8 Sep 2021
Answered: Matt J on 10 Sep 2021
Hi, I have Matlab 2020a and 2020b in different computers. My codes to run quadratic optimization (quadratic objective function, quadratic constraints) run into error in the newer version but not the older version of Matlab.
Here is an example: I wrote the following code to find the shortest distance between two circles:
%%% Define the Optimization Problem
CircleDistance = optimproblem;
%%%%% variables
x1 = optimvar('x1' , 1);
y1 = optimvar('y1' , 1);
x2 = optimvar('x2' , 1);
y2 = optimvar('y2' , 1);
% Constraints
CircleDistance.Constraints.Circle1 = x1.^2 + y1.^2 <= 5;
CircleDistance.Constraints.Circle2 = (x2-10).^2 + (y2-5).^2 <= 5;
% Objective Function
CircleDistance.Objective = (x1-x2).^2 + (y1 -y2).^2;
% Initial Point
x0.x1 = 0;
x0.y1 = 0;
x0.x2 = 10;
x0.y2 = 5;
% Solve the problem
x = solve(CircleDistance, x0);
Solving problem using fmincon. Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = struct with fields:
x1: 2.0000 x2: 8.0000 y1: 1.0000 y2: 4.0000
In Matlab 2020a, I get the correct solution (as listed above), but I get the following error when I run the code in Marlab 2020b (on a different computer).
Error using strjoin (line 38)
The first argument should be a cell array of strings.
Error in optim.internal.problemdef.compile.compileQuadraticConstraints
Error in optim.problemdef.OptimizationProblem/compileConstraints
Error in optim.internal.problemdef.ProblemImpl/prob2structImpl
Error in optim.internal.problemdef.ProblemImpl/solveImpl
Error in optim.problemdef.OptimizationProblem/solve
Error in Untitled (line 27)
x = solve(CircleDistance, x0);
Can someone help me out please? Thank you in advance.
S on 10 Sep 2021
When I run
>> which -all strjoin
in the matlab2020b machine, it gives me two addresses:
[address 1]\MATLAB\strjoin.m
[address 2]\MATLAB\R2020b\toolbox\matlab\strfun\strjoin.m % Shadowed
I deleted the strjoin.m associated with the first address (seemed pretty old, from 2014) and now the code solves properly.
When I run it on matlab2020a machine it only gives me one address in the proper 2020a folder.
I really appreciate you pointing me in this direction.
Can you tell me what is happening here? Was MATLAB running an old version of strjoin.m that was incompatible with the problem based optimization?
Thank you for your help

Sign in to comment.

Answers (1)

Matt J
Matt J on 10 Sep 2021
Was MATLAB running an old version of strjoin.m that was incompatible with the problem based optimization?
Yes, it appears that way.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by