Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float errore() {
- float h = sqrt(0.002);
- return h;
- }
- float trova_derivata(float x_n) {
- float h = errore();
- float derivata;
- derivata = (sinf(x_n + h) - sinf(x_n - h)) / (2 * h);
- return derivata;
- }
- float aggiornamento (float x_n) {
- float x_n1;
- x_n1 = x_n - sinf(x_n) / trova_derivata(x_n);
- return x_n1;
- }
- float is_radice(float x) {
- float h = errore();
- if ((sinf(x) <= 0 + h) && (sinf(x) >= 0 - h)) { return 1; }
- else { return 0; }
- }
- int main() {
- float x;
- float a, b;
- //Funzione y = sinx
- //Dichiarazione dell'intervallo chiuso
- a = 1.0; b = 6.0;
- x = a;
- while (x <= b) {
- if (is_radice(x)) { printf("%f e` radice.\n", x); }
- x = aggiornamento(x);
- }
- while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement