Add dot product
This commit is contained in:
parent
1f1a384c35
commit
408a97e93e
2 changed files with 19 additions and 0 deletions
12
vector.cpp
12
vector.cpp
|
@ -5,11 +5,23 @@ int main() {
|
|||
vector v = vector(3);
|
||||
cnumber one(1,0);
|
||||
cnumber two(2,0);
|
||||
cnumber three(3,0);
|
||||
cnumber four(4,0);
|
||||
cnumber five(5,0);
|
||||
cnumber i(0,1);
|
||||
v[0] = one;
|
||||
v[1] = two;
|
||||
v[2] = i;
|
||||
|
||||
vector w = vector(3);
|
||||
w[0] = three;
|
||||
w[1] = four;
|
||||
w[2] = five;
|
||||
cout << "v:" << endl;
|
||||
cout << v << endl;
|
||||
cout << "w:" << endl;
|
||||
cout << w << endl;
|
||||
cout << "v * w:" << endl;
|
||||
cout << v * w << endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -92,4 +92,11 @@ public:
|
|||
}
|
||||
return product;
|
||||
}
|
||||
const cnumber operator*(const vector &v) const {
|
||||
cnumber res(0,0);
|
||||
for (long long i = 0; i < this->get_dimention(); i++) {
|
||||
res = res + this->get_entry(i) * v.get_entry(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue