From 74ea09e973df571c98996ff47d4ab0f4e176ccd0 Mon Sep 17 00:00:00 2001
From: iliya <iliya.saroukha@hes-so.ch>
Date: Fri, 29 Sep 2023 16:10:11 +0200
Subject: [PATCH] vectors

---
 serie1/Vector.java | 106 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 106 insertions(+)
 create mode 100644 serie1/Vector.java

diff --git a/serie1/Vector.java b/serie1/Vector.java
new file mode 100644
index 0000000..ea6ee3f
--- /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) {
+
+    }
+}
-- 
GitLab