Help with LU Decomposition in C

  • Thread starter Thread starter iasc
  • Start date Start date
  • Tags Tags
    Decomposition
Click For Summary
SUMMARY

The discussion focuses on troubleshooting a C implementation of LU decomposition. The provided code initializes matrices L and U but encounters issues during the decomposition process. Key problems include incorrect initialization of the matrices and potential division by zero when calculating U. Participants emphasize the importance of ensuring that L[i][i] is non-zero before performing division.

PREREQUISITES
  • Understanding of LU decomposition in numerical linear algebra
  • Proficiency in C programming, particularly with matrix operations
  • Familiarity with handling floating-point arithmetic and potential division errors
  • Knowledge of algorithmic complexity and optimization techniques
NEXT STEPS
  • Review the implementation of LU decomposition algorithms in C
  • Learn about matrix initialization and error handling in C
  • Explore numerical stability in LU decomposition and pivoting techniques
  • Investigate testing frameworks for validating matrix operations in C
USEFUL FOR

Students and professionals in computer science, particularly those studying numerical methods, software developers working with linear algebra applications, and anyone interested in optimizing matrix computations in C.

iasc
Messages
17
Reaction score
0
Hey, I have this code for lu decomposition but It doesn't quite work. If anyone could help me with the problem I'd be very appreciative.

Code:
for(j=0; j<N; j++)
                for(i=j+1; i<N; i++)
                  U[i][j]=0;

        for(j=0; j<N; j++)
                for(i=j+1; i<N; i++)
                        L[j][i]=0;

        for(i=0; i<N; i++)
          U[i][i]=1;
          for(i=0; i<N; i++)
          L[i][0]=A[i][0];

        for(j=1; j<N; j++)
                U[0][j]=A[0][j]/A[0][0];

        for(i=0; i<N; i++)
        {
                for(j=0; j<=i; j++)
                {
                        sum=0;
                        for(k=0; k<j; k++)
                                sum+=(L[i][k]*U[k][j]);
                        L[i][j]=A[i][j]-sum;
                }
                for(j=N-1; j>=i; j--)
                {
                      if(j!=0)
                        {
                        sum=0;
                        for(k=0; k<i; k++)
                                sum+=(L[i][k]*U[k][j]);
                        if(L[i][i]!=0)
                                U[i][j]=(A[i][j]-sum)/L[i][i];
                        }
                }
        }
 
Last edited:
Physics news on Phys.org
While there is still time to edit your post, put code tags around it so that it is readable.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
8K