Dot

2つのベクトルの内積。

double vector::Dot(
  const vector&  b      // 2番目のベクトル
  );

パラメータ

b

[in] ベクトル

戻り値

スカラー

注意事項

2つの行列の内積は、行列積matrix::MatMul()です。

次は、MQL5でのベクトルのスカラー積の単純なアルゴリズムです。

double VectorDot(const vector& vector_a, const vector& vector_b)
 {
  double dot=0;
 
  if(vector_a.Size()==vector_b.Size())
    {
    for(ulong i=0; i<vector_a.Size(); i++)
        dot+=vector_a[i]*vector_b[i];
    }
 
  return(dot);
 }

 

MQL5の例

  for(ulong i=0; i<rows; i++)
    {
    vector v1=a.Row(i);
    for(ulong j=0; j<cols; j++)
       {
        vector v2=b.Row(j);
        result[i][j]=v1.Dot(v2);
       }
    }

 

Pythonの例

import numpy as np
 
a = [1, 0, 0, 1]
b = [4, 1, 2, 2]
print(np.dot(a, b))
 
>>> 6