2
2

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.

numpyの解決例

Last updated at Posted at 2018-01-18

線型方程式(numpy.linalg.solve)

簡単の例(2次元):

x + 2y = 5
2x + 3y = 8      ⇒  x = 1, y = 2

共通公式(多次元):

a11*x1 + a12*x2 + ... + a1n*xn = b1
a21*x1 + a22*x2 + ... + a2n*xn = b2
 .
 .
am1*x1 + am2*x2 + ... + amn*xn = bm

numpy.linalg.solveで解決:

例1(2次元):

 x + 2y = 5
 2x + 3y = 8
test.py
# -*- coding: utf-8 -*-
import numpy as np

A = np.array([[1.,2.] 
             ,[2.,3.]])
B = np.array([5.,8.])

X = np.linalg.solve(A, B)
# 計算結果の表示
print(X)  

結果

array([ 1.,  2.])

例2(3次元):

 x + 2y + z = 8
 2x + 3y + 2z = 14
 3x + 4y + 3z = 20
test.py
# -*- coding: utf-8 -*-
import numpy as np

A = np.array([[1.,2.,1.] 
             ,[2.,3.,2.]
             ,[3.,4.,3.]])
B = np.array([8.,14.,20.])

X = np.linalg.solve(A, B)
# 計算結果の表示
print(X)  

結果

array([ 1.,  2.,  3.])
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?