1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Lu Decomposition in C

  1. Dec 29, 2012 #1
    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 (Text):
    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: Dec 29, 2012
  2. jcsd
  3. Dec 29, 2012 #2

    phinds

    User Avatar
    Gold Member
    2016 Award

    While there is still time to edit your post, put code tags around it so that it is readable.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Lu Decomposition in C
  1. C++ . (Replies: 19)

Loading...