Solve a boundary value problem — one with conditions fixed at both ends of an interval — by the shooting method. Guess the initial slope at the left end, integrate to the right end, look at how far you miss the target, and re-aim, exactly like aiming a cannon. Watch the whole process in real time.
Parameters
ODE coefficient c (y'' = c·y)
c>0 gives a hyperbolic (exponential) solution, c<0 an oscillatory one
Interval length L
The interval [0, L] on which the BVP is solved
Left boundary value y(0)
Solution value A fixed at the left end of the interval
Right boundary value y(L)
Target value B fixed at the right end (the shooting target)
Maximum iterations
Cap on the number of shots. A linear problem converges in 2
Results
—
Required initial slope y'(0)
—
Right-end value reached y(L)
—
Endpoint error
—
Iterations (shots)
—
Mid-point value y(L/2)
—
Convergence
—
The shots — trajectory animation
Fired from the left boundary point, the solution is shot again and again with different initial slopes. The under-shooting (orange), over-shooting (red) and converged (blue, bold) trajectories are drawn; only the blue one passes exactly through the right-end target.
Converged solution y(x)
Trajectories of the successive shots
Theory & Key Formulas
$$y''=c\,y,\quad y(0)=A,\ y(L)=B$$
The boundary value problem to solve. The solution value A and B are fixed at the two ends of the interval [0, L]. It is converted to the first-order system $y'=v,\ v'=c\,y$ for integration.
The secant update of the initial slope. $y_{end}(s)$ is the value reached at the right end with initial slope s, and $s_0,s_1$ are trial slopes. For a linear ODE $y_{end}(s)$ is a first-degree function of s, so two shots and one interpolation hit the boundary exactly.
What is the Shooting Method?
🙋
A "boundary value problem" is a kind of differential equation, right? How is it different from solving an ordinary one?
🎓
Roughly speaking, the difference is where you supply the conditions. Like a thrown ball, an initial value problem gives the starting position and velocity together at one point. A boundary value problem instead splits the conditions between the two ends of an interval: "y is this value at the left end, that value at the right end." The deflection of a beam fixed at both ends, or the steady heat conduction in a rod whose two ends are held at set temperatures, are boundary value problems. The key is that both ends are pinned down.
🙋
If both ends are fixed, can't I just integrate from the left with Runge-Kutta as usual?
🎓
That is exactly the trap. A marching solver like Runge-Kutta can only take its first step once it has both the value and the slope at the starting point. But in a boundary value problem you know y(0) at the left end yet not y'(0), the initial slope. The right-end condition is given instead, but that does not help you start the integration from the left. One end alone simply does not give enough information to set off.
🙋
I see... so what do you do about the missing y'(0)?
🎓
That is where the shooting method comes in. The idea is simple: just guess the missing y'(0). Pick any slope s and the left end now has both value and slope — it is a plain initial value problem. You can integrate all the way to the right end with Runge-Kutta. There y reaches some value, and how far that is from the target B is the "miss". You aim a cannon at a distant target, see how far you miss, and fire again. That is why it is called the shooting method.
🙋
Firing over and over sounds like a lot of work — but on the tool the iteration count stays at "2" and won't move. Why?
🎓
Good question. The equation this tool handles, y''=c·y, is actually linear in s. When it is linear, the right-end value reached, y_end(s), is a first-degree function of s. A straight line is fixed once you have two points on it. So you fire once with s=0 and once with s=1, measure the endpoint values, and from the line through those two points you back out the slope s* that passes through the target B — that is the secant interpolation. No third shot is needed. The endpoint error is essentially zero, hitting the target to machine precision. That is why the count is 2.
🙋
So for a nonlinear problem you really would fire many more times?
🎓
Exactly. For a nonlinear problem y_end(s) becomes a curved function, and a line through two points will not hit it. So you think of it as "solve the equation miss F(s)=y_end(s)−B equals zero" and iterate the secant or Newton method, running one integration per iteration, firing until the miss is small enough. For stiff problems like boundary-layer flow equations, a bad initial guess can even make the solution blow up, so in practice engineers often use "multiple shooting", which splits the interval and fires on each piece separately.
Frequently Asked Questions
The shooting method solves a boundary value problem (BVP) — one with conditions fixed at both ends of an interval — by guessing the missing information at one end, turning it into an initial value problem (IVP), and iterating. For y''=c·y with y(0)=A and y(L)=B, the initial slope y'(0) at the left end is unknown. We guess it as s, integrate to the right end with Runge-Kutta, see how far the resulting y(L) misses the target B, and correct s. Just like aiming a cannon at a distant target, you fire and re-aim, which is why it is called the shooting method.
When the equation is linear in the initial slope s — as y''=c·y is — the value reached at the right end, y_end(s), is an affine (first-degree) function of s. A straight line is fully determined by two points, so firing once with s0=0 and once with s1=1 and measuring y_end lets you find, by linear interpolation (the secant step), the slope s* that hits the target B exactly. No third iteration is needed, and the endpoint error drops to machine precision (about 1e-12 or below).
For a nonlinear problem y_end(s) is no longer a straight line in s, so two shots do not hit the target. You then treat the endpoint miss F(s)=y_end(s)−B as a nonlinear equation to be driven to zero, applying the secant or Newton method iteratively. Each iteration runs one integration, and you repeat until the miss falls below a tolerance. This tool handles a linear equation, so it converges in two shots, but the maximum-iteration slider reflects the general nonlinear procedure.
A marching solver like Runge-Kutta can only start once it knows both the value and the slope at a single point. But in a boundary value problem you know y(0) at the left end yet not y'(0); the condition y(L) is given at the right end instead. One end alone does not provide enough information to start the integration. The shooting method fills this gap by guessing the missing y'(0), reducing the boundary value problem to an ordinary initial value problem integration.
Real-World Applications
Beam deflection in structural mechanics: The bending of a beam supported at both ends is a boundary value problem for the deflection w(x). Deflection or slope is constrained at both ends, so an initial value problem solver cannot tackle it directly. With the shooting method you guess an unknown reaction moment or shear force at one end and adjust until the boundary condition at the other end is met, letting you handle numerically even variable-section beams or elastically supported beams that resist a closed-form solution.
Steady heat conduction and reaction-diffusion: Steady heat conduction in a rod with both end temperatures fixed, or the reaction-diffusion equation inside a catalyst particle, are classic boundary value problems. With a heat-generation term or temperature-dependent properties they become nonlinear and admit no analytic solution. The shooting method assumes the unknown heat flux at one end, integrates, and matches the temperature at the other end to recover the temperature or reaction-rate distribution.
Boundary-layer equations in fluid mechanics: The Blasius equation f'''+f·f''/2=0, which describes the laminar boundary layer on a flat plate, is a nonlinear boundary value problem with conditions at the wall and at infinity. You guess the unknown wall shear f''(0) by the shooting method and iterate until the far-field condition f'→1 is satisfied. It is a classic application that feeds directly into estimates of friction drag and heat transfer around aircraft and turbine blades.
Eigenvalue problems in quantum mechanics: Finding the bound-state energy eigenvalues of the one-dimensional Schrödinger equation is also a boundary value problem, with the wave function decaying to zero at both ends. You integrate the wave function from one end with the energy as a parameter and use the shooting method to find the energy at which the value at the other end becomes zero. It is a representative case where eigenvalue search and the shooting method are combined.
Common Misconceptions and Pitfalls
The biggest pitfall is assuming that "because a linear problem hits in two shots, a nonlinear one converges just as fast". The equation y''=c·y handled by this tool is linear in the initial slope s, so the endpoint value y_end(s) is a first-degree function of s and two shots plus one interpolation hit the target exactly. But in a nonlinear boundary value problem y_end(s) becomes a curved function, and a line through two points will not hit it. With a poor initial guess the iteration can oscillate or fail to converge altogether. Keep the linear/nonlinear distinction in mind, and for nonlinear problems run the secant or Newton iteration through to the end.
Next, the oversight that "the shooting method cannot be used on an unstable equation whose initial value integration diverges". For a strongly positive coefficient c, a hyperbolic equation, the solution contains an exponentially growing component. Integrating from one end makes a tiny error in the initial slope blow up explosively through this growing mode, producing huge numbers or overflow at the endpoint. The longer the interval, the worse it gets. In practice this is avoided with "multiple shooting", which splits the interval into several sub-intervals, shoots each separately and joins them at the boundaries. Simple shooting is not a cure-all.
Finally, the misconception that "the accuracy of the shot is determined by the interpolation algorithm alone". The final accuracy of a shooting-method solution depends not only on the interpolation that drives the miss to zero (such as the secant method) but also on the accuracy of the inner initial value problem solver. This tool uses 4th-order Runge-Kutta with about 400 steps, so for a linear problem the endpoint error reaches machine precision. But with too few steps, or with a low-order Euler method, a discretization error remains in the integration itself even if the interpolation is perfect, and the solution can be no better than that accuracy. The shooting method is a two-stage process of "interpolation" and "integration", and only when both are accurate do you get a trustworthy solution.
How to Use
Enter the differential equation coefficient (cNum) and its valid range (cRange) governing the ODE curvature behavior.
Set domain length (lNum in meters) and left boundary condition ylNum, right boundary condition yrNum for your BVP.
Input the lRange and ylRange/yrRange tolerances, then execute iterations; the simulator adjusts the trial slope y'(0) until y(L) converges within endpoint error tolerance.
Worked Example
For a cantilever beam deflection problem: d²y/dx² + 0.5y = 0 with y(0)=0, y(3)=0 (3 meter span, simply supported ends). Initial slope guess y'(0)=1.2 rad. After 6 shots, simulator converges to y'(0)=−0.847 rad, reaching y(3)=0.0012 m (error 0.12%). Mid-point deflection y(1.5)=0.234 m. Convergence achieved in 0.18 seconds.
Practical Notes
Start with coarse lRange tolerance (±0.1) for quick qualitative results; refine to ±0.01 for engineering designs requiring stress verification.
Negative coefficient values (cNum < 0) model growing exponential behavior; watch for divergence requiring tighter ylRange bounds.