The numpy.matrix method is syntactically the simplest. However, numpy.array is the most practical.

import numpy as np
A = np.matrix([[3,6,-5],
              [1,-3,2],
              [5,-1,4]])

b = np.matrix([[12],
              [-2],
              [10]])

x = A**(-1) * b
print(x)
#output:
#[[1.75]
# [1.75]
# [0.75]]    

A = np.array([[3,6,-5],
              [1,-3,2],
              [5,-1,4]])

b = np.array([[12],
              [-2],
              [10]])

x = np.linalg.inv(A).dot(b)
print(x)
#output:
#[[1.75]
# [1.75]
# [0.75]]    

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading