Beruflich Dokumente
Kultur Dokumente
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a[3][3],x[5],d[3];
int i,j;
clrscr();
printf("enter the matrix");
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
scanf("%f",&a[i][j]);
}
printf("enter the matrix d");
for(i=0;i<=2;i++)
scanf("%f",&d[i]);
d[1]=d[1]-(a[1][0]/a[0][0])*d[0];
d[2]=d[2]-(a[2][0]/a[0][0])*d[0];
for(i=2;i>=0;i--)
{ a[1][i]=a[1][i]-(a[1][0]/a[0][0])*a[0][i];
a[2][i]=a[2][i]-(a[2][0]/a[0][0])*a[0][i];
}
d[2]=d[2]-(a[2][1]/a[1][1])*d[1];
for(i=2;i>=1;i--)
a[2][i]=a[2][i]-(a[2][1]/a[1][1])*a[1][i];
printf("the resulting matrix is=\n");
for(i=0;i<=2;i++)
{ for(j=0;j<=2;j++)
printf("%f\t",a[i][j]);
printf("%f",d[i]);
printf("\n");
}
x[3]=0;
x[4]=0;
for(i=2;i>=0;i--)
{
x[i]=(d[i]-(a[i][i+1]*x[i+1])-(a[i][i+2]*x[i+2]))/a[i][i];
}
for(i=0;i<=2;i++)
{printf("value of x[%d]=%f\n",i,x[i]);}
getch();
}
OUTPUT:
enter the matrix1
4
-1
1
1
-6
3
-1
-1
-1.000000
-5.000000
23.666666
-5.000000
-7.000000
49.333332
Output:
enter the matrix83
11
-4
7
52
13
3
8
29
enter the matrix d95
104
71
the error is.0001
value of x on iteration=1.144578
value of y on iteration=1.845922
value of z on iteration=1.820651
value of x on iteration=0.987680
value of y on iteration=1.411880
value of z on iteration=1.956618
value of x on iteration=1.051757
value of y on iteration=1.369263
value of z on iteration=1.961746
value of x on iteration=1.057652
value of y on iteration=1.367187
value of z on iteration=1.961708
value of x on iteration=1.057925
value of y on iteration=1.367160
value of z on iteration=1.961688
value of x on iteration=1.057928
value of y on iteration=1.367165
value of z on iteration=1.961686
value of x=1.057928
value of y=1.367165
value of z is=1.961686
value
value
value
value
value
value
value
of
of
of
of
of
of
of
z on iteration=0.999956
x on iteration=1.000000
y on iteration=-0.999997
z on iteration=0.999992
x=1.000000
y=-0.999997
z is=0.999992
OUTPUT:
enter the matrix2
-1
0
-1
2
-1
0
-1
2
enter the matrix d1
0
0
the error is.0001
eigen value=2.000000
x[0]=1.000000
x[1]=-0.500000
x[2]=0.000000
eigen value=2.500000
x[0]=1.000000
x[1]=-0.800000
x[2]=0.200000
eigen value=2.800000
x[0]=1.000000
x[1]=-1.000000
x[2]=0.428571
eigen value=3.428571
x[0]=0.875000
x[1]=-1.000000
x[2]=0.541667
eigen value=3.416667
x[0]=0.804878
x[1]=-1.000000
x[2]=0.609756
eigen value=3.414634
x[0]=0.764286
x[1]=-1.000000
x[2]=0.650000
eigen value=3.414286
x[0]=0.740586
x[1]=-1.000000
x[2]=0.673640
eigen value=3.414226
x[0]=0.726716
x[1]=-1.000000
x[2]=0.687500
eigen value=3.414216
x[0]=0.718593
x[1]=-1.000000
x[2]=0.695621
eigen value=3.414214
x[0]=0.713835
x[1]=-1.000000
x[2]=0.700378
the resulting eigen value is=3.414214
the resulting eigen vector 0.713835
-1.000000
0.700378