Error using fmincon (line 288) A must have 1 column(s).
Afficher commentaires plus anciens
i have this problem any one know how can i solve it
Error using fmincon (line 288)
A must have 1 column(s).
Error in Untitled3 (line 34)
[x,fval,exitflag,output] = fmincon(fun,nvars,A,b,Aeq,beq,LB,UB,nonlcon,IntCon,options)
the code is
clc
clear all
fun=@(x) 2.633*x(1)+2.992*x(2)+3.134*x(3)+3.678*x(4)+3.620*x(5)+2.948*x(6)+1.607*x(7)+2.952*x(8)+3.348*x(9)+3.680*x(10)+3.774*x(11)+2.995*x(12)+3.237*x(13)+1.608*x(14);
nvars = 14; % Number of variables
LB = [0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05]; % Lower bound for (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
UB = [1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1]; % Upper bound for (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
A=zeros(20,14); b=zeros(20,1);
A(1,1)=+2.633; A(1,6)=-4.112; b(1)=-0.3; %first row
A(2,1)=-4.870; A(2,2)=+2.992; b(2)=-0.3; %second row
A(3,2)=+2.992; A(3,7)=-2.178; b(3)=-0.3; %third row
A(4,2)=-3.857; A(4,3)=+3.130; b(4)=-0.3; %fourth row
A(5,3)=-3.989; A(5,4)=+3.678; b(5)=-0.3; %fifth row
A(6,4)=-4.979; A(6,5)=+3.620; b(6)=-0.3; %sixth row
A(7,5)=-5.756; A(7,6)=+2.948; b(7)=-0.3; %seventh row
A(8,5)=-5.826; A(8,7)=+1.607; b(8)=-0.3; %eighth row
A(9,6)=+2.948; A(9,14)=-2.150; b(9)=-0.3; %nighth row
A(10,7)=+1.607; A(10,13)=-6.920; b(10)=-0.3; %tenth row
A(11,7)=-2.144; A(11,8)=+2.952; b(11)=-0.3; %eleventh row
A(12,8)=+2.952; A(12,9)=-5.365; b(12)=-0.3; %tweleventh row
A(13,9)=+3.348; A(13,10)=-4.863; b(13)=-0.3; %thirteenth row
A(14,10)=+3.680; A(14,11)=-5.073; b(14)=-0.3; %fourteenth row
A(15,11)=+3.774; A(15,12)=-3.774; b(15)=-0.3; %fiveteenth row
A(16,12)=+2.995; A(16,13)=-6.920; b(16)=-0.3; %sixteenth row
A(17,12)=+2.995; A(17,14)=-2.151; b(17)=-0.3; %seventennth row
A(18,8)=-4.288; A(18,13)=+3.237; b(18)=-0.3; %eighteenth row
A(19,1)=-4.870; A(19,14)=+1.608; b(19)=-0.3; %nighnteenth row
A(20,9)=-5.365; A(20,14)=+1.608; b(20)=-0.3; %twinty row
Aeq=[];
beq=[];
nonlcon=[];
IntCon=[];
rng default % For reproducibility
options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
[x,fval,exitflag,output] = fmincon(fun,nvars,A,b,Aeq,beq,LB,UB,nonlcon,IntCon,options)
2 commentaires
madhan ravi
le 28 Nov 2018
it clearly says A must have 1 column but you assigned 14 columns
tahseen alshmary
le 28 Nov 2018
Réponses (1)
Walter Roberson
le 28 Nov 2018
0 votes
fmincon does not take aa nvars parameter . It takes an x0 parameter .
12 commentaires
tahseen alshmary
le 28 Nov 2018
Torsten
le 28 Nov 2018
[x,fval,exitflag,output] = fmincon(fun,ones(14,1),A,b,Aeq,beq,LB,UB,nonlcon,options)
And "fmincon" is overkill for your problem ; use "linprog" instead.
tahseen alshmary
le 28 Nov 2018
Torsten
le 28 Nov 2018
Why do you use your old call to "fmincon" instead of the one I provided ?
tahseen alshmary
le 28 Nov 2018
Torsten
le 28 Nov 2018
"IntCon" is not part of my list of variables passed to "fmincon".
tahseen alshmary
le 28 Nov 2018
Torsten
le 28 Nov 2018
Try
nvars = ones(1,14)
tahseen alshmary
le 28 Nov 2018
Walter Roberson
le 28 Nov 2018
particleswarm() accepts an nvar parameter but not an x0 parameter . Initial conditions of particleswarm can only be passed in through options .
tahseen alshmary
le 28 Nov 2018
Walter Roberson
le 29 Nov 2018
https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Catégories
En savoir plus sur Surrogate Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!