プログラムリスト
VBAのプログラムリストは以下のようになります。
'N=行列式の次数
'A(N,N)=固有値を求める行列
'B(N,N)=相似変換行列
'BINV(N,N)=相似変換の逆行列
'C(N,N)=相似変換後の行列
Dim U1(5, 201), U2(5, 201), V1(5, 201), V2(5, 201), Hx(5, 5), Hy(5, 5), Hz(5, 5), Ht(5, 5), Hm(5, 5)
Dim Hzy(5, 5), Hzyx(5, 5), Hzyxm(5, 5), Hzyxmt(5, 5)
Dim N, Ox, Oy, Oz, Mx, My, Mz, Rz, Ry, Rx, Rad
Sub Main()
Rad = 3.141592654 / 180
N = Sheets("Sheet1").Cells(4, 3).Value
Ox = Sheets("Sheet1").Cells(5, 3).Value
Oy = Sheets("Sheet1").Cells(6, 3).Value
Oz = Sheets("Sheet1").Cells(7, 3).Value
Mx = Sheets("Sheet1").Cells(8, 3).Value
My = Sheets("Sheet1").Cells(9, 3).Value
Mz = Sheets("Sheet1").Cells(10, 3).Value
Rz = Sheets("Sheet1").Cells(11, 3).Value
Ry = Sheets("Sheet1").Cells(12, 3).Value
Rx = Sheets("Sheet1").Cells(13, 3).Value
SetMat
For i = 1 To N
U1(1, i) = Sheets("Sheet1").Cells(17 + i, 2).Value
U1(2, i) = Sheets("Sheet1").Cells(17 + i, 3).Value
U1(3, i) = Sheets("Sheet1").Cells(17 + i, 4).Value
U1(4, i) = 1
U2(1, i) = Sheets("Sheet1").Cells(17 + i, 5).Value
U2(2, i) = Sheets("Sheet1").Cells(17 + i, 6).Value
U2(3, i) = Sheets("Sheet1").Cells(17 + i, 7).Value
U2(4, i) = 1
Next i
ExeMat
For i = 1 To N
Sheets("Sheet1").Cells(17 + i, 8).Value = V1(1, i)
Sheets("Sheet1").Cells(17 + i, 9).Value = V1(2, i)
Sheets("Sheet1").Cells(17 + i, 10).Value = V1(3, i)
Sheets("Sheet1").Cells(17 + i, 11).Value = V2(1, i)
Sheets("Sheet1").Cells(17 + i, 12).Value = V2(2, i)
Sheets("Sheet1").Cells(17 + i, 13).Value = V2(3, i)
Next i
Draw
End Sub
Sub SetMat()
For i = 1 To 4
For j = 0 To 4
Hx(i, j) = 0: Hy(i, j) = 0
Hz(i, j) = 0: Ht(i, j) = 0: Hm(i, j) = 0
Next j
Hx(i, i) = 1: Hy(i, i) = 1
Hz(i, i) = 1: Ht(i, i) = 1: Hm(i, i) = 1
Next i
Hx(2, 2) = Cos(Rx * Rad): Hx(2, 3) = -Sin(Rx * Rad)
Hx(3, 2) = Sin(Rx * Rad): Hx(3, 3) = Cos(Rx * Rad)
Hy(1, 1) = Cos(Ry * Rad): Hy(1, 3) = Sin(Ry * Rad)
Hy(3, 1) = -Sin(Ry * Rad): Hy(3, 3) = Cos(Ry * Rad)
Hz(1, 1) = Cos(Rz * Rad): Hz(1, 2) = -Sin(Rz * Rad)
Hz(2, 1) = Sin(Rz * Rad): Hz(2, 2) = Cos(Rz * Rad)
Ht(1, 4) = Ox: Ht(2, 4) = Oy: Ht(3, 4) = Oz
Hm(1, 1) = Mx: Hm(2, 2) = My: Hm(3, 3) = Mz
For k = 1 To 4
For i = 1 To 4
Hzy(i, k) = 0
For j = 0 To 4
Hzy(i, k) = Hzy(i, k) + Hy(i, j) * Hz(j, k)
Next j
Next i
Next k
For k = 1 To 4
For i = 1 To 4
Hzyx(i, k) = 0
For j = 0 To 4
Hzyx(i, k) = Hzyx(i, k) + Hx(i, j) * Hzy(j, k)
Next j
Next i
Next k
For k = 1 To 4
For i = 1 To 4
Hzyxm(i, k) = 0
For j = 0 To 4
Hzyxm(i, k) = Hzyxm(i, k) + Hm(i, j) * Hzyx(j, k)
Next j
Next i
Next k
For k = 1 To 4
For i = 1 To 4
Hzyxmt(i, k) = 0
For j = 0 To 4
Hzyxmt(i, k) = Hzyxmt(i, k) + Ht(i, j) * Hzyxm(j, k)
Next j
Next i
Next k
End Sub
Sub ExeMat()
For k = 1 To N
For i = 1 To 4
V1(i, k) = 0
V2(i, k) = 0
For j = 0 To 4
V1(i, k) = V1(i, k) + Hzyxmt(i, j) * U1(j, k)
V2(i, k) = V2(i, k) + Hzyxmt(i, j) * U2(j, k)
Next j
Next i
Next k
End Sub
Zmax = 0: Zmin = 10000
Ymax = 0: Ymin = 10000
For k = 1 To N
If V1(2, k) > Ymax Then Ymax = V1(2, k)
If V2(2, k) > Ymax Then Ymax = V2(2, k)
If V1(3, k) > Zmax Then Zmax = V1(3, k)
If V2(3, k) > Zmax Then Zmax = V2(3, k)
If V1(2, k) < Ymin Then Ymin = V1(2, k)
If V2(2, k) < Ymin Then Ymin = V2(2, k)
If V1(3, k) < Zmin Then Zmin = V1(3, k)
If V2(3, k) < Zmin Then Zmin = V2(3, k)
Next k
DY = Ymax - Ymin
DZ = Zmax - Zmin
If DY > DZ Then
mag = 500 / DY
Else
mag = 500 / DZ
End If
For k = 1 To N
Y1 = (V1(2, k) - Ymin) * mag + 10
Y2 = (V2(2, k) - Ymin) * mag + 10
Z1 = (Zmax - V1(3, k)) * mag + 10
Z2 = (Zmax - V2(3, k)) * mag + 10
Sheets("Sheet2").Shapes.AddLine(Y1, Z1, Y2, Z2).Select
Next k
End Sub