Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- #include <locale>
- using namespace std;
- int fcCounter = 0;
- float f(float x) {
- ++fcCounter;
- return (pow(x, 4) + (-0.1)*atan(4 * x));
- }
- int main() {
- float a, b;
- float eps; int i = 0;
- float x1, x2;
- printf("Input a, b, eps\n");
- scanf_s("%f %f %f", &a, &b, &eps);
- x1 = (a + b - (eps / 2)) / 2;
- x2 = (a + b + (eps / 2)) / 2;
- printf("i\ta\t x1\t x2\t b\n");
- printf("%i\t%.2f %.2f\t %.2f %.2f\n", i, a, x1, x2, b);
- while (fabs(b - a) > eps) {
- x1 = (a + b - (eps / 2)) / 2;
- x2 = (a + b + (eps / 2)) / 2;
- if (f(x1) > f(x2))
- {
- a = x1;
- }
- else
- {
- b = x2;
- }
- i++;
- printf("%i\t%.2f %.2f\t %.2f %.2f\n", i, a, x1, x2, b);
- } //
- printf(" x=%f y=%f, fcCounter=%i", (a + b) / 2, f((a + b) / 2), fcCounter);
- system("pause"); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement