diff --git a/src/main/java/ch/hepia/numeric/Vector.java b/src/main/java/ch/hepia/numeric/Vector.java index d210742e36bae5513ad8ee5176c15633db40a1c8..0a4613a8ab191b58917d873881186550e0c2fa02 100644 --- a/src/main/java/ch/hepia/numeric/Vector.java +++ b/src/main/java/ch/hepia/numeric/Vector.java @@ -1,16 +1,21 @@ package ch.hepia.numeric; import java.util.List; +import java.util.ArrayList; import java.util.function.DoubleFunction; import java.util.function.Function; final public class Vector { + private List<Double> values; + private Vector() {} private Vector(Double... elements) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + List<Double> vec = new ArrayList<>(); + for (double elem : elements){vec.add(elem);} + this.values = vec; } private Vector(List<Double> elements) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + this.values = elements; } public Transposed t() { @@ -18,18 +23,22 @@ final public class Vector { } public int len() { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + return this.values.size(); } public double get(int i) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + return this.values.get(i); } void set(int i, double value) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + this.values.set(i, value); } public Vector add(Vector that) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + List<Double> newVec = new ArrayList<>(); + for(int i=0; i < this.len();i++){ + newVec.add(this.get(i)+that.get(i)); + } + return new Vector(newVec); } public Vector mul(double m) { @@ -77,7 +86,7 @@ final public class Vector { } public static Vector of(Double... elements) { - throw new UnsupportedOperationException("This feature isn't implemented yet"); + return new Vector(elements); } public static Vector of(List<Double> elements) {