Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float Func(float x)
- {
- return x - sin(x);
- }
- float dFunc(float x)
- {
- return 1 - cos(x);
- }
- float solve(float x, float e)
- {
- float x0;
- int i = 0;
- printf("%i x: %f\n", i, x);
- do
- {
- i++;
- x0 = x;
- x = x0 - (Func(x)/dFunc(x));
- printf("%i x: %f\n", i, x);
- }
- while(fabs(x-x0) > .1*e);
- return x;
- }
- int main() {
- float root, x0;
- float e;
- printf("Enter precision");
- scanf("%f", &e);
- printf("\n");
- printf("Enter x0: ");
- scanf("%f", &x0);
- printf("\n");
- printf("e = %f, x0 = %f\n", e, x0);
- root = solve(x0, e);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement