Skip to content
Snippets Groups Projects
Commit d55ac700 authored by tanguy.dietrich's avatar tanguy.dietrich
Browse files

Ecriture de vectorLinespace()

parent d59575d1
No related branches found
No related tags found
2 merge requests!2Tanguy,!1David
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -113,7 +113,7 @@ final public class Vector {
}
public static Vector of(List<Double> elements) {
return new Vector(elements);
return new Vector(elements);
}
public static Vector empty() {
......@@ -137,8 +137,15 @@ final public class Vector {
return Vector.fill(nb,1.0);
}
public static Vector linespace(double from, double to, int nb) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
public static Vector linespace(double from, double to, int nb)
{
double step=to/(nb-1);
Vector v = Vector.zeros(nb);
for(int i=0;i<nb;i++)
{
v.set(i,step*i);
}
return v;
}
public static Vector tabulate(int nb, Function<Integer, Double> f) {
......
......@@ -34,13 +34,13 @@ class VectorTest {
assertEquals(Vector.fill(3, 1.7), Vector.of(1.7, 1.7, 1.7));
//assertEquals(Vector.tabulate(4, i -> i*5.0), Vector.of(0.0, 5.0, 10.0, 15.0));
}
/*
@Test
void vectorLinespace() {
assertEquals(Vector.linespace(0.0, 1.0, 3), Vector.of(0.0, 0.5, 1.0));
assertEquals(Vector.linespace(0.0, 1.0, 5), Vector.of(0.0, 0.25, 0.5, 0.75, 1.0));
}
*/
@Test
void vectorNormAndSum() {
assertEquals(Vector.of(1.0, 2.0, 2.0).norm(), 3.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment