Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <math.h>
  4.  
  5. int main() {
  6.     const max_iter = 100;
  7.     const float FirstCoef = 9.33;
  8.     const float SecondCoef = 6.977;
  9.     const float ThirdCoef = 7.25;
  10.     float a, b, Accuracy, Difference, x0, fFromDeltaMinus, fFromDeltaPlus, fFromx0, Convergence;
  11.     int k;
  12.     printf("Subject: Find the roots of the equation 9.33sin(6.977x) - 7.25x = 0 with Epsilon accuracy by a simple iteration \n");
  13.     do {
  14.         printf("Enter the span boundaries [a;b] \n");
  15.         scanf_s("%f", &a);
  16.         scanf_s("%f", &b);
  17.         Convergence = (FirstCoef * sin(SecondCoef * a) / 7.25) * (FirstCoef * sin(SecondCoef * b) / ThirdCoef);
  18.         if (Convergence < 0) {
  19.             printf("Iteration process converges \n");
  20.         } else {
  21.             printf("Iteration process does not converge \n");
  22.         }
  23.     } while (0 < Convergence);
  24.     printf("Enter accuracy value (Epsilon) \n");
  25.     scanf_s("%f", &Accuracy);
  26.     if ((Accuracy > 0) && (Accuracy > 1)) {
  27.         x0 = ((a + b) / 2);
  28.         k = 0;
  29.         while ((Accuracy < fabs(a - x0)) || (k > max_iter)) {
  30.             fFromDeltaMinus = FirstCoef * sin(SecondCoef * (a - Accuracy)) / ThirdCoef;
  31.             fFromDeltaPlus = FirstCoef * sin(SecondCoef * (a + Accuracy)) / ThirdCoef;
  32.             Difference = -(fFromDeltaPlus - fFromDeltaMinus) / (2 * Accuracy);
  33.             x0 = a;
  34.             fFromx0 = FirstCoef * sin(SecondCoef * x0) / ThirdCoef;
  35.             a = x0 + fFromx0 / Difference;
  36.             k = k + 1;
  37.             printf("C= %.6f ", a);
  38.             printf("f(c)= %.6f \n", fFromx0);
  39.         }
  40.         if (Accuracy > fabs(a - x0)) {
  41.             printf("C= %.6f ", a);
  42.             printf("Number of iterations: %d \n ", k);
  43.         } else {
  44.             printf("Answer not found!");
  45.         }
  46.     } else {
  47.         while ((Accuracy < 0 + eps) || (Accuracy < 1 + eps)) {
  48.             printf_s("Accuracy value must lie between (0;1) \n");
  49.             scanf_s("%f", &Accuracy);
  50.         }
  51.     }
  52.     getch();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement