Hallo, habe versucht eine Taylor Reihe für Sinus aufzustellen, klappt leider aber nur bis x=6, kann mir jemand evtl. helfen und sagen, inwieweit mein Code abgeändert werden muss? Ach ja, die Reihenentwicklung soll nur bis n=8 gehen.
Java:
public class sinTaylor {
static double Fakultät(double n){
double sum = 1;
for(int i = 1; i <=n; i++) {
sum = sum * i;
}
return sum;
}
public static double sinTaylor(double x){
double sum = 0;
double sum1 = 0;
int n=8;
for(int i = 0; i <= n; i++) {
double zwein= 2*i+1;
sum1 = Math.pow(-1, i) * Math.pow(x, zwein) / Fakultät(zwein);
sum = sum1 + sum;
}
return sum;
}
public static void main(String[] args){
double y=6;
System.out.println("Test: calcSum");
System.out.println("sinTaylor " + sinTaylor(y) + ", sin: " + Math.sin(y) );
}
}