SHARE
TWEET

biraj bro

a guest Feb 26th, 2020 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4. main()
  5. {
  6.  int i,j,n;
  7.  float A[40][40],x[40],z[40],e[40],zmax,emax;
  8.  printf("\nEnter the order of matrix:");
  9.  scanf("%d",&n);
  10.  printf("\nEnter matrix elements row-wise\n");
  11.  for(i=1; i<=n; i++)
  12.  {
  13.  for(j=1; j<=n; j++)
  14.  {
  15.  printf("A[%d][%d]=", i,j);
  16.  scanf("%f",&A[i][j]);
  17.  }
  18.  }
  19.  printf("\nEnter the column vector\n");
  20.  for(i=1; i<=n; i++)
  21.  {
  22.  printf("X[%d]=",i);
  23.  scanf("%f",&x[i]);
  24.  }
  25.  do
  26.  {
  27.  for(i=1; i<=n; i++)
  28.  {
  29.  z[i]=0;
  30.  for(j=1; j<=n; j++)
  31.  {
  32.  z[i]=z[i]+A[i][j]*x[j];
  33.  }
  34.  }
  35.  zmax=fabs(z[1]);
  36.  for(i=2; i<=n; i++)
  37.  {
  38.  if((fabs(z[i]))>zmax)
  39.  zmax=fabs(z[i]);
  40.  }
  41.  for(i=1; i<=n; i++)
  42.  {
  43.  z[i]=z[i]/zmax;
  44.  }
  45.  for(i=1; i<=n; i++)
  46.  {
  47.  e[i]=0;
  48.  e[i]=fabs((fabs(z[i]))-(fabs(x[i])));
  49.  }
  50.  emax=e[1];
  51.  for(i=2; i<=n; i++)
  52.  {
  53.  if(e[i]>emax)
  54.  emax=e[i];
  55.  }
  56.  for(i=1; i<=n; i++)
  57.  {
  58.  x[i]=z[i];
  59.  }
  60.  }
  61.  while(emax>0.001);
  62.  printf("\n The required eigen value is %f",zmax);
  63.  printf("\n\nThe required eigen vector is :\n");
  64.  for(i=1; i<=n; i++)
  65.  {
  66.  printf("%f\t",z[i]);
  67.  }
  68.  getch();
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top