# On LU Decomposition in C Program

Page 1 of 1

## 2 Replies - 26745 Views - Last Post: 21 June 2010 - 04:16 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=178497&amp;s=f7afac57bf2d61b74d8c64365a071125&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 coolghuy12

Reputation: 0
• Posts: 7
• Joined: 11-January 10

# On LU Decomposition in C Program

Posted 20 June 2010 - 09:57 PM

Hi experts.

I was writing a C program on LU Decomposition.
As a start, I was able to do the following for the library file:

a is the matrix, n means the matrix a is n by n, dont mind b and c yet.
```int LU(double ** a, int n,
double ** b, double **c)
{
double p;
int i, j;
for(i=1; i < n; i++){
if( a[i][0] !=0 )
{
p = a[i][0];
for(j=0; j < n; j++){
a[i][j] = a[i][j]  - p*(a[0][j]/a[0][0]);
}
}
}
return 1;
}
```

But the following is only good for the first column of the matrix.
By the way, this screenshot shows the progress of the U MATRIX.
As you can see, this is not yet a complete U Matrix.
How do I expand the function I wrote? Thanks!

Is This A Good Question/Topic? 0

## Replies To: On LU Decomposition in C Program

### #2 taylorc8

• B&

Reputation: 150
• Posts: 1,572
• Joined: 21-July 09

## Re: On LU Decomposition in C Program

Posted 21 June 2010 - 03:06 AM

http://en.wikipedia....U_decomposition

I am a bit too stupid to understand the inputs and expected output, but is starting at 1 here intentional?

```for(i=1; i < n; i++)

```

Hey check out the Doolittle algorithm on the wiki too.

This post has been edited by taylorc8: 21 June 2010 - 03:11 AM

### #3 coolghuy12

Reputation: 0
• Posts: 7
• Joined: 11-January 10

## Re: On LU Decomposition in C Program

Posted 21 June 2010 - 04:16 AM

taylorc8, on 21 June 2010 - 02:06 AM, said:

I am a bit too stupid to understand the inputs and expected output, but is starting at 1 here intentional?

```for(i=1; i < n; i++)

```

Yes, the first row need not be transformed.
Actually I've figured out the solution a while ago. Thanks!

This post has been edited by coolghuy12: 21 June 2010 - 04:17 AM

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }