optim.problemdef.OptimizationProblem/solve SOLVE requires a non-empty initial point structure to solve a nonlinear problem.
Show older comments
Hi, I am currently creating an optimization problem to find the minimum value of an equation with 5 constraints. My code is:
clear;
clc;
prob = optimproblem("Description","BestWorstMethod");
A_B = [2 1 3 3 8];
A_W = [4;8;4;3;1];
n=length(A_B);
W = optimvar("W",n,"LowerBound",0);
e = optimvar("e",1,"LowerBound",0);
w_b = W(2);
w_w = W(5);
prob.Objective = e;
[cons1,cons2] = fcn2optimexpr(@consBO,A_B,W,w_b);
[cons3,cons4] = fcn2optimexpr(@consOW,A_W,W,w_w);
prob.Constraints.cons1 = cons1 <= e;
prob.Constraints.cons2 = cons2 <= e;
prob.Constraints.cons3 = cons3 <= e;
prob.Constraints.cons4 = cons4 <= e;
prob.Constraints.cons5 = sum(W)==1;
[sol,optimval] = solve(prob);
optimW = sol.W
function [cons1,cons2] = consBO(A_B,W,w_b)
n=length(A_B);
cons1 = zeros(1,n);
cons2 = zeros(1,n);
for j = 1:n
cons1(j) = w_b - A_B(j) * W(j);
cons2(j) = A_B(j) * W(j) - w_b;
end
end
function [cons3,cons4] = consOW(A_W,W,w_w)
n=length(A_W);
cons3 = zeros(1,n);
cons4 = zeros(1,n);
for j = 1:n
cons3(j) = W(j) - A_W(j) * w_w;
cons4(j) = A_W(j)* w_w - W(j);
end
end
The function consBO and consOW define the for loop structure on constraints.The constraint inequality is shown below.

I keep getting the same errors:
Error using optim.problemdef.OptimizationProblem/solve
SOLVE requires a non-empty initial point structure to solve a nonlinear problem.
Please let me know if you have any advice. Thanks!
Answers (1)
My advice is: Do what the error message tells you to do and supply an initial point structure to make MATLAB happy.
initial.e = 0;
initial.W = ones(n,1);
[sol,optimval] = solve(prob,initial);
Categories
Find more on Nonlinear Optimization 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!