python - 用奇异矩阵计算求解方程组

标签 python r wolfram-mathematica linear-algebra

我有这个奇异矩阵(我称之为 A)

-3a          1         0    0
 3a    -2a - 1         2    0
 0      2a        -a-b-2    3
 0           0     a+b     -3

我正在尝试求解 Ax = 0,使得 x 中的元素之和为 1。我想根据 a 和 b 求解 x。我知道如何手动执行此操作(使用高斯消元法根据第四个分量编写所有分量,然后设置第四个分量以使解归一化)。但是有没有办法通过计算来做到这一点?我可以在 Python、Mathematica 或 R 中完成它。(或 MATLAB,但我认为没有办法在 MATLAB 中完成。)

我复制的代码是通过向矩阵添加第五行来实现的,

1    1    1    1

然后使用 QR 分解找到最小二乘解。但是,我不认为我可以这样做,因为我没有 a 和 b 的值,我想根据 a 和 b 来求解。

最佳答案

In[1]:= A = {{-3a,1,0,0}, {3a,-2a-1,2,0}, {0,2a,-a-b-2,3}, {0,0,a+b,-3}};
x = {p, q, r, s};
sol = Reduce[A.x==0 && p+q+r+s==1 && Det[A]==0, x, Backsubstitution->True]

Out[3]= (1+3*a+3*a^2+a^3+a^2*b) != 0 && 
p == 1/(1+3*a+3*a^2+a^3+a^2*b) && 
q == (3*a)/(1+3*a+3*a^2+a^3+a^2*b) && 
r == (3*a^2)/(1+3*a+3*a^2+a^3+a^2*b) && 
s == (a^3 + a^2*b)/(1+3*a+3*a^2+a^3+a^2*b)

In[4]:= x=x/.ToRules[sol (* Watch out for that denominator!!! *)];
Simplify[A.x]

Out[5]= {0, 0, 0, 0}

In[6]:= Simplify[Total[x]]

Out[6]= 1

关于python - 用奇异矩阵计算求解方程组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19057458/

相关文章:

wolfram-mathematica - 数学 : is it possible to put AxesLabel for 3D graphics at the end of the axes as in 2D?

Python 正则表达式 - 了解匹配和搜索之间的区别

python - 如何在旧的 MinMaxScaler 上重新缩放新数据库?

python - 是否可以使用 python 获取网页的前几个,比如 1K?

r - 计算某些值的累积和

wolfram-mathematica - 如何在 mathematica 中显示循环内的图

python - 单击 Scrapy 中的按钮

dplyr 的相对频率/比例

r - data.table 中与 dplyr 中不同

wolfram-mathematica - 用子列表中的第一项替换子列表