symbolic matrices optimization with fmincon

1 回表示 (過去 30 日間)
ali akbar
ali akbar 2020 年 10 月 2 日
コメント済み: ali akbar 2020 年 10 月 16 日
I am trying to minimize a function. The function is , where and are defined as
chi= rand(4,4) %% for example
syms t [1 16] real
tt=[t1 0 0 0;t5+1i*t6 t2 0 0;t11+1i*t12 t7+1i*t8 t3 0;t15+1i*t16 t13+1i*t14 t9+1i*t10 t4];
tt2=[t1 0 0 0;t5-1i*t6 t2 0 0;t11-1i*t12 t7-1i*t8 t3 0;t15-1i*t16 t13-1i*t14 t9-1i*t10 t4];
chi1=simplify(transpose(tt2)*tt) %% chi1 is 4x4 matrix with 16 symbolic variables
fun=sum((chi1-chi).^2);
g=matlabFunction(fun);
rng default;
gs=GlobalSearch;
opts=optimoptions(@fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',[],'objective',g,'lb',[],'ub',[],'options',opts)
t=run(gs,problem)
and I am encountering an incessant error
PROBLEM structure should have a non-empty X0 field.
After putting arbitrary values of 'x0' (16 values), the error changes to
not enough input arguments.
Currently, not able to sort out where the problem is. Any help will be appreciated.

採用された回答

Alan Weiss
Alan Weiss 2020 年 10 月 5 日
I was able to modify your program to run. I don't know if it is correct, but at least it runs.
chi= rand(4,4) %% for example
syms t [1 16] real
t = reshape(t,4,4); % You need this for the function to be well-defined
tt=[t1 0 0 0;t5+1i*t6 t2 0 0;t11+1i*t12 t7+1i*t8 t3 0;t15+1i*t16 t13+1i*t14 t9+1i*t10 t4];
tt2=[t1 0 0 0;t5-1i*t6 t2 0 0;t11-1i*t12 t7-1i*t8 t3 0;t15-1i*t16 t13-1i*t14 t9-1i*t10 t4];
chi1=simplify(transpose(tt2)*tt) %% chi1 is 4x4 matrix with 16 symbolic variables
fun=real(sum((chi1-chi).^2,'all')); % I had to take the real part because fmincon needs real values
g=matlabFunction(fun,'vars',{t}); % This is also necessary: fmincon takes just one input argument
rng default;
gs=GlobalSearch;
opts=optimoptions(@fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',randn(4),'objective',g,'lb',[],'ub',[],'options',opts)
t=run(gs,problem)
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
ali akbar
ali akbar 2020 年 10 月 16 日
Yes Alan, Your solution also worked. I solved it the hard way where I manually changed every t1.....t16 to t(1)....t(16).
Thanks for the help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by