Implementing Identity-Quadratic Functions in Python
Now that you've covered algebraic functions, let's work with them in Python. In this section, you'll learn not only function manipulation, but also visualization.
Identity Function
The identity function returns the input value unchanged, following the form f(x)=x. In Python, we implement it as:
# Identity Function
def identity_function(x):
return x
To visualize it, we generate x-values from -10 to 10, plot the function, and mark the origin. The function extends infinitely in both directions, indicated by arrows.
12345678910111213import numpy as np import matplotlib.pyplot as plt # Identity Function def identity_function(x): return x x = np.linspace(-10, 10, 100) # Generate values y = identity_function(x) plt.plot(x, y, label="f(x) = x", color='blue', linewidth=2) plt.scatter(0, 0, color='red') # Mark the origin plt.show()
Constant Function
A constant function always returns the same output, regardless of the input. It follows f(x)=c.
# Constant Function
def constant_function(x, c):
return np.full_like(x, c)
This implementation ensures all x-values yield the same output. The resulting plot is a horizontal line at y=c, with arrows indicating infinite extension.
1234567891011import numpy as np import matplotlib.pyplot as plt # Constant Function def constant_function(x, c): return np.full_like(x, c) x = np.linspace(-10, 10, 100) y = constant_function(x, c=5) plt.plot(x, y, label="f(x) = 5", color='blue', linewidth=2) plt.show()
Linear Function
A linear function follows the form f(x)=mx+b, where m represents the slope and b the y-intercept.
# Linear Function
def linear_function(x, m, b):
return m * x + b
The graph of a linear function is a straight line. We plot it with arrows indicating infinite extension, and mark key points such as the x-intercept and y-intercept.
123456789101112import numpy as np import matplotlib.pyplot as plt # Linear Function def linear_function(x, m, b): return m * x + b x = np.linspace(-20, 20, 400) y = linear_function(x, m=2, b=-5) plt.plot(x, y, color='blue', linewidth=2) plt.scatter(0, -5, color='red', label="Y-Intercept") plt.show()
Quadratic Function
A quadratic function follows f(x)=ax2+bx+c, creating a parabolic curve. Key features include the vertex and x-intercepts.
# Quadratic Function
def quadratic_function(x):
return x**2 - 4*x - 2
To analyze the function, we find its vertex and intercepts. The graph marks these points while arrows indicate that the parabola extends infinitely.
123456789101112import numpy as np import matplotlib.pyplot as plt # Quadratic Function def quadratic_function(x): return x**2 - 4*x - 2 x = np.linspace(-2, 6, 200) y = quadratic_function(x) plt.plot(x, y, color='blue', linewidth=2) plt.scatter(2, quadratic_function(2), color='red', label="Vertex") plt.show()
1. What is the output of the identity function for any input x?
2. What does the constant function return for all values of x?
3. In a linear function f(x)=mx+b, what does m represent?
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.89
Implementing Identity-Quadratic Functions in Python
Swipe um das Menü anzuzeigen
Now that you've covered algebraic functions, let's work with them in Python. In this section, you'll learn not only function manipulation, but also visualization.
Identity Function
The identity function returns the input value unchanged, following the form f(x)=x. In Python, we implement it as:
# Identity Function
def identity_function(x):
return x
To visualize it, we generate x-values from -10 to 10, plot the function, and mark the origin. The function extends infinitely in both directions, indicated by arrows.
12345678910111213import numpy as np import matplotlib.pyplot as plt # Identity Function def identity_function(x): return x x = np.linspace(-10, 10, 100) # Generate values y = identity_function(x) plt.plot(x, y, label="f(x) = x", color='blue', linewidth=2) plt.scatter(0, 0, color='red') # Mark the origin plt.show()
Constant Function
A constant function always returns the same output, regardless of the input. It follows f(x)=c.
# Constant Function
def constant_function(x, c):
return np.full_like(x, c)
This implementation ensures all x-values yield the same output. The resulting plot is a horizontal line at y=c, with arrows indicating infinite extension.
1234567891011import numpy as np import matplotlib.pyplot as plt # Constant Function def constant_function(x, c): return np.full_like(x, c) x = np.linspace(-10, 10, 100) y = constant_function(x, c=5) plt.plot(x, y, label="f(x) = 5", color='blue', linewidth=2) plt.show()
Linear Function
A linear function follows the form f(x)=mx+b, where m represents the slope and b the y-intercept.
# Linear Function
def linear_function(x, m, b):
return m * x + b
The graph of a linear function is a straight line. We plot it with arrows indicating infinite extension, and mark key points such as the x-intercept and y-intercept.
123456789101112import numpy as np import matplotlib.pyplot as plt # Linear Function def linear_function(x, m, b): return m * x + b x = np.linspace(-20, 20, 400) y = linear_function(x, m=2, b=-5) plt.plot(x, y, color='blue', linewidth=2) plt.scatter(0, -5, color='red', label="Y-Intercept") plt.show()
Quadratic Function
A quadratic function follows f(x)=ax2+bx+c, creating a parabolic curve. Key features include the vertex and x-intercepts.
# Quadratic Function
def quadratic_function(x):
return x**2 - 4*x - 2
To analyze the function, we find its vertex and intercepts. The graph marks these points while arrows indicate that the parabola extends infinitely.
123456789101112import numpy as np import matplotlib.pyplot as plt # Quadratic Function def quadratic_function(x): return x**2 - 4*x - 2 x = np.linspace(-2, 6, 200) y = quadratic_function(x) plt.plot(x, y, color='blue', linewidth=2) plt.scatter(2, quadratic_function(2), color='red', label="Vertex") plt.show()
1. What is the output of the identity function for any input x?
2. What does the constant function return for all values of x?
3. In a linear function f(x)=mx+b, what does m represent?
Danke für Ihr Feedback!