Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <iostream>
- #define EPSILON 0.01
- using namespace std;
- float getFuncResult(float x) {
- return (0.5 * pow(x, 2) - sin(x));
- }
- float getDerivative(float x) {
- return (x - cos(x));
- }
- void main() {
- float x0 = 0.5;
- float xnext;
- for (;;) {
- xnext = x0 - getFuncResult(x0) / getDerivative(x0);
- if (abs(xnext - x0) < EPSILON) break;
- x0 = xnext;
- }
- cout << "Result: " << x0 << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement