-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaVsCpp.txt
More file actions
91 lines (75 loc) · 2.61 KB
/
JavaVsCpp.txt
File metadata and controls
91 lines (75 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include "helper.h"
#include "equation_matrix_solver.h"
#include <memory>
#include "matrix.h"
#include "array.h"
#include "curve.h"
#include "incident_field.h"
#include <vector>
#include "discretization.h"
#include "incident_field_package.h"
#include "curve_package.h"
#include "timer.h"
#include <complex>
#include <math.h>
inline complex<double> kernel(const double& x1, const double& x2, const double& y1, const double &y2) {
const double k = 5 * M_PI;
return h2(k * sqrt(sqr(x1 - y1) + sqr(x2 - y2)));
}
int main() {
size_t size = 3000;
Matrix<complex<double>>* matrix = new Matrix<complex<double>>(size);
Array<double>* chebyshevPoints = new Array<double>(size);
for (size_t i = 0; i < size; i++) {
double arg = M_PI * (double)(2*i+1)/(2*size);
(*chebyshevPoints)[i] = cos(arg);
//cout << arg << " " << (*chebyshevPoints)[i] << endl;
}
Timer timer;
timer.start();
for (size_t i = 0; i < size; i++) {
//cout << endl;
for (size_t j = 0; j < size; j++) {
(*matrix)[i][j] = kernel((*chebyshevPoints)[i], 0, (*chebyshevPoints)[j], 0);
//cout << (*matrix)[i][j] << " " ;
}
}
timer.stop();
std::cout << "calculation time:" <<std::endl;
std::cout << timer.interval()<<std::endl;
delete matrix;
delete chebyshevPoints;
return 0;
}
package restservice;
import cern.jet.math.Bessel;
import org.jscience.mathematics.number.Complex;
public class Main {
public final static int MATRIX_SIZE=3000;
public final static double K = Math.PI * 5;
public static void main(String[] args) {
double[] chebyshevPoints = new double[MATRIX_SIZE];
for (int i=0; i < MATRIX_SIZE; i++) {
chebyshevPoints[i] = Math.cos(Math.PI * ((double)(2*i+1) / (2*MATRIX_SIZE)));
// System.out.println("chebyshevPoints[" + i + "] = " + chebyshevPoints[i]);
}
long startTime = System.currentTimeMillis();
Complex[][] matrix = new Complex[MATRIX_SIZE][MATRIX_SIZE];
for (int i=0; i < MATRIX_SIZE; i++) {
//System.out.println();
for (int j = 0; j < MATRIX_SIZE; j++) {
matrix[i][j] = kernel(chebyshevPoints[i], 0, chebyshevPoints[j], 0);
//System.out.print(matrix[i][j] + " ");
}
}
long finishTime = System.currentTimeMillis();
System.out.println("Calculation time: " + (double)(finishTime-startTime)/1000);
}
public static Complex HankelSecondKindZeroOrder(double x) {
return Complex.valueOf(Bessel.j0(x),-Bessel.y0(x));
}
public static Complex kernel(double x1, double x2, double y1, double y2) {
return HankelSecondKindZeroOrder( K * Math.sqrt(Math.pow(x1 - y1, 2) + Math.pow(x2 - y2, 2)) );
}
}