def f(x):
return x**2 - 3*x + 2
1 📌 Introduction
In this post, we demonstrate how to use Python code, visualizations, and LaTeX math in a single Quarto blog post.
2 🧮 Defining a Function with Python
Let’s define a simple quadratic function using Python:
3 📊 Plotting the Function
We’ll plot the function over the interval ([0, 5]).
import matplotlib.pyplot as plt
import numpy as np
= np.linspace(0, 5, 100)
x = f(x)
y
="f(x) = x² - 3x + 2")
plt.plot(x, y, label0, color='gray', lw=0.5)
plt.axhline("Plot of f(x)")
plt.title("x")
plt.xlabel("f(x)")
plt.ylabel(
plt.legend()True)
plt.grid( plt.show()
4 ✏️ Adding LaTeX Math
We can write LaTeX equations inline like this: \(f(x) = x^2 - 3x + 2\), or as display equations:
\[ f(x) = x^2 - 3x + 2 \]
To find the roots, solve:
\[ x^2 - 3x + 2 = 0 \]
Which factors to:
\[ (x - 1)(x - 2) = 0 \Rightarrow x = 1, 2 \]
5 ✅ Summary
This blog post used: - Python code to define and compute, - Matplotlib to create plots, and - LaTeX to format math equations.
All rendered together beautifully in a Quarto document!