i would like to ask about the optimization in matlab function that works with multi variable input with each input has different boundaries the output is only one variables

 採用された回答

John D'Errico
John D'Errico 2015 年 11 月 29 日

1 投票

help fmincon
Or, as found on the file exchange, fminsearchbnd.

5 件のコメント

mohammed hussein
mohammed hussein 2015 年 11 月 30 日
編集済み: Walter Roberson 2015 年 11 月 30 日
thank you John D'Errico for answering me
i am trying these function a lot of time but it doesn't work
i have the equation
Function =(X-5)^2+(Y+6)^2+Z
when the boundary of
X from 0 to 1
Y from -1 to 2
Z from 2 to 3
i did that in matlab but i doesn't work
fun = inline('(x-5)^2+(y+6)^2+Z');
x0 = [1 1 1];
Lb=[0 -1 2];
Ub=[1 2 3];
[x,fval,exitflag,output] = fminsearch(fun,x0,Lb,Ub);
disp(fval)
it gives me error
Error in fminsearch (line 190)
fv(:,1) = funfcn(x,varargin{:});
Error in Untitled (line 5)
[x,fval,exitflag,output] = fminsearch(fun,x0,Lb,Ub);
can you help me with that problem
thank you
Walter Roberson
Walter Roberson 2015 年 11 月 30 日
fminsearch does not permit boundary conditions. As John indicated, you need to use fmincon() or you need to get the fminsearchbnd File Exchange contribution.
mohammed hussein
mohammed hussein 2015 年 11 月 30 日
thank you Walter Roberson i used the fmincon()
fun = inline('(x-5)^2+(y+6)^2+Z');
x0 = [1 1 1];
Lb=[0 -1 2];
Ub=[1 2 3];
[x,fval,exitflag,output] = fmincon(fun,x0,Lb,Ub);
disp(fval)
but also gives me the error
Error using fmincon (line 293) Row dimension of A is inconsistent with length of b.
Error in Untitled (line 5) [x,fval,exitflag,output] = fmincon(fun,x0,Lb,Ub);
John D'Errico
John D'Errico 2015 年 11 月 30 日
Read the help for fmincon.
You cannot simply pass in a list of variables in any order as arguments and expect fmincon to know that the 3rd and 4th arguments are to be interpreted as bounds.
READ THE HELP!!!!!
[x,fval,exitflag,output] = fmincon(fun,x0,[],[],[],[],Lb,Ub);
As you were passing in those arguments, fmincon thought they were to be treated as the equations for a set of linear INEQUALITY constraints. As such, what it thought were A and b were inconsistent in size.
mohammed hussein
mohammed hussein 2015 年 11 月 30 日
Thank you john

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2015 年 11 月 30 日

1 投票

fun = @(x)(x(1)-5)^2+(x(2)+6)^2+x(3);
x0 = [1 1 1];
Lb=[0 -1 2];
Ub=[1 2 3];
[x,fval,exitflag,output] = fmincon(fun,x0,[],[],[],[],Lb,Ub);
disp(fval)
Best wishes
Torsten.

1 件のコメント

mohammed hussein
mohammed hussein 2015 年 11 月 30 日
Thank you Torsten It is working

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by