1 |
< |
#include "Utility.hpp" |
2 |
< |
#include <vector> |
3 |
< |
#include <iostream> |
4 |
< |
#include <math.h> |
5 |
< |
using namespace std; |
6 |
< |
|
7 |
< |
double dotProduct(vector<double>& v1, vector<double>& v2){ |
8 |
< |
double sum; |
9 |
< |
|
10 |
< |
sum = 0; |
11 |
< |
|
12 |
< |
if(v1.size() != v2.size()){ |
13 |
< |
cerr << "Utility Error: dimension of two vectors are not matched" << endl; |
14 |
< |
exit(-1); |
15 |
< |
} |
16 |
< |
|
17 |
< |
for(int i = 0; i < v1.size(); i++) |
18 |
< |
sum += v1[i]*v2[i]; |
19 |
< |
return sum; |
20 |
< |
} |
21 |
< |
|
22 |
< |
double copysign(double sign, double value){ |
23 |
< |
double result = fabs(value); |
24 |
< |
|
25 |
< |
return sign >= 0 ? result : -result; |
26 |
< |
} |
1 |
> |
#include "Utility.hpp" |
2 |
> |
#include <vector> |
3 |
> |
#include <iostream> |
4 |
> |
#include <math.h> |
5 |
> |
using namespace std; |
6 |
> |
|
7 |
> |
double dotProduct(vector<double>& v1, vector<double>& v2){ |
8 |
> |
double sum; |
9 |
> |
|
10 |
> |
sum = 0; |
11 |
> |
|
12 |
> |
if(v1.size() != v2.size()){ |
13 |
> |
cerr << "Utility Error: dimension of two vectors are not matched" << endl; |
14 |
> |
exit(-1); |
15 |
> |
} |
16 |
> |
|
17 |
> |
for(int i = 0; i < v1.size(); i++) |
18 |
> |
sum += v1[i]*v2[i]; |
19 |
> |
return sum; |
20 |
> |
} |
21 |
> |
|
22 |
> |
double norm2(vector<double>& x){ |
23 |
> |
return sqrt(dotProduct(x, x)); |
24 |
> |
} |