Skip to content
Snippets Groups Projects
Commit 9a1b1519 authored by david's avatar david
Browse files

ajout de la fonction norm

parent abbc94b6
No related branches found
No related tags found
1 merge request!1David
...@@ -78,7 +78,18 @@ final public class Vector { ...@@ -78,7 +78,18 @@ final public class Vector {
} }
public double norm() { public double norm() {
throw new UnsupportedOperationException("This feature isn't implemented yet"); //throw new UnsupportedOperationException("This feature isn't implemented yet");
double norme=0;
double power=0;
for(int i=0;i<this.lstVector.size();i++)//a ameliorer avec for(e:element)
{
power=power +(this.lstVector.get(i)*this.lstVector.get(i));
}
norme=Math.sqrt(power);
return norme;
} }
public Vector sliceFrom(int i) { public Vector sliceFrom(int i) {
...@@ -159,11 +170,13 @@ final public class Vector { ...@@ -159,11 +170,13 @@ final public class Vector {
} }
public static Vector sum(List<Vector> vs) { public static Vector sum(List<Vector> vs) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); throw new UnsupportedOperationException("This feature isn't implemented yet");
} }
public static double norms(List<Vector> vs) { public static double norms(List<Vector> vs) {
throw new UnsupportedOperationException("This feature isn't implemented yet"); throw new UnsupportedOperationException("This feature isn't implemented yet");
} }
......
...@@ -41,16 +41,18 @@ class VectorTest { ...@@ -41,16 +41,18 @@ class VectorTest {
assertEquals(Vector.linespace(0.0, 1.0, 3), Vector.of(0.0, 0.5, 1.0)); 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)); assertEquals(Vector.linespace(0.0, 1.0, 5), Vector.of(0.0, 0.25, 0.5, 0.75, 1.0));
} }
*/
@Test @Test
void vectorNormAndSum() { void vectorNormAndSum() {
assertEquals(Vector.of(1.0, 2.0, 2.0).norm(), 3.0); assertEquals(Vector.of(1.0, 2.0, 2.0).norm(), 3.0);
assertEquals(Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))).norm(), 3.0); //assertEquals(Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))).norm(), 3.0);
assertEquals( //assertEquals(
Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))).norm(), // Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))).norm(),
Vector.norms(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))) // Vector.norms(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0)))
); // );
assertEquals(Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))), Vector.of(1.0, 2.0, 2.0)); // assertEquals(Vector.sum(List.of(Vector.of(1.0, 2.0, 1.0), Vector.of(0.0, 0.0, 1.0))), Vector.of(1.0, 2.0, 2.0));
} }
/*
@Test @Test
void vectorTranspose() { void vectorTranspose() {
Vector v1 = Vector.of(1.0, 2.0, 3.0); Vector v1 = Vector.of(1.0, 2.0, 3.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment