-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.java
75 lines (68 loc) · 3.16 KB
/
Util.java
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
// Title : Util.java
// Description : This class contains useful static methods
// regarding discretisations of affine functions.
// Author : Léo Martire.
// Date : 2016.
// Notes : None.
package BrownianGenerator;
import java.util.Arrays; // useful ?
import java.util.Locale; // for double formatting
public class Util{
// Attributes //---------------------------------------------
//-----------------------------------------------------------
// Constructors //-------------------------------------------
//-----------------------------------------------------------
// Methods //------------------------------------------------
public static double[] concat(double[] a, double[] b){
// Concatenate two double arrays.
// @param a the first array
// @param b the second array
// @return an array containing a and b at the end of a
double[] c= new double[a.length+b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
public static double[] fillWithStep(int size, double startPoint, double stp){
// Fills an array of given size with values starting at a certain one and incrementing by a fixed step.
// @param size the wanted size
// @param startPoint the first value of the array
// @param stp the step by which to increment
// @return an array of wanted size with values starting at the wanted one and incrementing by the given step
double[] arr=new double[size];
arr[0]=startPoint;
for(int i=1; i<size; i++){
arr[i]=arr[i-1]+stp;
}
return(arr);
}
public static double[] getTriangleCoefs(int j, int k){
// Get the two coefficients encoding the two affine lines encoding the (j, k) non-normalised Faber-Schauder function.
// @param j j index of the non-normalised Faber-Schauder function
// @param k k index of the non-normalised Faber-Schauder function
// @return [a1, b1, a2, b2] where the first slope of the (j, k) non-normalised Faber-Schauder function is given by (a1 * x + b1) and the second one by (a2 * x + b2)
double[] r={Math.pow(2, (double)(j)/2),
-k*Math.pow(2, -(double)(j)/2),
-Math.pow(2, (double)(j)/2),
(k+1)*Math.pow(2, -(double)(j)/2)};
return(r);
}
public static double[] sample(double[] abscissas, double a, double b){
// Samples over a given array of abcsissas an affine function given by its characteristic coefficients.
// @param abscissas table containing the wanted abscissas
// @param a slope of the affine function
// @param b offset at x=0 of the affine function
// @return a table containing (a * x + b) evaluated for all x in the abscissas table
double[] r=new double[abscissas.length];
for(int i=0; i<abscissas.length; i++){
r[i]=a*abscissas[i]+b;
}
return(r);
}
public static String formatDouble(double d){
// Formats a double into a #,#
String str=(d<0?"":" ")+String.format(Locale.US, "%.16e", d);
return(str);
}
//-----------------------------------------------------------
}