Skip to content

Commit 4874dc3

Browse files
committed
update
1 parent 5226d9b commit 4874dc3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/main/java/com/thealgorithms/maths/ChebyshevIteration.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ private static void validateInputs(
132132
}
133133

134134
// --- Vector/Matrix Helper Methods ---
135+
/**
136+
* Computes the product of a matrix A and a vector v (Av).
137+
*/
135138
private static double[] matrixVectorMultiply(double[][] a, double[] v) {
136139
int n = a.length;
137140
double[] result = new double[n];
@@ -145,10 +148,50 @@ private static double[] matrixVectorMultiply(double[][] a, double[] v) {
145148
return result;
146149
}
147150

151+
/**
152+
* Computes the subtraction of two vectors (v1 - v2).
153+
*/
148154
private static double[] vectorSubtract(double[] v1, double[] v2) {
149155
int n = v1.length;
150156
double[] result = new double[n];
151157
for (int i = 0; i < n; i++) {
152158
result[i] = v1[i] - v2[i];
153159
}
154160
return result;
161+
}
162+
163+
/**
164+
* Computes the addition of two vectors (v1 + v2).
165+
*/
166+
private static double[] vectorAdd(double[] v1, double[] v2) {
167+
int n = v1.length;
168+
double[] result = new double[n];
169+
for (int i = 0; i < n; i++) {
170+
result[i] = v1[i] + v2[i];
171+
}
172+
return result;
173+
}
174+
175+
/**
176+
* Computes the product of a scalar and a vector (s * v).
177+
*/
178+
private static double[] scalarMultiply(double scalar, double[] v) {
179+
int n = v.length;
180+
double[] result = new double[n];
181+
for (int i = 0; i < n; i++) {
182+
result[i] = scalar * v[i];
183+
}
184+
return result;
185+
}
186+
187+
/**
188+
* Computes the L2 norm (Euclidean norm) of a vector.
189+
*/
190+
private static double vectorNorm(double[] v) {
191+
double sumOfSquares = 0;
192+
for (double val : v) {
193+
sumOfSquares += val * val;
194+
}
195+
return Math.sqrt(sumOfSquares);
196+
}
197+
}

0 commit comments

Comments
 (0)