#範例9-8:用sympy判別三個向量之間,是線性獨立,或線性相依? #三個向量:v1=(1,–2,3),v2=(5,6,–1),v3=(3,2,1) #注意:因為三個向量,所以三個輸入變數k1,k2,k3 #判別向量是否為線性獨立,方法3:A_reduced_form, inds = A.rref() #inds = 記錄線性獨立的行向量index(culumn index) from sympy import * A = Matrix( [ [1, 5 ,3], [-2, 6 ,2], [3, -1 ,1] ]) A_reduced_form, inds = A.rref() print('簡化後的梯形Am=', A_reduced_form) n = A.shape[1] n_independent = len(inds) if n == n_independent: print('三個向量彼此線性獨立') else: print('三個向量彼此線性相依') print('彼此線性獨立的行數m=', inds) c1 = inds[0] c2 = inds[1] print('印出線性獨立的向量=', A[:,c1]) print('印出線性獨立的向量=', A[:,c2])