Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float errore() {
  5.       float h = sqrt(0.002);
  6.       return h;
  7. }
  8.  
  9. float trova_derivata(float x_n) {
  10.       float h = errore();
  11.       float derivata;
  12.       derivata = (sinf(x_n + h) - sinf(x_n - h)) / (2 * h);
  13.      return derivata;
  14. }
  15.  
  16.  
  17. float aggiornamento (float x_n) {
  18.       float x_n1;
  19.       x_n1 = x_n - sinf(x_n) / trova_derivata(x_n);
  20.       return x_n1;
  21. }
  22.  
  23. float is_radice(float x) {
  24.       float h = errore();
  25.       if ((sinf(x) <= 0 + h) && (sinf(x) >= 0 - h)) { return 1; }
  26.       else { return 0; }
  27. }
  28.  
  29.  
  30. int main() {
  31.     float x;
  32.     float a, b;
  33.    
  34.     //Funzione y = sinx
  35.    
  36.     //Dichiarazione dell'intervallo chiuso
  37.    
  38.     a = 1.0; b = 6.0;
  39.     x = a;
  40.    
  41.     while (x <= b) {
  42.           if (is_radice(x)) { printf("%f e` radice.\n", x); }
  43.           x = aggiornamento(x);
  44.     }
  45.     while(1);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement