-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
55 lines (49 loc) · 1.67 KB
/
Copy pathTest.java
File metadata and controls
55 lines (49 loc) · 1.67 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
import java.util.Arrays;
/**
* Test.java, ECE4960-P4
* Created by Yuan He(yh772) on 2018/04/18
* Platform: Java 8, Eclipse, MacOS
* Copyright © 2018 Yuan He. All rights reserved.
*
* P4, Test script:
* Testings for basic functions, and validations for ODE solvers
*/
public class Test {
/**Function: Validate ODE solvers, using the example in class
* Including RK34 with adaption, RK4, and Forward-Euler solver
* @param: None
* @return: None*/
public static void validateODE() {
/* Testing data initializing*/
double xx0[] = {2};
Vector x0 = new Vector(xx0);
String fType[] = {"ODE Validation"};
double h = 1;
Vector x1 = new Vector(x0.len);
/* Testing RK34 */
System.out.println("\nTesting RK34 with the in-class example");
for(double t=0; t<4 ; t++) {
x1 = Solvers.RK34AdaptiveH(x0, t, h, fType);
x0.v = x1.v.clone();
System.out.print(Arrays.toString(x1.v) + " Error% = " + Solvers.relativeErr(x1, t, fType)+"\n");
}
/* Testing RK4 */
System.out.println("\nTesting RK4 with the in-class example");
x0 = new Vector(xx0);
for(double t=0; t<4 ; t++) {
// Extract x(RK4) out of xRK3_xRK4
x1 = Solvers.xRK3_xRK4(x0, t, h, fType).get(1);
// Update the initial x
x0.v = x1.v.clone();
System.out.print(Arrays.toString(x1.v) + " Error% = " + Solvers.relativeErr(x1, t, fType)+"\n");
}
/* Testing Forward Euler */
System.out.println("\nTesting Forward-Euler with the in-class example");
x0 = new Vector(xx0);
for(double t=0; t<4; t++) {
x1 = Solvers.forwardEuler(x0, t, h, fType);
x0.v = x1.v.clone();
System.out.print(Arrays.toString(x1.v) + " Error% = " + Solvers.relativeErr(x1, t, fType)+"\n");
}
}
}