diff --git a/serie1/Vector.java b/serie1/Vector.java new file mode 100644 index 0000000000000000000000000000000000000000..ea6ee3f68ed7b5d664b206732a01d5fd24a2e914 --- /dev/null +++ b/serie1/Vector.java @@ -0,0 +1,106 @@ +import com.sun.tools.javac.util.List; + +public class Vector { + + public static double[] add(double[] lhs, double[] rhs) { + double res[] = new double[3]; + + for (int i = 0; i < res.length; i++) { + res[i] = lhs[i] + rhs[i]; + } + + return res; + } + + public static double[] scalar_mul(double[] vec, int scalar) { + double res[] = new double[3]; + + for (int i = 0; i < vec.length; i++) { + res[i] = vec[i] * scalar; + } + + return res; + } + + public static double[] sub(double[] lhs, double[] rhs) { + double invert_lhs[] = scalar_mul(lhs, -1); + double res[] = add(rhs, invert_lhs); + + return res; + } + + public static int len(double[] vec) { + return vec.length; + } + + public static double norm(double[] vec) { + double res; + + for (int i = 0; i < vec.length; i++) { + sum += vec[i]; + } + + return Math.sqrt(res); + } + + public static double[] sum(List<double[]> vec_list) { + double[] res; + for (int i = 0; i < vec_list.length; i++) { + res += add(res, vec_list[i]); + } + return res; + } + + public static double[] norms(List<double[]> vec_list) { + double[] res; + for (int i = 0; i < vec_list.length; i++) { + res += norm(vec_list[i]); + } + return res; + } + + public static double[] concat(double[] lhs, double[] rhs) { + int len = lhs.length + rhs.length; + double res[] = new double[len]; + + for (int i = 0; i < lhs.length; i++) { + res[i] = lhs[i]; + } + + for (int i = lhs.length; i < res.length; i++) { + res[i] = rhs[i - lhs.length]; + } + + return res; + } + + public static double[] sliceFrom(double vec[], int stop_idx) { + double[] res; + + if (stop_idx < 0) { + throw new Exception("Specified index: " + stop_idx + " is smaller than zero"); + } + + try { + for (int i = 0; i < stop_idx; i++) { + res[i] = vec[i]; + } + } catch (IndexOutOfBoundsException e) { + System.err.println("L'indice spécifié " + i + " dépasse la capacité du vecteur"); + } + } + + public static double[] slice(double[] vec, int start_idx, int stop_idx) { + + if (start_idx < 0 || stop_idx < 0) { + throw new Exception("Index or indices out of bounds"); + } + + double[] up_to_stop = sliceFrom(vec, stop_idx); + + } + + public static void main(String[] args) { + + } +}