fmincon error occurs without details in Matlab

1 view (last 30 days)
I followed the instructions, but what I only can get is "error in (filename)" without any additional details. Could you tell me which part made an error?
clear;clc;lb = [0,0];
ub = [1,1];
A = [1 1];
B = [1];
Aeq = [];
Beq = [];
x0=[0.5, 0.5];
f=@(x)(200*x(1)-37)^2+(200*x(2)-83)^2+(200*x(1)+200*x(2)-122)^2+(400*x(1)-82)^2+(400*x(2)-157)^2+(400*x(1)+400*x(2)-250)^2;
x = fmincon(f,x0,A,B,Aeq,Beq,lb,ub)

Answers (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 11 Nov 2021
It is working ok.
clearvars;clc;
lb = [0, 0];
ub = [1, 1];
A = [1 1];
B = 1;
Aeq = [];
Beq = [];
x0=[0.5, 0.5];
f=@(x)(200*x(1)-37)^2+(200*x(2)-83)^2+(200*x(1)+200*x(2)-122)^2+(400*x(1)-82)^2+(400*x(2)-157)^2+(400*x(1)+400*x(2)-250)^2;
x = fmincon(f,x0,A,B,Aeq,Beq,lb,ub)
Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
x = 1×2
0.2090 0.4050

Matt J
Matt J on 11 Nov 2021
lsqlin would be better for this than fmincon.
lb = [0,0];
ub = [1,1];
A = [1 1];
b = [1];
C=[200,0;
0 200;
200 200;
400 0;
0 400;
400 400];
d=[ 37 83 122 82 157 250].';
lsqlin(C,d, A,b,[],[],lb,ub)
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.
ans = 2×1
0.2090 0.4050

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!