All pastes #2045983 Raw Edit

Untitled

public text v1 · immutable
#2045983 ·published 2011-04-13 13:19 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//Prototipos
float funcao(float x);
float funcao_teste(float x);


int main(){
    
    float x0, x1, precisao, k, xbarra, cubo, teste;

    
    x0 = 0.5;
    precisao = 0.0001;

    
             if( x0 < precisao){
                 xbarra = x0;
             }

    
             while(k < precisao){
                                  x1 = x0 - funcao(x0);//passo 4
                                  
                                  
                                  if( funcao(x1) < precisao || abs(x1 - x0) < precisao){
                                                 xbarra = x1;
                                  }
                                 
                                  x0 = x1;

                                  

                                          cubo= pow (x0 , 3);
                                          teste = (cubo - 9*x0 +3);
                                          k = teste;
                                          
                                  printf("K = %0.20f\nX0 = %0.20f\nRaiz = %0.20f\nCriterio de Parada = %0.20f\n", k, x0, xbarra, teste);
                                  system("pause");
                                  
             }
              
              
              
              x1 = x0 - funcao(x0);//repetimos o codigo fora do while para que se verfique a primeira posicao de quando k > precisao
                                  
                                  
              if( funcao(x1) < precisao || abs(x1 - x0) < precisao){
              xbarra = x1;
              }
                                 
              x0 = x1;

                                  

            cubo= pow (x0 , 3);
            teste = (cubo - 9*x0 +3);
            k = teste;
                                                      
            printf("K = %0.20f\nX0 = %0.20f\nRaiz = %0.20f\nCriterio de Parada = %0.20f\n", k, x0, xbarra, teste);
            system("pause");
}
                 
//Funcao de teste de parada         
float funcao_teste(float x){
      
      float cubo, teste;
                                  cubo= pow (x , 3);
                                  teste = (cubo - 9*x +3);
                                  printf("teste = %f", teste);
                                  return abs(teste);
}
                                  
//Funcao que calcula a funcao
float funcao(float x){
         float quadrado, cubo, resul;
                
                quadrado = pow (x , 2);
                cubo= pow (x , 3);
    
                resul = (cubo - 9*x +3) / (3* quadrado -9);
                
                return resul;
}