Created
November 27, 2014 19:31
-
-
Save kuzemkon/42f1ddb4632f91d5a63d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <math.h> | |
| using namespace std; | |
| float a, b, E, Dx, Ep, x; | |
| int i; | |
| float f(float x) { | |
| return tan(x) - ((tan(x)*tan(x)*tan(x) + 1) / 3) + 0.2*tan(x)*tan(x)*tan(x)*tan(x)*tan(x); | |
| } | |
| float fp(float x) { | |
| return (f(x + Dx) - f(x)) / Dx; | |
| } | |
| float f2p(float x) { | |
| return (fp(x + Dx) - fp(x)) / Dx; | |
| } | |
| int main() { | |
| cout << "Enter limit a, b and accuracy E\n"; | |
| cout << "a ="; | |
| cin >> a; | |
| cout << "b ="; | |
| cin >> b; | |
| cout << "E ="; | |
| cin >> E; | |
| Dx = E / 1000; | |
| Ep = fabs(x - b); | |
| x = b; | |
| if (f(x)*f2p(x)<0) { | |
| cout << "Tabulate the function, please/n"; | |
| system("pause"); | |
| } | |
| else { | |
| i = 0; | |
| while (fabs(Ep) > E) { | |
| x = x - f(x) / fp(x); | |
| Ep = fabs(x - b); | |
| b = x; | |
| i = i + 1; | |
| cout << i << " x =" << x; | |
| cout << " f(x) =" << f(x) << endl; | |
| } | |
| } | |
| system("pause"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment