Generate a vector of equations using loop
古いコメントを表示
I have bunch of quadratic terms that I want to transform them into a vector of quadratic equations.
nlcon_funs=cell(size_con,1);
for i=1:size_con
nlcon_funs{i}=@(x) x'*Qc{i}*x+lc{i}'*x;
end
nlcon=@(x) nlcon_funs;
Where nlcon is a vector of equations which is expected to have the form
@(x) [x'*Qc{2}*x+lc{2}'*x;x'*Qc{2}*x+lc{2}'*x;...]
Since I have Qc and lc with pretty big size, it is impossible for me to write out nlcon directly, that's why I was trying to use a loop to create such form
@(x) [x'*Qc{2}*x+lc{2}'*x;x'*Qc{2}*x+lc{2}'*x;...]
with given Qc and lc. However, it does not work as expected. Can someone tell me where I went wrong and how to fix it thanks!
1 件のコメント
Stephen23
2016 年 1 月 10 日
回答 (1 件)
Walter Roberson
2016 年 1 月 7 日
If you are using fmincon or similar then the nlcon cannot be a vector of function handles: it would have to be a single function that invoked the vector of handles on each argument, such as
nlcon = @(x) cellfun(@(fun) fun(x), nlcon_funs)
But then you might as well
nlcon = @(x) cellfun(@(QC,LC) x'*QC*x + LC'*x, qc, lc)
which removes the problem of building the function handles.
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!