0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBAでの、行列計算

Last updated at Posted at 2019-08-03

職場のPCでは、プログラミングとしてエクセルVBAしか使えないというケースが割とあるのではないでしょうか。

データ分析やシミュレーションを行う上で行列計算をよく使いますが、
VBAで3次元以上の高次元の行列計算に関する情報を入手するのに少し苦労したので、ここでメモします。

事例
 平成元年から31年までの、プロ野球チーム(全12球団)の、全試合(143と仮定)における勝敗を記録したい。

コード例

 Dim matrix(1 to 31,1 to 12,1 to 143) as long
 又は
 Dim year as long
 year = 31
 ReDim matrix(1 to 31,1 to 12,1 to 143) as long

  以上のコードで、
  (1) 「1 to 31」によって、平成元年から31年までの年度を指定しています。
  (2) 「1 to 12」によって、どのプロ野球チームかを指定しています。
    (1は巨人、2は阪神など、あらかじめ別途数字を割り振る必要は有)
  (3) 「1 to 143」によって、何試合目かを指定しています。

 ここで、巨人を「1」、勝ちを「1」、引き分けを「0」、負けを「−1」という数字で表すとすると、

 「平成30年の巨人の10試合目の試合結果は勝ちであった」という情報は、
 matrix(30,1,10) = 1
で表すことができます。

 なお、「平成29年の巨人の20試合目の結果は負けであった」という情報は、
 matrix(29,1,20) = -1
となります。

 これを使って行列の計算を簡単に行うことができます。

 実務を意識した、より具体的な使用例は、別途アップしたいと考えています。
 

 

  

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?