Back substitution help examining code?

조회 수: 5 (최근 30일)
Erik Hoston
Erik Hoston 2020년 2월 23일
답변: Sai Sri Pathuri 2020년 2월 26일
I am examining this code for performing back substitution on naive gaussian elimination, and I can't seem to figure out where the x(j) is defined at? Or what exactly it's suppose to be prior to finding the solution x. I know that x is our solutions / solution vector to the system of equations when performing naive gaussian elimination. But I am not sure what exactly the value of a(i,j) * x(j) is at this step; is our solution vector x just suppose to be all zeros?? I am just not following how the solution vector is used in this step. Thanks for the help.
for i = n : -1 : 1
for j = i+1 : n
b(i) = b(i) - a(i,j)*x(j);
end
x(i) = b(i)/a(i,i);
end

답변 (1개)

Sai Sri Pathuri
Sai Sri Pathuri 2020년 2월 26일
Consider the system of equations as Ax = B where A is the coefficient matrix and B is the constant matrix.
In your code, the matrices a,b correspond to the matrices A, B after Gaussian elimination. For i = n, the value of j is n+1. Hence, the code inside second for loop is not executed. When j = n (the code inside second for loop run for the first time), the value of x(j) is defined as
x(j) = x(n) = b(n)/a(n,n);
And the remaining indices (1:n) of x are set to zero. The values of x for index < n is obtained by using the previous index value. For example, x(n) is used in the computation of x(n-1).

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by