pracma (version 1.9.9)

shooting: Shooting Method

Description

The shooting method solves the boundary value problem for second-order differential equations.

Usage

shooting(f, t0, tfinal, y0, h, a, b, itermax = 20, tol = 1e-6, hmax = 0)

Arguments

f
function in the differential equation $y'' = f(x, y, y')$.
t0, tfinal
start and end points of the interval.
y0
starting value of the solution.
h
function defining the boundary condition as a function at the end point of the interval.
a, b
two guesses of the derivative at the start point.
itermax
maximum number of iterations for the secant method.
tol
tolerance to be used for stopping and in the ode45 solver.
hmax
maximal step size, to be passed to the solver.

Value

Returns a list with two components, t for grid (or `time') points between t0 and tfinal, and y the solution of the differential equation evaluated at these points.

Details

A second-order differential equation is solved with boundary conditions y(t0) = y0 at the start point of the interval, and h(y(tfinal), dy/dt(tfinal)) = 0 at the end. The zero of h is found by a simple secant approach.

References

L. V. Fausett (2008). Applied Numerical Analysis Using MATLAB. Second Edition, Pearson Education Inc.

See Also

bvp

Examples

Run this code
#-- Example 1
f <- function(t, y1, y2) -2*y1*y2
h <- function(u, v) u + v - 0.25

t0 <- 0; tfinal <- 1
y0 <- 1
sol <- shooting(f, t0, tfinal, y0, h, 0, 1)
## Not run: 
# plot(sol$t, sol$y[, 1], type='l', ylim=c(-1, 1))
# xs <- linspace(0, 1); ys <- 1/(xs+1)
# lines(xs, ys, col="red")
# lines(sol$t, sol$y[, 2], col="gray")
# grid()## End(Not run)

#-- Example 2
f <- function(t, y1, y2) -y2^2 / y1
h <- function(u, v) u - 2
t0 <- 0; tfinal <- 1
y0 <- 1
sol <- shooting(f, t0, tfinal, y0, h, 0, 1)

Run the code above in your browser using DataLab