如何用矩阵A *(X + B)= C(不平方)求解方程

Ros*_*ose -2 python arrays numpy matrix

在python中可以解决A*x=B。但是是否有可能解决 A*(B+x)=Cx是未知向量和x1 = 0的问题,从而使我们有2个方程和2个未知值并平方?

A= np.array([[1,2,3],[3,2,1]])
B= np.array([10,20,-10])
C= np.array([0,0])

¿XX= np.array([0,1,1]) >> so that we only solve x2 and x3?

Solution: x = array([0, -40, 20])
Run Code Online (Sandbox Code Playgroud)

我知道我可以做类似A * x = B的事情,但是我想更直接地做到这一点:

A=np.array([[2,3],[2,1]])
B=np.array([-10,-30])
x=np.linalg.solve(A,B)

array([-20.,  10.])
Run Code Online (Sandbox Code Playgroud)

总而言之,我想要一个X矢量,它是(0,x2,x3),因此它成为可以求解的方程,但仍然不知道如何使用np.linalg.solve()来实现。然后系统将如下所示:

(10+x1) +( 40+2x2) - (30+3x3) = 0
(30+3x1) + (40+2x2) - (10+x3) = 0

10 + ( 40+2x2) - (30+3x3) = 0
30 + (40+2x2) - (10+x3) = 0
Run Code Online (Sandbox Code Playgroud)

只解决x2和x3

cht*_*mon 5

我们可以通过重写开始,A(x + b)= c为Ax + Ab = c,Ax = c-Ab。此外,我们有一个方程,陈述x0 =0。我们可以通过陈述一个新问题A'= [A; [1,0,0]和b'= [c-Ab; x0]。然后,我们可以像以前一样解决新问题。

import numpy as np

A = np.array([[1, 2, 3],
              [3, 2, 1]])
b = np.array([10, 20, -10])
c = np.array([0, 0])  # note this is different from the one you posted

x0 = 0   # first element of x

Aprime = np.vstack([A, [1, 0, 0]])
bprime = np.concatenate([c - A @ b, [x0]])

x = np.linalg.solve(Aprime, bprime)
Run Code Online (Sandbox Code Playgroud)

这会产生您得到的答案([0,-40,20])