Initial Value Problem Solver — Theory
1. What is an initial value problem?
An initial value problem, or IVP, is a differential equation together with a starting value.
For a first-order equation, the usual form is:
\[
\frac{dy}{dx}=f(x,y),
\qquad
y(x_0)=y_0.
\]
The condition \(y(x_0)=y_0\) tells the solution curve exactly where it must pass.
2. First-order IVPs
A first-order IVP asks for a function \(y(x)\) whose derivative satisfies:
\[
y'=f(x,y).
\]
The graph of the solution must pass through the initial point:
\[
(x_0,y_0).
\]
If an exact formula is known, the solution can be written symbolically.
If not, numerical methods approximate the solution point by point.
3. Example: \(y'=y,\ y(0)=1\)
The equation says that the function is equal to its own derivative:
\[
\frac{dy}{dx}=y.
\]
The general solution is:
\[
y=Ce^x.
\]
Use the initial condition:
\[
y(0)=1.
\]
Then:
\[
1=Ce^0=C.
\]
Therefore:
\[
y=e^x.
\]
4. Second-order IVPs
A second-order IVP usually needs two initial conditions:
\[
y''=F(x,y,y'),
\qquad
y(x_0)=y_0,
\qquad
y'(x_0)=v_0.
\]
The value \(y(x_0)\) gives the starting position, and \(y'(x_0)\) gives the starting slope or velocity.
5. Turning a second-order IVP into a system
Numerical methods usually handle first-order systems. For a second-order equation, define:
\[
v=y'.
\]
Then:
\[
y'=v,
\qquad
v'=F(x,y,v).
\]
So the second-order equation becomes a system of two first-order equations.
6. Euler method
Euler’s method is the simplest numerical method. Starting from \((x_n,y_n)\), it uses the slope at the current point:
\[
y_{n+1}=y_n+h f(x_n,y_n).
\]
The new \(x\)-value is:
\[
x_{n+1}=x_n+h.
\]
Euler’s method is easy to understand, but it can be inaccurate if the step size \(h\) is too large.
7. Heun method
Heun’s method, also called improved Euler, averages an initial slope and a predicted slope:
\[
k_1=f(x_n,y_n),
\]
\[
k_2=f(x_n+h,y_n+hk_1).
\]
Then:
\[
y_{n+1}=y_n+\frac{h}{2}(k_1+k_2).
\]
Heun’s method is usually more accurate than Euler’s method.
8. RK4 method
The fourth-order Runge–Kutta method, or RK4, uses four slope estimates:
\[
k_1=f(x_n,y_n),
\]
\[
k_2=f\left(x_n+\frac{h}{2},y_n+\frac{h k_1}{2}\right),
\]
\[
k_3=f\left(x_n+\frac{h}{2},y_n+\frac{h k_2}{2}\right),
\]
\[
k_4=f(x_n+h,y_n+h k_3).
\]
The update is:
\[
y_{n+1}=y_n+\frac{h}{6}(k_1+2k_2+2k_3+k_4).
\]
RK4 is widely used because it is accurate and stable for many problems.
9. Exact recognition
Some IVPs have common exact solutions. For example:
10. Solution curve and initial marker
The solution curve must pass through:
\[
(x_0,y_0).
\]
The graph marks this point so that the starting condition is visible.
If a solution curve does not pass through the initial point, it is not the correct IVP solution.
11. Step size and accuracy
The step size \(h\) controls how far the method moves at each step.
Smaller \(h\) usually gives a better approximation but requires more computation.
\[
h=\Delta x.
\]
A large step size can cause visible error, especially for rapidly changing solutions.
13. Common mistakes
- Forgetting the initial condition: the solution must pass through \((x_0,y_0)\).
- Using only one initial condition for a second-order IVP: second-order problems need both \(y(x_0)\) and \(y'(x_0)\).
- Confusing \(y'\) and \(y''\): first-order and second-order equations require different setups.
- Using too large a step size: large \(h\) can produce a poor numerical solution.
- Reading numerical curves as exact formulas: numerical methods approximate the solution unless an exact form is recognized.
- Ignoring units: graph axes should show both numbered values and units.