v_1、v_2、v_3、v_4、v_5 の 5 つのベクトルがあるとします。これらのベクトルにはそれぞれ、最小値から最大値までの範囲の値が含まれています。たとえば、次のようになります。
v_1 = minimum_value:step:maximum_value;
これらのベクトルはそれぞれ同じステップ サイズを使用しますが、最小値と最大値は異なります。このように、それぞれ長さが異なります。
関数 F(v_1, v_2, v_3, v_4, v_5) はこれらのベクトルに依存しており、それらの要素の任意の組み合わせを使用できます。(説明が下手で申し訳ありません)。F の最大値を見つけて、その結果の値を記録しようとしています。私の現在のアプローチは、ベクトル要素のすべての組み合わせに対して関数を実行するために、示されているように複数の組み込み for ループを使用することでした。
% Set the temp value to a small value
temp = 0;
% For every combination of the five vectors use the equation. If the result
% is greater than the one calculated previously, store it along with the values
% (postitions) of elements within the vectors
for a=1:length(v_1)
for b=1:length(v_2)
for c=1:length(v_3)
for d=1:length(v_4)
for e=1:length(v_5)
% The function is a combination of trigonometrics, summations,
% multiplications etc..
Result = F(v_1(a), v_2(b), v_3(c), v_4(d), v_5(e))
% If the value of Result is greater that the previous value,
% store it and record the values of 'a','b','c','d' and 'e'
if Result > temp;
temp = Result;
f = a;
g = b;
h = c;
i = d;
j = e;
end
end
end
end
end
end
ステップサイズが小さい場合、これは非常に遅くなります。各ベクトルに約 100 個の要素がある場合、組み合わせの数は約 100*100*100*100*100 になります。適切に収束した答えを得るには小さなステップ値が必要なので、これは問題です。
Vectorizationまたはその他の方法を使用してこれを高速化できるかどうか疑問に思っていました。計算の前に組み合わせを生成することも検討していましたが、これは現在の方法よりもさらに遅いように見えました。私は長い間Matlabを使用していませんが、埋め込まれたforループの数を見るだけで、これは間違いなく高速化できると思います。提案していただきありがとうございます。