A graphof a function is the visual representation of all ordered pairs (x, f(x)). It gives us insight into the function’s behavior, such as:
Where it increases or decreases
Its symmetry
Maximum or minimum points
Intercepts and asymptotes
A function maps every input x to a unique output f(x). Plotting this for various x-values results in a curve or line.
2. Basic Example
Let’s consider:
f(x)=x2
To graph this, we compute several (x, f(x)) values:
x
f(x) = x²
-3
9
-2
4
-1
1
0
0
1
1
2
4
3
9
Plotting these points gives a parabolaopening upwards.
3. Key Features of a Graph
When analyzing graphs, observe:
Feature
Description
Domain
All x-values for which f(x) is defined
Range
All possible f(x) values
x-intercepts
Where the graph crosses the x-axis (f(x) = 0)
y-intercept
Where the graph crosses the y-axis (x = 0)
Asymptotes
Lines that the graph approaches but never touches
Symmetry
Even/Odd/None
Increasing/Decreasing Intervals
Where the graph goes up/down
Maximum/Minimum
Peaks and valleys of the graph
4. Python Example: Plotting a Function
Example 1: Plotting 𝑓(𝑥)=x2
Let’s use matplotlib and numpy to graph a function.
Output:
You can also plot using sympy.
Output:
Example 2: 𝑓(𝑥)=sin(x)
Let’s use matplotlib and numpy to graph a function.
Output:
You can also plot using sympy.
Output:
5. Try Multiple Graphs Together
Let’s use matplotlib and numpy to graph a function.
Output:
You can also plot using sympy.
Output:
Keywords
symbolic math, sympy, sine function, sin(x), plot sin, symbolic plotting, python math, calculus, symbolic computing, algebra, trigonometry, math visualization, pure sympy, no numpy, no matplotlib, math graph, function plot, symbolic expression, math function, sympy plot, nerd cafe
import numpy as np
import matplotlib.pyplot as plt
# Define the function
def f(x):
return x**2
# Generate x values
x = np.linspace(-10, 10, 400)
y = f(x)
# Plot
plt.figure(figsize=(8,5))
plt.plot(x, y, label="f(x) = x²", color='blue')
plt.axhline(0, color='black', linewidth=0.5) # x-axis
plt.axvline(0, color='black', linewidth=0.5) # y-axis
plt.title("Graph of f(x) = x²")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()
import sympy as sp
# Define the symbolic variable and function
x = sp.symbols('x')
f = x**2
# Plot using sympy
sp.plotting.plot(f, (x, -10, 10),
title="Graph of f(x) = x²",
xlabel="x", ylabel="f(x)",
line_color='blue', legend=True)
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2*np.pi, 2*np.pi, 400)
y = np.sin(x)
plt.figure(figsize=(8,5))
plt.plot(x, y, label="f(x) = sin(x)", color='green')
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.title("Graph of f(x) = sin(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()
import sympy as sp
# Define the symbolic variable and function
x = sp.symbols('x')
f = sp.sin(x)
# Plot using sympy
sp.plotting.plot(f, (x, -10, 10),
title="Graph of f(x) = sin(x)",
xlabel="x", ylabel="f(x)",
line_color='blue', legend=True)h