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
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -78,7 +78,18 @@ final public class Vector {
}
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) {
......@@ -159,11 +170,13 @@ final public class Vector {
}
public static Vector sum(List<Vector> vs) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
public static double norms(List<Vector> vs) {
throw new UnsupportedOperationException("This feature isn't implemented yet");
}
......
......@@ -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, 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);
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(),
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))).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(),
// 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));
}
/*
@Test
void vectorTranspose() {
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