Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- double fofx(double input) {
- return 1/input - cos(input);
- }
- int main() {
- int k = 0;
- double a = 4.0;
- double b = 6.0;
- double x = 0.0;
- cout << "k\t\tak\t\tbk\t\txk\t\t" << endl;
- for (k = 0; k <= 5; k++) {
- x = (a + b)/2;
- cout << k << "\t\t" << a << "\t\t" << b << "\t\t" << x << endl;
- if (fofx(x) * fofx(a) < 0) {
- b = x;
- } else {
- a = x;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement