This note covers slope fields, which show the direction of solutions to a first-order differential equation, and Euler's method, which builds an approximate solution one small step at a time. These tools matter because many real equations for growth, cooling and mixing cannot be solved exactly, but can always be approximated.
Key ideas
A first-order differential equation gives the gradient of an unknown function as a rule in \(x\) and \(y\), written \(\dfrac{dy}{dx}=f(x,y)\). A solution is a curve whose gradient at every point matches the rule. An initial condition, such as \(y(0)=1\), picks out one particular curve.
Slope fields. A slope field (or direction field) is a grid of points, each with a short line segment drawn at the gradient \(f(x,y)\) found at that point. To read one:
- Where \(f(x,y)=0\), the segments are horizontal.
- Where \(f(x,y)\gt 0\), they slope up. Where \(f(x,y)\lt 0\), they slope down.
- A larger size of \(f(x,y)\) means a steeper segment.
- A solution curve starts at the given point and follows the segments, always moving along the nearest direction without crossing a segment.
If \(f\) depends only on \(x\), every column of segments looks the same. If \(f\) depends only on \(y\), every row looks the same. An isocline is a curve along which the gradient is constant, such as the line \(y=x\) for \(\dfrac{dy}{dx}=x-y\), where the gradient is 0.
Euler's method. Starting at \((x_0,y_0)\), use the gradient there to move forward a step of size \(h\) along the tangent. Repeat: \[x_{n+1}=x_n+h,\qquad y_{n+1}=y_n+h\,f(x_n,y_n).\] The gradient is always calculated from the old point \((x_n,y_n)\). You can do the steps by hand, in a spreadsheet or on a GDC.
Accuracy. Each step follows a straight line, so the method drifts away from a curved solution. A smaller \(h\) gives a better estimate but needs more steps. If the true solution curves upwards (concave up), the tangent lines lie below it and Euler's method underestimates. If it curves downwards, it overestimates.
Comparing with an exact solution. Some equations can be solved exactly by separating variables. For \(\dfrac{dy}{dx}=ky\), write \(\int\dfrac{1}{y}\,dy=\int k\,dx\), so \(\ln|y|=kx+c\), which gives \(y=Ae^{kx}\). Comparing the exact value with the Euler value shows the size of the error.
Sketching a solution. To sketch the solution through a given point on a slope field, start at the point and move to the right, bending the curve so that it is tangent to each segment it passes. Then repeat to the left. Solution curves for different starting points never cross each other, because each point has only one gradient.
Using technology. A spreadsheet or the GDC can repeat the same calculation many times. Set up one row for the first step, then copy it down. Halving \(h\) roughly halves the error, which you can check by running the method twice.
Definitions and formulae
| Term or formula | Meaning / when to use |
|---|---|
| \(\dfrac{dy}{dx}=f(x,y)\) | Gradient given as a rule in \(x\) and \(y\). |
| Slope field | Grid of short segments showing the gradient at each point. |
| Isocline | Curve joining points with the same gradient. |
| \(x_{n+1}=x_n+h\) | Move \(x\) forward by the step size. |
| \(y_{n+1}=y_n+h\,f(x_n,y_n)\) | Euler step: move along the tangent at the old point. |
| \(y=Ae^{kx}\) | Exact solution of \(\dfrac{dy}{dx}=ky\), used to check the error. |
Worked examples
Example 1 For \(\dfrac{dy}{dx}=x-y\), find the gradient at \((0,0)\), \((1,0)\), \((0,2)\), \((2,2)\) and \((1,3)\), and describe the isocline for gradient 0.
Substitute each point into \(x-y\).
\((0,0)\): \(0-0=0\). \((1,0)\): \(1-0=1\). \((0,2)\): \(0-2=-2\). \((2,2)\): \(2-2=0\). \((1,3)\): \(1-3=-2\).
The gradient is zero when \(x-y=0\), which is the line \(y=x\). Along this line the segments are horizontal.
Above the line (\(y\gt x\)) the gradient is negative, and below it (\(y\lt x\)) the gradient is positive.
Answer: gradients \(0,\ 1,\ -2,\ 0,\ -2\); horizontal segments along \(y=x\)
Example 2 Use Euler's method with \(h=0.25\) to estimate \(y(1)\) for \(\dfrac{dy}{dx}=x+y\), with \(y(0)=1\).
Four steps take \(x\) from 0 to 1.
Step 1: \(f(0,1)=1\), so \(y_1=1+0.25(1)=1.25\) at \(x=0.25\).
Step 2: \(f(0.25,1.25)=1.5\), so \(y_2=1.25+0.25(1.5)=1.625\) at \(x=0.5\).
Step 3: \(f(0.5,1.625)=2.125\), so \(y_3=1.625+0.25(2.125)=2.15625\) at \(x=0.75\).
Step 4: \(f(0.75,2.15625)=2.90625\), so \(y_4=2.15625+0.25(2.90625)=2.8828125\) at \(x=1\).
Answer: \(y(1)\approx 2.88\)
Example 3 A hot drink's temperature excess over the room, \(y\) degrees Celsius, satisfies \(\dfrac{dy}{dt}=-0.4y\) with \(y(0)=50\), where \(t\) is in minutes. Use Euler's method with \(h=0.5\) to estimate \(y(2)\), then compare with the exact solution.
Each step is \(y_{n+1}=y_n+0.5(-0.4y_n)=0.8\,y_n\).
\(y_1=40\), \(y_2=32\), \(y_3=25.6\), \(y_4=20.48\) at \(t=2\).
Exact solution: separating variables gives \(y=50e^{-0.4t}\), so \(y(2)=50e^{-0.8}\approx 22.47\).
Euler's estimate is lower than the exact value by about 1.99, because the exponential decay curve is concave up.
Answer: Euler gives 20.5; exact value 22.5; the estimate is too low
Example 4 Use Euler's method with \(h=0.2\) to estimate \(y(0.6)\) for \(\dfrac{dy}{dx}=xy\), with \(y(0)=1\).
Step 1: \(f(0,1)=0\), so \(y_1=1+0.2(0)=1\) at \(x=0.2\).
Step 2: \(f(0.2,1)=0.2\), so \(y_2=1+0.2(0.2)=1.04\) at \(x=0.4\).
Step 3: \(f(0.4,1.04)=0.416\), so \(y_3=1.04+0.2(0.416)=1.1232\) at \(x=0.6\).
Separating variables gives the exact solution \(y=e^{x^2/2}\), so \(y(0.6)=e^{0.18}\approx1.197\). The estimate is a little low.
Answer: \(y(0.6)\approx 1.12\)
Common errors
- Using the new \(y\)-value to compute the gradient. Always use \(f(x_n,y_n)\) from the start of the step.
- Forgetting to increase \(x\) by \(h\) at each step, so the gradient uses the wrong \(x\).
- Drawing slope-field segments of the same steepness everywhere. The steepness must follow the value of \(f(x,y)\).
- Giving a decimal answer rounded too early. Keep full values through the steps and round only the final answer.
- Stating whether Euler overestimates or underestimates without looking at the concavity of the solution.
Exam tip: Set out Euler's method as a table with columns for \(x_n\), \(y_n\), \(f(x_n,y_n)\) and \(y_{n+1}\). This makes your steps clear and makes a slip easy to find.
Check yourself
- For \(\dfrac{dy}{dx}=xy+1\), find the gradient at \((2,-1)\).
Answer
\(2(-1)+1=-1\). - For \(\dfrac{dy}{dx}=3-y\) with \(y(0)=1\) and \(h=0.5\), find \(y_1\) and \(y_2\).
Answer
\(y_1=1+0.5(3-1)=2\). \(y_2=2+0.5(3-2)=2.5\). - For \(\dfrac{dy}{dx}=(x-1)(y+2)\), where are the segments horizontal?
Answer
The gradient is zero when \(x=1\) or \(y=-2\), so along the vertical line \(x=1\) and the horizontal line \(y=-2\). - For \(\dfrac{dy}{dx}=y^2\) with \(y(0)=1\) and \(h=0.1\), find \(y_2\).
Answer
\(y_1=1+0.1(1)=1.1\). \(y_2=1.1+0.1(1.21)=1.221\).