Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Commits
9a1b1519
Commit
9a1b1519
authored
5 years ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
ajout de la fonction norm
parent
abbc94b6
No related branches found
No related tags found
1 merge request
!1
David
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/numeric/Vector.java
+14
-1
14 additions, 1 deletion
src/main/java/ch/hepia/numeric/Vector.java
src/test/java/ch/hepia/numeric/AppTest.java
+8
-6
8 additions, 6 deletions
src/test/java/ch/hepia/numeric/AppTest.java
with
22 additions
and
7 deletions
src/main/java/ch/hepia/numeric/Vector.java
+
14
−
1
View file @
9a1b1519
...
...
@@ -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"
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/numeric/AppTest.java
+
8
−
6
View file @
9a1b1519
...
...
@@ -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);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment