mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-25 05:22:39 +08:00
style: enable ParameterName
in CheckStyle. (#5196)
* Enabled: ParameterName in CheckStyle. * Refactored to fix bug caused by selfAssignment of variables in VectorCrossproduct class
This commit is contained in:

committed by
GitHub

parent
2568b96784
commit
c42b1c940c
@ -15,12 +15,12 @@ public final class Convolution {
|
||||
* signal must start from 0. If you have a signal that has values before 0
|
||||
* then shift it to start from 0.
|
||||
*
|
||||
* @param A The first discrete signal
|
||||
* @param B The second discrete signal
|
||||
* @param a The first discrete signal
|
||||
* @param b The second discrete signal
|
||||
* @return The convolved signal
|
||||
*/
|
||||
public static double[] convolution(double[] A, double[] B) {
|
||||
double[] convolved = new double[A.length + B.length - 1];
|
||||
public static double[] convolution(double[] a, double[] b) {
|
||||
double[] convolved = new double[a.length + b.length - 1];
|
||||
|
||||
/*
|
||||
The discrete convolution of two signals A and B is defined as:
|
||||
@ -35,10 +35,10 @@ public final class Convolution {
|
||||
*/
|
||||
for (int i = 0; i < convolved.length; i++) {
|
||||
convolved[i] = 0;
|
||||
int k = Math.max(i - B.length + 1, 0);
|
||||
int k = Math.max(i - b.length + 1, 0);
|
||||
|
||||
while (k < i + 1 && k < A.length) {
|
||||
convolved[i] += A[k] * B[i - k];
|
||||
while (k < i + 1 && k < a.length) {
|
||||
convolved[i] += a[k] * b[i - k];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
@ -6,34 +6,34 @@ public final class Gaussian {
|
||||
private Gaussian() {
|
||||
}
|
||||
|
||||
public static ArrayList<Double> gaussian(int mat_size, ArrayList<Double> matrix) {
|
||||
public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix) {
|
||||
ArrayList<Double> answerArray = new ArrayList<Double>();
|
||||
int i;
|
||||
int j = 0;
|
||||
|
||||
double[][] mat = new double[mat_size + 1][mat_size + 1];
|
||||
double[][] x = new double[mat_size][mat_size + 1];
|
||||
double[][] mat = new double[matSize + 1][matSize + 1];
|
||||
double[][] x = new double[matSize][matSize + 1];
|
||||
|
||||
// Values from arraylist to matrix
|
||||
for (i = 0; i < mat_size; i++) {
|
||||
for (j = 0; j <= mat_size; j++) {
|
||||
for (i = 0; i < matSize; i++) {
|
||||
for (j = 0; j <= matSize; j++) {
|
||||
mat[i][j] = matrix.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
mat = gaussianElimination(mat_size, i, mat);
|
||||
answerArray = valueOfGaussian(mat_size, x, mat);
|
||||
mat = gaussianElimination(matSize, i, mat);
|
||||
answerArray = valueOfGaussian(matSize, x, mat);
|
||||
return answerArray;
|
||||
}
|
||||
|
||||
// Perform Gaussian elimination
|
||||
public static double[][] gaussianElimination(int mat_size, int i, double[][] mat) {
|
||||
public static double[][] gaussianElimination(int matSize, int i, double[][] mat) {
|
||||
int step = 0;
|
||||
for (step = 0; step < mat_size - 1; step++) {
|
||||
for (i = step; i < mat_size - 1; i++) {
|
||||
for (step = 0; step < matSize - 1; step++) {
|
||||
for (i = step; i < matSize - 1; i++) {
|
||||
double a = (mat[i + 1][step] / mat[step][step]);
|
||||
|
||||
for (int j = step; j <= mat_size; j++) {
|
||||
for (int j = step; j <= matSize; j++) {
|
||||
mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]);
|
||||
}
|
||||
}
|
||||
@ -42,27 +42,27 @@ public final class Gaussian {
|
||||
}
|
||||
|
||||
// calculate the x_1, x_2, ... values of the gaussian and save it in an arraylist.
|
||||
public static ArrayList<Double> valueOfGaussian(int mat_size, double[][] x, double[][] mat) {
|
||||
public static ArrayList<Double> valueOfGaussian(int matSize, double[][] x, double[][] mat) {
|
||||
ArrayList<Double> answerArray = new ArrayList<Double>();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < mat_size; i++) {
|
||||
for (j = 0; j <= mat_size; j++) {
|
||||
for (i = 0; i < matSize; i++) {
|
||||
for (j = 0; j <= matSize; j++) {
|
||||
x[i][j] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = mat_size - 1; i >= 0; i--) {
|
||||
for (i = matSize - 1; i >= 0; i--) {
|
||||
double sum = 0;
|
||||
for (j = mat_size - 1; j > i; j--) {
|
||||
for (j = matSize - 1; j > i; j--) {
|
||||
x[i][j] = x[j][j] * x[i][j];
|
||||
sum = x[i][j] + sum;
|
||||
}
|
||||
if (x[i][i] == 0) {
|
||||
x[i][i] = 0;
|
||||
} else {
|
||||
x[i][i] = (x[i][mat_size] - sum) / (x[i][i]);
|
||||
x[i][i] = (x[i][matSize] - sum) / (x[i][i]);
|
||||
}
|
||||
answerArray.add(x[i][j]);
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ public final class PronicNumber {
|
||||
/**
|
||||
* This method checks if the given number is pronic number or non-pronic number
|
||||
*
|
||||
* @param input_number Integer value which is to be checked if is a pronic number or not
|
||||
* @param inputNumber Integer value which is to be checked if is a pronic number or not
|
||||
* @return true if input number is a pronic number, false otherwise
|
||||
*/
|
||||
static boolean isPronic(int input_number) {
|
||||
static boolean isPronic(int inputNumber) {
|
||||
// Iterating from 0 to input_number
|
||||
for (int i = 0; i <= input_number; i++) {
|
||||
for (int i = 0; i <= inputNumber; i++) {
|
||||
// Checking if product of i and (i+1) is equals input_number
|
||||
if (i * (i + 1) == input_number && i != input_number) {
|
||||
if (i * (i + 1) == inputNumber && i != inputNumber) {
|
||||
// return true if product of i and (i+1) is equals input_number
|
||||
return true;
|
||||
}
|
||||
|
@ -55,14 +55,14 @@ public class VectorCrossProduct {
|
||||
/**
|
||||
* constructor, initialises Vector with given Direction Ratios
|
||||
*
|
||||
* @param _x set to x
|
||||
* @param _y set to y
|
||||
* @param _z set to z
|
||||
* @param vectorX set to x
|
||||
* @param vectorY set to y
|
||||
* @param vectorZ set to z
|
||||
*/
|
||||
VectorCrossProduct(int _x, int _y, int _z) {
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
VectorCrossProduct(int vectorX, int vectorY, int vectorZ) {
|
||||
x = vectorX;
|
||||
y = vectorY;
|
||||
z = vectorZ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user