Home c++ Solution of the linear equation using LU decomposition

Solution of the linear equation using LU decomposition

Author

Date

Category

There are doubts that the dedicated formulas from the textbook in C++
Where l [n] [n] and u [n] [n] previously counted

double y [n]; // Find y [n] by formula (2.11)
Sum = 0;
for (int i = 0; i & lt; n; i ++)
  For (int k = 0; k & lt; n-1; k ++) {
    Sum + = L [i] [k] * y [k];
    y [i] = b [i] - Sum;
  }
COUT & LT; & LT; Endl & lt; & lt; "Y [n] =" & lt; & lt; Endl; // withdraw y [n]
FUNCSCREAN (Y, N);
Double x [n]; // Find X [n] by formula (2.13)
Sum = 0;
for (int i = n - 1; i & gt; = 0; i--)
  For (int k = i; k & lt; n; k ++) {
    Sum + = U [i] [k] * x [k];
    x [i] = (y [i] - Sum) / (u [i] [i]);
  }

Answer 1, Authority 100%

For example, formula 2.11 is much more like

for (int i = 0; i & lt; n; i ++) {
  Sum = 0;
  For (int k = 0; k & lt; i; k ++) {
    Sum + = L [i] [k] * y [k];
  }
  y [i] = b [i] - Sum;
}

than your

sum = 0;
for (int i = 0; i & lt; n; i ++)
  For (int k = 0; k & lt; n-1; k ++) {
    Sum + = L [i] [k] * y [k];
    y [i] = b [i] - Sum;
  }

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions