Advertisement
Guest User

power method by AShish ACharya roll number 05 kathford inter

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