在Python / Numpy / Scipy中解决未知的Matrix

时间:2013-04-06 09:03:33

标签: python numpy scipy scientific-computing finite-element-analysis

我需要为unkowns u4f1f2f3f5f6解决这个矩阵系统一个特定的FEA问题。我已经使用我的输入生成了包含数字的矩阵,需要根据这些知识来解决它。

  • 代码的行为如下:

    0 + 0 + 0 + 150*1000*u4 + 0 + 0 = −1732

因此,u4=-0.01154

  • 所以其他未知数可以通过以下方式找到:

    0 + 0 + 0 + (43:4)(−0:0115) 1000 + 0 + 0 = f1

因此f1=-500 等等....

我是初学者,熟悉numpy和python OOP的基础知识。请帮我设置一个代码。

The matrices to be solved

2 个答案:

答案 0 :(得分:1)

In [0]: import numpy as np    

In [1]: A = np.random.rand(6,6)

In [2]: a4 = A[3,:]

In [3]: u4 = -1732/a4[3]

In [4]: f = a4*u4

In [5]: f
Out[5]: 
array([ -246.6101995 ,  -589.6732277 ,  -574.67690895, -1732.        ,
       -2592.99948033, -2383.52077134])

用您的数据替换A或至少第四列a4 ...

答案 1 :(得分:1)

这是:

from __future__ import division
from numpy import asarray as ar,sum as sums

A = ar([[25,-43.3,-25,43.3,0,0],
        [-43.3,75,43.3,-75,0,0],
        [-25,43.3,50,0,-25,-43.3],
        [43.3,-75,0,150,-43.3,-75],
        [0,0,-25,-43.3,25,43.3],
        [0,0,-43.3,-75,43.3,75]])*1e3
u4 = -0.01154
B = ar([0,0,0,u4,0,0])
F = sums(A*B,axis=1)

所以你会:

>>> F
array([ -499.682,   865.5  ,     0.   , -1731.   ,   499.682,   865.5  ])