Add dot product

main
Micke Nordin 2 years ago
parent 1f1a384c35
commit 408a97e93e
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -5,11 +5,23 @@ int main() {
vector v = vector(3); vector v = vector(3);
cnumber one(1,0); cnumber one(1,0);
cnumber two(2,0); cnumber two(2,0);
cnumber three(3,0);
cnumber four(4,0);
cnumber five(5,0);
cnumber i(0,1); cnumber i(0,1);
v[0] = one; v[0] = one;
v[1] = two; v[1] = two;
v[2] = i; v[2] = i;
vector w = vector(3);
w[0] = three;
w[1] = four;
w[2] = five;
cout << "v:" << endl;
cout << v << endl; cout << v << endl;
cout << "w:" << endl;
cout << w << endl;
cout << "v * w:" << endl;
cout << v * w << endl;
return 0; return 0;
} }

@ -92,4 +92,11 @@ public:
} }
return product; 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…
Cancel
Save