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 - 2 * (x * x) - 3 * x + 10;
- }
- float derivadaFunc(float x){
- return 3 * (x * x) - (4 * x) - 3;
- }
- float absolut(float x){
- if(x > 0){
- return x;
- }else{
- return (x * -1);
- }
- }
- int main()
- {
- float e = 0.01, x0 = 1.9, x1 = 0;
- int k = 0;
- printf("%.8f\n\n", func(x0) / derivadaFunc(x0));
- if(absolut(func(x0)) < e){
- printf("X = %.8f", x0);
- }else{
- k = 1;
- do{
- x1 = x0 - (func(x0) / derivadaFunc(x0));
- printf("%d\t %.8f\t %.8f\t %.8f\t\t \n", k, x0, func(x0), absolut(x1 - x0));
- x0 = x1;
- k++;
- }while((absolut(func(x1)) > e) || (absolut(x1 - x0) > e));
- }
- printf("\nX = %.8f\n", x1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment