Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- #define f1(x,y,z) (17-y+2*z)/20
- #define f2(x,y,z) (-18-3*x+z)/20
- #define f3(x,y,z) (25-2*x+3*y)/20
- #define EPS 0.001
- int main()
- {
- float x0=0, y0=0, z0=0, x1, y1, z1, e1, e2, e3, e;
- int count=1;
- printf("\nCount\tx\ty\tz\n");
- do
- {
- /* Calculation */
- x1 = f1(x0,y0,z0);
- y1 = f2(x0,y0,z0);
- z1 = f3(x0,y0,z0);
- printf("%d\t%0.4f\t%0.4f\t%0.4f\n",count, x1,y1,z1);
- /* Error */
- e1 = fabs(x0-x1);
- e2 = fabs(y0-y1);
- e3 = fabs(z0-z1);
- count++;
- /* Set value for next iteration */
- x0 = x1;
- y0 = y1;
- z0 = z1;
- }while(e1>e && e2>e && e3>e);
- printf("\nSolution: x=%0.3f, y=%0.3f and z = %0.3f\n",x1,y1,z1);
- getch();
- return 0;
- }
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- /* Arrange systems of linear
- equations to be solved in
- diagonally dominant form
- and form equation for each
- unknown and define here
- */
- /* In this example we are solving
- 3x + 20y - z = -18
- 2x - 3y + 20z = 25
- 20x + y - 2z = 17
- */
- /* Arranging given system of linear
- equations in diagonally dominant
- form:
- 20x + y - 2z = 17
- 3x + 20y -z = -18
- 2x - 3y + 20z = 25
- */
- /* Equations:
- x = (17-y+2z)/20
- y = (-18-3x+z)/20
- z = (25-2x+3y)/20
- */
- /* Defining function */
- #define f1(x,y,z) (17-y+2*z)/20
- #define f2(x,y,z) (-18-3*x+z)/20
- #define f3(x,y,z) (25-2*x+3*y)/20
- #define e 0.001
- /* Main function */
- int main()
- {
- float x0=0, y0=0, z0=0, x1, y1, z1, e1, e2, e3;
- int count=1;
- printf("\nCount\tx\ty\tz\n");
- do
- {
- /* Calculation */
- x1 = f1(x0,y0,z0);
- y1 = f2(x1,y0,z0);
- z1 = f3(x1,y1,z0);
- printf("%d\t%0.4f\t%0.4f\t%0.4f\n",count, x1,y1,z1);
- /* Error */
- e1 = fabs(x0-x1);
- e2 = fabs(y0-y1);
- e3 = fabs(z0-z1);
- count++;
- /* Set value for next iteration */
- x0 = x1;
- y0 = y1;
- z0 = z1;
- }while(e1>e && e2>e && e3>e);
- printf("\nSolution: x=%0.3f, y=%0.3f and z = %0.3f\n",x1,y1,z1);
- getch();
- return 0;
- }
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- #define MAXIT 10
- #define EPS 0.001
- int main()
- {
- int i,j,n,A[20][20],X[20][2],count=1;
- float Xo[20][2],Xn[20][2],Xmax=0;
- printf("Enter the size of the matrix A : ");scanf("%d",&n);
- printf("\nEnter the elements of the %d*%d matrix A\n",n,n);
- for(i=1;i<=n;i++)
- {for(j=1;j<=n;j++)
- {printf("\nA[%d][%d] : ",n,n);scanf("%d",&A[i][j]);}
- }
- printf("\nEnter the initial Guess Vector X : \n");
- for(i=1;i<=n;i++)
- {
- printf("Enter X[%d][1] : ",i);scanf("%d",&X[i][1]);
- }
- Xo[1][1]=A[1][1]*X[1][1]+A[1][2]*X[2][1]+A[1][3]*X[3][1];
- Xo[2][1]=A[2][1]*X[1][1]+A[2][2]*X[2][1]+A[2][3]*X[3][1];
- Xo[3][1]=A[3][1]*X[1][1]+A[3][2]*X[2][1]+A[3][3]*X[3][1];
- for(i=1;i<=n;i++)
- {
- if(Xo[i][1]>Xmax)
- {Xmax = Xo[i][1];}
- }
- Xn[1][1] = Xo[1][1]/Xmax;
- Xn[2][1] = Xo[2][1]/Xmax;
- Xn[3][1] = Xo[3][1]/Xmax;
- count++;
- if((fabs(Xn[1][1]-Xo[1][1])<EPS)&&(fabs(Xn[1][1]-Xo[1][1])<EPS)&&(fabs(Xn[1][1]-Xo[1][1])<EPS)||count<MAXIT)
- printf("\nThe Required Eigen Value is : %f",Xmax);
- printf("\nThe Required Eigen Vector is :\n");
- printf("\n|%.3f|",Xn[1][1]);
- printf("\n|%.3f|",Xn[2][1]);
- printf("\n|%.3f|",Xn[3][1]);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement