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
francois.hofer
poo2019numeric
Commits
87bac1a3
Commit
87bac1a3
authored
5 years ago
by
fefe
Browse files
Options
Downloads
Patches
Plain Diff
Inv function tested ! Works fine Youhhhhou ! Solve function done but not tested yet !
parent
c458dcf4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/numeric/Matrix.java
+14
-2
14 additions, 2 deletions
src/main/java/ch/hepia/numeric/Matrix.java
src/test/java/ch/hepia/numeric/AppTest.java
+15
-0
15 additions, 0 deletions
src/test/java/ch/hepia/numeric/AppTest.java
with
29 additions
and
2 deletions
src/main/java/ch/hepia/numeric/Matrix.java
+
14
−
2
View file @
87bac1a3
...
@@ -105,7 +105,10 @@ public class Matrix {
...
@@ -105,7 +105,10 @@ public class Matrix {
}
}
public
Matrix
inv
()
{
public
Matrix
inv
()
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Matrix
newMat
=
this
.
adjugate
();
newMat
=
newMat
.
mul
(
1.0
/
this
.
det
());
return
newMat
;
}
}
public
double
det
()
{
public
double
det
()
{
...
@@ -202,7 +205,16 @@ public class Matrix {
...
@@ -202,7 +205,16 @@ public class Matrix {
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
}
}
public
static
Vector
solve
(
Matrix
m
,
Vector
b
)
{
public
static
Vector
solve
(
Matrix
m
,
Vector
b
)
{
throw
new
UnsupportedOperationException
(
"This feature isn't implemented yet"
);
Matrix
newMat
=
m
.
inv
();
List
<
Double
>
newLst
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
newMat
.
nbCols
();
i
++){
double
tot
=
0.0
;
for
(
int
y
=
0
;
y
<
b
.
len
();
y
++){
tot
+=
newMat
.
cols
().
get
(
y
).
get
(
i
)
*
b
.
get
(
i
);
}
newLst
.
add
(
tot
);
}
return
Vector
.
of
(
newLst
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/numeric/AppTest.java
+
15
−
0
View file @
87bac1a3
...
@@ -240,4 +240,19 @@ class VectorTest {
...
@@ -240,4 +240,19 @@ class VectorTest {
return
(
double
)
i
+
j
;
return
(
double
)
i
+
j
;
}));
}));
}
}
@Test
void
matrixInv
()
{
List
<
Vector
>
lstVec
=
new
ArrayList
<>();
lstVec
.
add
(
Vector
.
of
(
1.0
,
1.0
,
2.0
));
lstVec
.
add
(
Vector
.
of
(
1.0
,
2.0
,
1.0
));
lstVec
.
add
(
Vector
.
of
(
2.0
,
1.0
,
1.0
));
Matrix
m
=
Matrix
.
of
(
lstVec
);
lstVec
=
new
ArrayList
<>();
lstVec
.
add
(
Vector
.
of
(-
0.25
,
-
0.25
,
0.75
));
lstVec
.
add
(
Vector
.
of
(-
0.25
,
0.75
,
-
0.25
));
lstVec
.
add
(
Vector
.
of
(
0.75
,
-
0.25
,
-
0.25
));
assertEquals
(
m
.
inv
(),
Matrix
.
of
(
lstVec
));
}
}
}
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