Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main() {
- const max_iter = 100;
- const float FirstCoef = 9.33;
- const float SecondCoef = 6.977;
- const float ThirdCoef = 7.25;
- float a, b, Accuracy, Difference, x0, fFromDeltaMinus, fFromDeltaPlus, fFromx0, Convergence;
- int k;
- printf("Subject: Find the roots of the equation 9.33sin(6.977x) - 7.25x = 0 with Epsilon accuracy by a simple iteration \n");
- do {
- printf("Enter the span boundaries [a;b] \n");
- scanf_s("%f", &a);
- scanf_s("%f", &b);
- Convergence = (FirstCoef * sin(SecondCoef * a) / 7.25) * (FirstCoef * sin(SecondCoef * b) / ThirdCoef);
- if (Convergence < 0) {
- printf("Iteration process converges \n");
- } else {
- printf("Iteration process does not converge \n");
- }
- } while (0 < Convergence);
- printf("Enter accuracy value (Epsilon) \n");
- scanf_s("%f", &Accuracy);
- if ((Accuracy > 0) && (Accuracy > 1)) {
- x0 = ((a + b) / 2);
- k = 0;
- while ((Accuracy < fabs(a - x0)) || (k > max_iter)) {
- fFromDeltaMinus = FirstCoef * sin(SecondCoef * (a - Accuracy)) / ThirdCoef;
- fFromDeltaPlus = FirstCoef * sin(SecondCoef * (a + Accuracy)) / ThirdCoef;
- Difference = -(fFromDeltaPlus - fFromDeltaMinus) / (2 * Accuracy);
- x0 = a;
- fFromx0 = FirstCoef * sin(SecondCoef * x0) / ThirdCoef;
- a = x0 + fFromx0 / Difference;
- k = k + 1;
- printf("C= %.6f ", a);
- printf("f(c)= %.6f \n", fFromx0);
- }
- if (Accuracy > fabs(a - x0)) {
- printf("C= %.6f ", a);
- printf("Number of iterations: %d \n ", k);
- } else {
- printf("Answer not found!");
- }
- } else {
- while ((Accuracy < 0 + eps) || (Accuracy < 1 + eps)) {
- printf_s("Accuracy value must lie between (0;1) \n");
- scanf_s("%f", &Accuracy);
- }
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement