• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision4 (tree)
Time2013-11-12 10:53:40
Authorevakichi

Log Message

Add Matrix.java

Change Summary

Incremental Difference

--- java/src/math/Test.java (revision 3)
+++ java/src/math/Test.java (revision 4)
@@ -26,6 +26,11 @@
2626 f5.printFrac();
2727 Frac f6 = Frac.div(f1, f2);
2828 f6.printFrac();
29+ int a[]={1,2,3};
30+ int b[][]={{1,2,3},{2,3,4},{3,4,5}};
31+ Matrix.printVector(Matrix.multMatrix(a, b));
32+ Matrix.printMatrix(Matrix.multMatrix(b, b));
33+
2934 }
3035
3136 }
--- java/src/math/Tips.java (revision 3)
+++ java/src/math/Tips.java (revision 4)
@@ -20,4 +20,6 @@
2020 else
2121 return Tips.gcd(l, n);
2222 }
23+
24+
2325 }
--- java/src/math/Matrix.java (nonexistent)
+++ java/src/math/Matrix.java (revision 4)
@@ -0,0 +1,54 @@
1+/**
2+ *
3+ */
4+package math;
5+
6+/**
7+ * @author ishihara
8+ *
9+ */
10+public class Matrix {
11+ public static void printVector(int[] v)
12+ {
13+ for(int i=0;i<v.length;i++)
14+ System.out.print(v[i]+" ");
15+ System.out.println();
16+ }
17+ public static void printMatrix(int[][] m)
18+ {
19+ for(int i=0;i<m.length;i++)
20+ {
21+ for(int j=0;j<m[i].length;j++)
22+ System.out.print(m[i][j]+" ");
23+ System.out.println();
24+ }
25+ System.out.println();
26+ }
27+
28+ public static int[] multMatrix(int a[],int b[][])
29+ {
30+ int c[]=new int[a.length];
31+ for(int i=0;i<a.length;i++)
32+ {
33+ c[i]=0;
34+ for(int j=0;j<b.length;j++)
35+ {
36+ c[i]+=a[j]*b[j][i];
37+ }
38+ }
39+ return c;
40+ }
41+
42+ public static int[][] multMatrix(int a[][],int b[][])
43+ {
44+ int c[][]=new int[a.length][b[0].length];
45+ for(int i=0;i<a.length;i++)
46+ for(int j=0;j<b.length;j++)
47+ {
48+ c[i][j]=0;
49+ for(int k=0;k<b[i].length;k++)
50+ c[i][j]+=a[i][k]*b[k][j];
51+ }
52+ return c;
53+ }
54+}