Optimization of a unknown vector variable

Hello ,
I have a code
a,b -----> variables should be vector(like a=[a1,a2,a3,a4])
x=h1*a^2+h2*b^2+h3;------>objctive fun(h1,h2,h3 are constants let say which has 1*4 value)
---->constraints are also present here.. so I am writting the code like
for i=1:4
x(i)=h1(i)*a^2+h2(i)*b^2+h3(i)
end
obj=sum(x);----->(objective function is basically summation of x )
x0=[1,1];
lb = [];
ub = [];
Aeq = [];
beq =[];
A = [];
b = [];
fun=@(p) obj(p(1),p(2));
nonlcon =@constraintfcn;
opts = optimoptions('fmincon','Display','iter','Algorithm','sqp');
[x_value,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,opts);
But I am not getting the ans,I want optimized value as vector .

2 件のコメント

Matt J
Matt J 2020 年 11 月 27 日
Quite unclear, I'm afraid. What is the for-loop supposed to be doing? Do you have more than one objective to minimize? Why does the right hand side not depend on i?
Soumili Sen
Soumili Sen 2020 年 11 月 28 日
編集済み: Soumili Sen 2020 年 11 月 28 日
yes, you are right. My objective function is summation of 'x' (I have modified my code), and the unknown optimized veriables are vector. so how can I continue to find the values?

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

 採用された回答

Matt J
Matt J 2020 年 11 月 28 日
編集済み: Matt J 2020 年 11 月 28 日

0 投票

H1=sum(h1);
H2=sum(h2);
H3=sum(h3);
obj=@(a,b) H1.*a.^2 +H2.*b.^2+H3;
x0=[1,1];
lb = [];
ub = [];
Aeq = [];
beq =[];
A = [];
b = [];
fun=@(p) obj(p(1),p(2));
nonlcon =@constraintfcn;
opts = optimoptions('fmincon','Display','iter','Algorithm','sqp');
[x_value,fval] = fmincon( fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,opts);

12 件のコメント

Soumili Sen
Soumili Sen 2020 年 11 月 28 日
Thanks for response, but here we are getting a single value of a & b.like
x_value= 1.23,2.3 ---> (values of a and b corresponding)
but I want optimizd value as a=4 values(like a1,a2,a3,a4) and b=4 values.
here I am using unknown veriable declaration as
syms a b;
for my desire output can I write it like
a=sym('a',[1 4]);
If it possible,how can I further proceed?
Matt J
Matt J 2020 年 11 月 28 日
The objective function that you have shown us is only dependent on a single a and b. You have not shown us an 8 variable objective function.
Soumili Sen
Soumili Sen 2020 年 11 月 28 日
ok.sorry for my mistake.how I can resolve this problem according to my desire output?
Matt J
Matt J 2020 年 11 月 28 日
You must show us the objective function that you really want. I still don't know what it is.
John D'Errico
John D'Errico 2020 年 11 月 28 日
As it is, with the objective function shown, the min lies at all zeros for the vector a, since the objective function is just a weighted sum of the squares of the elements in a. That assumes all the elements in h are non-negative. If any element of h is negative, then no minimum exists.
As Matt says, if this does not satisfy the problem (I doubt it will) then more information is needed.
Soumili Sen
Soumili Sen 2020 年 11 月 28 日
編集済み: Soumili Sen 2020 年 11 月 28 日
ok, below I have modified the representation of my objective function,
h1=rand(1,4);
h2=rand(1,4);
h3=rand(1,4);
a=sym('a',[1 4]);
b=sym('b',[1 4]);
x=h1.*a+h2.*b+h3;
for i=1:4
x1(i)=norm(x(i));
end
obj=sum(x1)
How I can optimized this a values and b values? thanks in advance.
Matt J
Matt J 2020 年 11 月 28 日
編集済み: Matt J 2020 年 11 月 28 日
Similar to fun() below, nonlcon must accept input in the form of a 4x2 matrix p.
obj=@(a,b) dot(h1,a)+dot(h2,b)+sum(h3);
fun=@(p) obj(p(:,1),p(:,2));
[x_value,fval] = fmincon(fun,ones(4,2),[],[],[],[],nonlcon,opts);
Soumili Sen
Soumili Sen 2020 年 11 月 29 日
yah,the code is running. Thank you so much to clarify the doubts. I have one question i.e,
if I want complex value of 'a' (a,a2,a3,a4 are complex in nature) then how the code will be modified?
Matt J
Matt J 2020 年 11 月 29 日
If a=ar+ac*1i, then you must rewrite the problem with ar and ac (which are real-valued) as the unknowns.
Soumili Sen
Soumili Sen 2020 年 11 月 29 日
ok,thanks
Matt J
Matt J 2020 年 11 月 29 日
You're welcome, but please Accept-click the answer if you consider the matter resolved.
Soumili Sen
Soumili Sen 2020 年 11 月 29 日
yah sure.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLinear Programming and Mixed-Integer Linear Programming についてさらに検索

質問済み:

2020 年 11 月 27 日

コメント済み:

2020 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by