Created
September 25, 2018 13:43
-
-
Save yuyosy/786c356d8b552b887186d2d6094a1f1b to your computer and use it in GitHub Desktop.
Julia <matrix>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m1 = [1 2 3] # 横行列 | |
m2 = [1; 2; 3] # 縦行列 [1, 2, 3]と同等 | |
println("m1 = ", m1) | |
println("m2 = ", m2) | |
# 2×2の行列 | |
m3 = [ | |
2 3; | |
4 5; | |
] | |
m4 = [ | |
1 2; | |
2 2; | |
] | |
println("m3 = ", m3) | |
println("m4 = ", m4) | |
println("2*m3 = ", 2m3) | |
# 転置 | |
println("m3の転置 : ",m3') | |
# 逆行列 | |
m5 = inv(m3) | |
println("m3の逆行列 : ", m5) | |
# 行列の演算 | |
println("m3-m4 = ", m3-m4) | |
println("行列の積 m3*m4 = ", m3*m4) | |
println("行列の各要素同士の積 : ", m3.*m4) | |
# 連立一次方程式 | |
# x - 2y + 3z = 1 | |
# 3x + y - 5z = -4 | |
# -2x + 6y - 9z = -2 | |
A = [1 -2 3; 3 1 -5; -2 6 -9] | |
b = [1; -4; -2] | |
x, y, z = A\b # 実行結果は[1.0, 3.0, 2.0]となるが行列の各要素を変数xyzに代入する | |
println("x = $x, y = $y, z = $z") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment