FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/algorithms/math/MatrixMultiply.java at master · AllAlgorithms/java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
AllAlgorithms
/
java
Public archive
Notifications
You must be signed in to change notification settings
Fork
83
Star
116
Code
Issues
3
Pull requests
6
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
java
/
algorithms
/
math
/
MatrixMultiply.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (33 loc) · 1.07 KB
Breadcrumbs
java
/
algorithms
/
math
/
MatrixMultiply.java
Copy path
File metadata and controls
39 lines (33 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public
class
MatrixMultiply
{
/**
* Multiples 2 2-dimensional matrices together given their dimensions are
* compatible
*
* @param mat_a A 2-Dimensional matrix to be multiplied
* @param mat_b A 2-Dimensional matrix to be multiplied
* @return The product of the two matrices if compatible dimensions, null
* otherwise
*/
public
static
double
[][]
matrixMultiply2D
(
double
[][]
mat_a
,
double
[][]
mat_b
) {
int
aRows
=
mat_a
.
length
;
int
aColumns
=
mat_a
[
0
].
length
;
int
bRows
=
mat_b
.
length
;
int
bColumns
=
mat_b
[
0
].
length
;
if
(
aColumns
!=
bRows
)
throw
new
IllegalArgumentException
(
"A:Rows: "
+
aColumns
+
" did not match B:Columns "
+
bRows
+
"."
);
double
[][]
mat_result
=
new
double
[
aRows
][
bColumns
];
for
(
int
i
=
0
;
i
<
aRows
;
i
++) {
for
(
int
j
=
0
;
j
<
bColumns
;
j
++) {
mat_result
[
i
][
j
] =
0.00000
;
}
}
for
(
int
i
=
0
;
i
<
aRows
;
i
++) {
// aRow
for
(
int
j
=
0
;
j
<
bColumns
;
j
++) {
// bColumn
for
(
int
k
=
0
;
k
<
aColumns
;
k
++) {
// aColumn
mat_result
[
i
][
j
] +=
mat_a
[
i
][
k
] *
mat_b
[
k
][
j
];
}
}
}
return
mat_result
;
}
}
Back
|
FazBrowse Home
|
New Git URL