Ankündigung

Einklappen
Keine Ankündigung bisher.

sin(x) ohne math.h programmieren

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • sin(x) ohne math.h programmieren

    hallo zusammen
    habe ein problem muss cos(x) und sin(x) ohne benutzung von math.h programmieren.
    also ich habe nun cos(x) ohne math.h hinbekommen aber ich bekomme jetzt sin(x) einfach nicht hin.kann mir jemand helfen!!!

    also sourcecode für cos(x) lautet:

    #include <stdio.h>

    main()
    {
    double x,term,cosx;
    int i;
    printf("X?: ");
    scanf("%lf",&x);
    term = 1;
    cosx = 1;

    for (i=1;i < 20; ++i)
    {
    term = term * x * x;
    term = term / i * 2 * ( i * 2-1);
    if ( i % 2 == 0 )
    cosx = cosx + term ;
    else
    cosx = cosx - term;
    }
    printf("\n %.9f ",cosx);

    im Anhang ist die formel für sin(x)

  • #2
    ...hm, sieht wie eine 1. Semester Hausaufgabe aus und genug Zeit ist auch schon vergangen, um Dir meine Lösung zu präsentieren :

    double mySin(double x) {
    int i;
    int n = 20;
    double term = x;
    double fak = 1.0;
    double y = x;

    for(i = 1; i < n; i++) {
    term *= x * x * -1.0;
    term /= (2*i) * (2*i + 1);
    y += term;
    }

    return y;
    }

    Kommentar

    Lädt...
    X