新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何求解線性方程組?
小編介紹過python中使用scipy.linalg模塊計算矩陣的行列式的方法,既然scipy.linalg模塊可以進行線性計算,那是不是可以求解線性方程組,答案當然是可以的,使用scipy.linalg.solve()就可以簡單的實現(xiàn)求解線性方程組,本文介紹python中使用scipy.linalg.solve()求解線性方程組的過程。

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、欽州ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學管理、有技術(shù)的欽州網(wǎng)站制作公司
一、導入scipy.linalg模塊
import numpy as np #導入numpy庫 from scipy import linalg as lg #導入scipy庫的linalg模塊 arr=np.array([[1,2],[3,4]]) #創(chuàng)建方陣arr b=np.array([6,14]) #創(chuàng)建矩陣b
二、使用scipy.linalg.solve()求解線性方程組
使用格式
print('Sol:',lg.solve(arr,b)) #求方程組arr*x=b的解使用實例
# 求解線性方程組 from scipy import linalg import numpy as np # x1 + x2 + 7*x3 = 2 # 2*x1 + 3*x2 + 5*x3 = 3 # 4*x1 + 2*x2 + 6*x3 = 4 A = np.array([[1, 1, 7], [2, 3, 5], [4, 2, 6]]) # A代表系數(shù)矩陣 b = np.array([2, 3, 4]) # b代表常數(shù)列 x = linalg.solve(A, b) print(x)
輸出
[0.6 0.35 0.15]
以上就是python中使用scipy.linalg.solve()求解線性方程組的過程,希望能幫助你解決問題喲~
網(wǎng)站標題:創(chuàng)新互聯(lián)Python教程:python如何求解線性方程組?
本文鏈接:http://fisionsoft.com.cn/article/djejpeh.html


咨詢
建站咨詢
