vault backup: 2023-10-27 19:03:01
This commit is contained in:
35
SS23/Mathe/Ilias/Zusatz_Material/Cosinus.java
Normal file
35
SS23/Mathe/Ilias/Zusatz_Material/Cosinus.java
Normal file
@@ -0,0 +1,35 @@
|
||||
// Cosinus.java
|
||||
// Programm zum Spielen, Ausprobieren und Verbessern
|
||||
// Ziel: "Gute" Berechnung der Cosinus-Funktion
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Cosinus
|
||||
{
|
||||
public static double myfak(int k)
|
||||
{
|
||||
double x;
|
||||
if (k==0) {return 1.0;}
|
||||
else {return ((double) k)*myfak(k-1);}
|
||||
}
|
||||
public static double mycos(double x)
|
||||
{
|
||||
double sum=0.0;
|
||||
double term=0.0;
|
||||
for (int k=0;k<=10;k++)
|
||||
{
|
||||
term=Math.pow((-1),k)*Math.pow(x,2*k)/myfak(2*k);
|
||||
sum+=term;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
double x;
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
System.out.print("Wie lautet die Stelle x? x = ");
|
||||
x = Double.parseDouble(in.readLine());
|
||||
System.out.println("Meine Rechnung liefert cos(x) = " + mycos(x));
|
||||
System.out.println("Java-Mathe-Bib liefert cos(x) = " + Math.cos(x));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user