Plotting a Slope Field with TikZ (Unlocking LaTeX Graphics, Ep. 60)

In this episode of Unlocking LaTeX Graphics, applied mathematician Tammy Kolda shows how to draw slope fields in LaTeX using pure TikZ. A slope field visualizes a differential equation dy/dx = f(x,y) by drawing short normalized line segments at each grid point. She explains slope fields for differential equations of the form dy/dx = f(x,y) and demonstrates how to build a plot by manually drawing axes and tick marks, then using nested foreach loops to place normalized line segments on a grid. Starting with f(x,y) = x − y, she derives how to compute segment endpoints so every line has fixed length, then adds a title and swaps in other functions such as f(x,y)=sin(x)+y and f(x,y)=sin(xy). She also shows a case where TikZ fails, previewing a future PGFPLOTS-based approach. She concludes with a workaround for vertical slopes in f(x,y)=2cos(x)/y using if-then-else. This is part one of a multi-part series; a future video will cover the PGFPLOTS approach using quiver plots. 00:00 Welcome and Intro 01:20 What is a Slope Field 02:15 Document Setup 02:34 Drawing Axes 03:26 Adding Axis Tick Marks 04:32 Drawing the Slope Field for dy/dx = x-y 07:16 Adding a Title 07:26 Changing the Function to dy/dx = sin(x)+y 07:53 Changing the function to dy/dx = sin(xy) 08:04 Problems Plotting an Exponential 08:28 Handling Vertical Slopes for dy/dx = cos(x)/y 09:32 Thanks for Watching Key terms: texlatex, TikZ, slope field, differential equations, foreach loop, pgfmathsetmacro Other Episodes Mastering loops in TikZ:    • Mastering Loops in TikZ: A LaTeX Tutorial ...   TikZ math functions:    • TikZ Math Functions in LaTeX: Usage and Co...   Today's Document on Overleaf: https://www.overleaf.com/read/crkzxwk... Unlocking LaTeX Graphics Book: https://latex-graphics.com Purchase Book on Amazon: https://amzn.to/3z76nwb