LoginSignup
0
0

More than 5 years have passed since last update.

sympyで「疎行列(sparse matrix)」をやってみた

Posted at

(参考)Python:FEMでの疎行列計算の利用(3次元骨組構造解析での事例)>簡単な連立一次方程式を解いてみる(1)
https://qiita.com/damyarou/items/85c7902cc658d748115e
(参考)Sparse Matrices
http://docs.sympy.org/latest/modules/matrices/sparse.html

fullscript.py
from sympy import *
var("A B C")
A=Matrix(([ 1,  5,  0,  0,  0],
          [ 0,  2,  8,  0,  0],
          [ 0,  0,  3,  9,  0],
          [ 0,  0,  0,  4, 10],
          [ 0,  0,  0,  0,  5]))

B =Matrix(([1],[2],[3],[4],[5]))
C=A.inv() * B
print("C=[",float(C[0]),float(C[1]),float(C[2]),float(C[3]),float(C[4]),"]")
# C=[ 106.0 -21.0 5.5 -1.5 1.0 ]
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