from edumath.differential_equations import euler_method
euler_method(lambda x, y: y, initial_x=0, initial_y=2, step=0.5, steps=3)[(0, 2), (0.5, 3.0), (1.0, 4.5), (1.5, 6.75)]
Some differential equations are difficult to solve exactly. A slope field helps you understand the behavior of solutions anyway. It shows the slope predicted by the equation at many points.
After this lesson you should be able to:
For an equation
dy/dx = f(x,y)
choose a point (x,y), compute f(x,y), and draw a short segment with that slope. Repeat this at many points. The result is a slope field.
A solution curve should follow the local directions in the slope field, like a leaf floating along a stream.
dy/dx = 0.x increases.For an autonomous equation
dy/dt = f(y)
an equilibrium occurs where f(y)=0. If a solution starts at that value, its rate of change is zero, so it stays there.
Example:
dy/dt = y(1-y)
Equilibria occur when
y(1-y)=0
so y=0 and y=1.
Euler’s method is a simple numerical method. It says: use the current slope for one small step.
x_{n+1} = x_n + h
y_{n+1} = y_n + h f(x_n, y_n)
Here h is the step size.
Approximate the solution to
y' = y, y(0)=2
using one step of size h=0.5.
At the starting point, the slope is
f(0,2)=2
Update x:
x_1 = 0 + 0.5 = 0.5
Update y:
y_1 = 2 + 0.5(2) = 3
So the next Euler point is (0.5, 3).
For
dy/dt = y(1-y)
0 < y < 1, then y(1-y)>0, so y increases;y > 1, then 1-y<0, so y decreases;y < 0, then y<0 and 1-y>0, so y decreases.The equilibrium y=1 attracts nearby positive solutions. We call it stable. The equilibrium y=0 pushes nearby solutions away. We call it unstable.
x and y.What does a horizontal segment in a slope field mean?
Use one Euler step for y'=2y, y(0)=1, h=0.25.
Find the equilibria of dy/dt = y(4-y).
For dy/dt = y(4-y), is the solution increasing or decreasing when y=5?
2; x_1=0.25; y_1=1+0.25(2)=1.5.y=0 and y=4.5(4-5)=-5 is negative.A slope field is a visual calculator for an ODE. It does not give a formula by itself; it shows local directions that solution curves should follow.
Guess first. For y' = x - y, what is the slope at (2, 1)?
Guided exercise.
Substitute the coordinates into the right-hand side:
f(x,y) = x - y
f(2,1) = 2 - 1 = 1
At (2,1), the slope-field segment should tilt upward with slope 1.
Checkpoint. For y' = y(2-y), compute the slope at y=0, y=1, and y=3. Which segments are horizontal?
Guess first. For y' = y(2-y), which values of y make the derivative zero?
Guided exercise.
y(2-y) = 0
y = 0 or y = 2
Test intervals:
0 < y < 2 -> y' > 0, solutions move upward
y > 2 -> y' < 0, solutions move downward
y < 0 -> y' < 0, solutions move downward
So y=2 attracts nearby positive solutions, while y=0 repels nearby positive solutions.
Checkpoint. Find the equilibria of y' = (y - 1)(3 - y). Test the sign of y' on each interval.
Guess first. Euler’s method uses the old slope or the new slope?
Guided exercise. Use one step for y' = x + y, y(0)=1, h=0.2.
x0 = 0, y0 = 1
slope = f(0,1) = 0 + 1 = 1
x1 = 0 + 0.2 = 0.2
y1 = 1 + 0.2(1) = 1.2
Euler uses the slope at the current point, then moves.
Checkpoint. Use one Euler step for y' = 2 - y, y(0)=0, h=0.5.
Guess first. If an Euler approximation increases, does that prove the exact solution always increases?
Guided exercise.
Euler steps give sampled evidence. A slope-field or sign analysis gives broader behavior. For autonomous equations, the sign of f(y) on intervals tells you where solutions increase or decrease between equilibria.
Checkpoint. For y' = y(1-y), explain why a solution starting at y(0)=0.5 should increase toward 1 without solving the equation exactly.
Use edumath for Euler approximations.
[(0, 2), (0.5, 3.0), (1.0, 4.5), (1.5, 6.75)]
Use SymPy for an exact comparison when an exact solution exists.
\(\displaystyle y{\left(x \right)} = C_{1} e^{x}\)
The exact solution of y'=y is exponential. Euler’s method approximates that curve with small straight-line steps.