我正在尝试编写一个带有double_product(vector<double> a, vector<double> b)
计算两个向量的标量积的函数的程序。标量积是
$a_{0}b_{0}+a_{1}b_{1}+...+a_{n-1}b_{n-1}$.
这就是我所拥有的。这是一团糟,但我正在努力!
#include <iostream>
#include <vector>
using namespace std;
class Scalar_product
{
public:
Scalar_product(vector<double> a, vector<double> b);
};
double scalar_product(vector<double> a, vector<double> b)
{
double product = 0;
for (int i = 0; i <= a.size()-1; i++)
for (int i = 0; i <= b.size()-1; i++)
product = product + (a[i])*(b[i]);
return product;
}
int main() {
cout << product << endl;
return 0;
}