Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- float func(float x){
- return x * x * x - 9 * x + 3;
- //return x * x * x - x - 1;
- return x * x - 0.9;
- }
- float funcIteracao(float x){
- return ((x * x * x) / 9) + (0.33333333);
- //return (1 / x) + (1 / (x * x));
- //return x * x + x - 0.9;
- }
- float absolut(float x){
- if(x > 0){
- return x;
- }else{
- return (x * -1);
- }
- }
- int main()
- {
- float e = 0.001, x0 = 2.5, x1 = 0;
- int k = 0;
- if(absolut(func(x0)) < e){
- printf("X = %.7f", x0);
- }else{
- k = 1;
- do{
- x1 = funcIteracao(x0);
- printf("%d\t %.7f\t %.7f\t %.7f\t\t \n", k, x0, func(x0), absolut(x1 - x0));
- x0 = x1;
- k++;
- }while((absolut(func(x1)) > e) || (absolut(x1 - x0) > e));
- }
- printf("\nX = %.7f\n", x0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment