0% found this document useful (0 votes)
23 views4 pages

Doolittle Method Implementation in C

This document contains the source code for a C program that solves systems of linear equations using LU decomposition. It takes in the order of the coefficient matrix and its elements from the user. It then decomposes the matrix into lower and upper triangular matrices L and U. It uses forward and back substitution on the decomposed matrices to solve for the unknown vector x given the column vector b. It prints out the solution vector x.

Uploaded by

Prabal Acharya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Doolittle Method Implementation in C

This document contains the source code for a C program that solves systems of linear equations using LU decomposition. It takes in the order of the coefficient matrix and its elements from the user. It then decomposes the matrix into lower and upper triangular matrices L and U. It uses forward and back substitution on the decomposed matrices to solve for the unknown vector x given the column vector b. It prints out the solution vector x.

Uploaded by

Prabal Acharya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9 Nov 2018, 9:00 AM

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int i,j,k,n;
float A[30][30],L[30][30],U[30]
[30],x[30],y[30],b[30],s,t,a,c;
printf("Enter the order of the coefficient
matrix\n");
scanf("%d",&n);
printf("Enter the element of coefficient matrix
row wise\n");
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%f",&A[i][j]);
}
}
printf("Enter the column vector\n");
for(i=1;i<=n;i++){
scanf("%f",&b[i]);
}
for(i=1;i<=n;i++){
L[i][i]=1;
for(j=1;j<=n;j++){
if(i<j){
L[i][j]=0;
}
if(i>j){
U[i][j]=0;
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i<=j){
s=0;
for(k=1;k<=i-1;k++){
s=s+L[i][k]*U[k][j];
}
U[i][j]=A[i][j]-s;
}
if(i>j){
t=0;
for(k=1;k<=j-1;k++){
t=t+L[i][k]*U[k][j];
}
L[i][j]=(A[i][j]-t)/U[j][j];
}
}
}
y[1]=b[1];
for(i=2;i<=n;i++){
a=0;
for(j=1;j<=i-1;j++){
a=a+L[i][j]*y[j];
}
y[i]=b[i]-a;
}
x[n]=y[n]/U[n][n];
for(i=n-1;i>=1;i--){
c=0;
for(j=i+1;j<=n;j++){
c=c+U[i][j]*x[j];
}
x[i]=(y[i]-c)/U[i][i];
}
printf("The required solution is\n");
for(i=1;i<=n;i++){
printf("x[%d]=%6.4f\n",i,x[i]);
}
getch();
}

You might also like