Implementierung Grundlegender Funktionen in Python
Funktionen definieren Beziehungen zwischen Eingaben und Ausgaben und sind somit grundlegend in Mathematik, Programmierung und Data Science. In Python können verschiedene Funktionstypen definiert und visualisiert werden, wie eineindeutige (one-to-one), mehrdeutige (many-to-one), surjektive (onto), injektive (into) und bijektive Funktionen.
Funktionstypen in Python
Eineindeutige (Injektive) Funktion
Eine eineindeutige Funktion stellt sicher, dass jede Eingabe auf eine eindeutige Ausgabe abgebildet wird. Wie zu sehen ist, haben keine zwei Eingaben die gleiche Ausgabe.
123456789# One-to-One Function: f(x) = x def one_to_one(x): return x # Example Outputs print("One-to-One Function Outputs:") print(one_to_one(2)) # Output is 2 print(one_to_one(5)) # Output is 5
Viele-zu-eins-Funktion
Eine Viele-zu-eins-Funktion erlaubt, dass mehrere Eingabewerte auf denselben Ausgabewert abgebildet werden.
12345678# Many-to-One Function: f(x) = x^2 def many_to_one(x): return x ** 2 # Example Outputs print("\nMany-to-One Function Outputs:") print(many_to_one(3)) # Output is 9 print(many_to_one(-3)) # Output is also 9 (Same output for different inputs)
Auf (Surjektive) Funktion
Eine auf Funktion stellt sicher, dass jedes mögliche Element der Zielmenge von mindestens einem Eingabewert erreicht wird.
1234567891011import numpy as np # Onto Function: f(x) = tan(x) def onto(x): return np.tan(x) # Example Outputs print("\nOnto Function Outputs:") print(onto(1)) # Output is approximately 1.557 print(onto(-1)) # Output is approximately -2.185
Into-Funktion
Eine Into-Funktion bedeutet, dass nicht alle Werte im Zielbereich abgedeckt werden – einige Ausgaben bleiben ungenutzt.
12345678910import numpy as np # Into Function: f(x) = sin(x) (Only outputs between -1 and 1) def into(x): return np.sin(x) # Example Outputs print("\nInto Function Outputs:") print(into(0)) # Output is approximately 0 print(into(np.pi / 2)) # Output is approximately 1
Bijektive Funktion (Eineindeutig & Auf jede Abbildung)
Eine bijektive Funktion ist sowohl eineindeutig als auch auf jede Abbildung, was bedeutet, dass sie invertierbar ist.
12345678# Bijective Function: f(x) = x def bijective(x): return x # Example Outputs print("\nBijective Function Outputs:") print(bijective(3)) # Output is 3 print(bijective(-4)) # Output is -4
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 1.96
Implementierung Grundlegender Funktionen in Python
Swipe um das Menü anzuzeigen
Funktionen definieren Beziehungen zwischen Eingaben und Ausgaben und sind somit grundlegend in Mathematik, Programmierung und Data Science. In Python können verschiedene Funktionstypen definiert und visualisiert werden, wie eineindeutige (one-to-one), mehrdeutige (many-to-one), surjektive (onto), injektive (into) und bijektive Funktionen.
Funktionstypen in Python
Eineindeutige (Injektive) Funktion
Eine eineindeutige Funktion stellt sicher, dass jede Eingabe auf eine eindeutige Ausgabe abgebildet wird. Wie zu sehen ist, haben keine zwei Eingaben die gleiche Ausgabe.
123456789# One-to-One Function: f(x) = x def one_to_one(x): return x # Example Outputs print("One-to-One Function Outputs:") print(one_to_one(2)) # Output is 2 print(one_to_one(5)) # Output is 5
Viele-zu-eins-Funktion
Eine Viele-zu-eins-Funktion erlaubt, dass mehrere Eingabewerte auf denselben Ausgabewert abgebildet werden.
12345678# Many-to-One Function: f(x) = x^2 def many_to_one(x): return x ** 2 # Example Outputs print("\nMany-to-One Function Outputs:") print(many_to_one(3)) # Output is 9 print(many_to_one(-3)) # Output is also 9 (Same output for different inputs)
Auf (Surjektive) Funktion
Eine auf Funktion stellt sicher, dass jedes mögliche Element der Zielmenge von mindestens einem Eingabewert erreicht wird.
1234567891011import numpy as np # Onto Function: f(x) = tan(x) def onto(x): return np.tan(x) # Example Outputs print("\nOnto Function Outputs:") print(onto(1)) # Output is approximately 1.557 print(onto(-1)) # Output is approximately -2.185
Into-Funktion
Eine Into-Funktion bedeutet, dass nicht alle Werte im Zielbereich abgedeckt werden – einige Ausgaben bleiben ungenutzt.
12345678910import numpy as np # Into Function: f(x) = sin(x) (Only outputs between -1 and 1) def into(x): return np.sin(x) # Example Outputs print("\nInto Function Outputs:") print(into(0)) # Output is approximately 0 print(into(np.pi / 2)) # Output is approximately 1
Bijektive Funktion (Eineindeutig & Auf jede Abbildung)
Eine bijektive Funktion ist sowohl eineindeutig als auch auf jede Abbildung, was bedeutet, dass sie invertierbar ist.
12345678# Bijective Function: f(x) = x def bijective(x): return x # Example Outputs print("\nBijective Function Outputs:") print(bijective(3)) # Output is 3 print(bijective(-4)) # Output is -4
Danke für Ihr Feedback!