fmincon error occurs without details in Matlab

조회 수: 3(최근 30일)
Asim Azhar
Asim Azhar 2021년 11월 10일
답변: Matt J 2021년 11월 11일
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)

답변(2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 11일
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 2021년 11월 11일
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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by