我将这个方程系统设为一组1 ≤ n ≤ 30
−(2 + α)x1 + x2 = b1,
xj−1 − (2 + α)xj + xj+1 = bj , for 2 ≤ j ≤ 29,
x29 − (2 + α)x30 = b30.
α= 1 我们假设膜保持在端点(即x0 = 0和x31 = 0)。膜上没有重量,因此对于j = 1,所有bj = 0。 。 。 30除了j = 6,其中施加负荷:b6 = 2。
我想计算系统的LU分解。 我不知道如何在matlab中实现系统的左侧。 右边我这样做了:
b=[0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]';
如何做左侧?
由于
答案 0 :(得分:0)
It's unclear why you have included the entire linear system if you are only interested in the LU factorization of A? Regardless, here is some code which generates your A matrix as described above, and solves the linear system and shows the LU factorization.
% equation A*X = b
b = zeros(30,1);
b(6) = 2;
alpha = 1;
A = zeros(30, 30);
A(1, 1) = -(2 + alpha);
A(1, 2) = 1;
for i = 2:29
A(i, i-1) = 1;
A(i, i) = -(2 + alpha);
A(i, i+1) = 1;
end
A(30, 29) = 1;
A(30, 30) = -(2 + alpha);
You can then get the LU factorization using lu(A)
or solve the linear system of equations using linsolve(A,b)
.