Created
April 15, 2015 08:03
-
-
Save 3c7/7a1c22619bc6921707c2 to your computer and use it in GitHub Desktop.
Praktomat Übung 2 Aufgabe 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public class Abs implements Funktion { | |
public boolean istDefiniertFuer(double x) { | |
return true; | |
} | |
public double wert(double x) { | |
if (this.istDefiniertFuer(x)) return Math.abs(x); | |
return 0.0; | |
} | |
public String toString() { | |
return "|x|"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public interface Funktion { | |
boolean istDefiniertFuer(double x); | |
double wert(double x); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Kettenfunktion implements Funktion | |
{ | |
private Funktion f; | |
private Funktion g; | |
public Kettenfunktion(Funktion f, Funktion g) { | |
this.f = f; | |
this.g = g; | |
} | |
public boolean istDefiniertFuer(double x) { | |
return g.istDefiniertFuer(x) && f.istDefiniertFuer(g.wert(x)); | |
} | |
public double wert(double x) { | |
return f.wert(g.wert(x)); | |
} | |
public String toString() { | |
return "f(g(x)) mit f(x) = " + f + " und g(x) = " + g; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public class Polynom implements Funktion { | |
private double[] werte; | |
public Polynom(double[] werte) { | |
this.werte = werte; | |
} | |
public boolean istDefiniertFuer(double x) { | |
return true; | |
} | |
public double wert(double x) { | |
double erg = 0.0; | |
for (int i=0; i<this.werte.length; i++) { | |
erg += this.werte[i] * Math.pow(x,i); | |
} | |
return erg; | |
} | |
public String toString() { | |
String fkt = ""; | |
for (int i=0; i<this.werte.length; i++) { | |
fkt = this.werte[i] + "*x^" + i + fkt; | |
if (i < this.werte.length - 1) fkt = " + " + fkt; | |
} | |
return fkt; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public class Reziprok implements Funktion { | |
public boolean istDefiniertFuer(double x) { | |
if (x != 0) return true; | |
return false; | |
} | |
public double wert(double x) { | |
if (this.istDefiniertFuer(x)) return 1.0 / x; | |
return 0.0; | |
} | |
public String toString() { | |
return "1/x"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public class RezWurzel implements Funktion { | |
Kettenfunktion kfkt = new Kettenfunktion(new Wurzel(), new Abs()); | |
Kettenfunktion RezWurzel = new Kettenfunktion(new Reziprok(), kfkt); | |
public boolean istDefiniertFuer(double x) { | |
if (RezWurzel.istDefiniertFuer(x)) return true; | |
return false; | |
} | |
public double wert(double x) { | |
if (this.istDefiniertFuer(x)) return RezWurzel.wert(x); | |
return 0.0; | |
} | |
public String toString() { | |
return RezWurzel.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 14.04.2015. | |
*/ | |
public class Wurzel implements Funktion { | |
public boolean istDefiniertFuer(double x) { | |
if (x >= 0) return true; | |
return false; | |
} | |
public double wert(double x) { | |
if (this.istDefiniertFuer(x)) return Math.sqrt(x); | |
return 0.0; | |
} | |
public String toString() { | |
return "sqrt(x)"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funktion.java und Kettenfunktion.java sind gegeben.