Find the key for vector transformation

1 回表示 (過去 30 日間)
Ali
Ali 2022 年 9 月 27 日
コメント済み: Ali 2022 年 11 月 27 日
Hello friends, Below is the optimization work. Even though I woked with fminsearch and similar tools, I cannot figure this out. Any help? Thank you very much. A & B & KEY are vectors of same length. the KEY is unknown. find the KEY such that minimize the function B-A(KEY).
clc;clear
A= [25 21.2 0.4 3.5 15 60 14 8.1 16.9 1.1];
KEY= [3 5 8 1 10 9 7 6 2 4];
B= A(KEY) + rand(1,10);

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 27 日
You do not want to minimize B-A(KEY): those are vectors and you cannot minimize a vector.
A= [25 21.2 0.4 3.5 15 60 14 8.1 16.9 1.1];
KEY= [3 5 8 1 10 9 7 6 2 4];
B= A(KEY) + rand(1,10);
Kp = perms(KEY);
values = sum((B - A(Kp)).^2,2);
[bestresult, idx] = min(values);
bestresult
bestresult = 3.4348
Kp(idx,:)
ans = 1×10
3 5 8 1 10 9 7 6 2 4
  5 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 28 日
That's why I was talking about custom functions to enforce integer permutation.
Ali
Ali 2022 年 9 月 28 日
Thank you so much, I will try ga.

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 9 月 28 日
  1 件のコメント
Ali
Ali 2022 年 11 月 27 日
Thank you for late reply. I saw your comment now, I appreciate and take a look.

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

カテゴリ

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