Learn R Programming

pracma (version 1.2.0)

bvp: Solve Boundary Value Problem

Description

Solves the two-point boundary value problem given as a differential equation of the form: $$-c_1 y'' + c_2 y' + c_3 y = f(x)$$ with the centered finite difference method. The solution $y(x)$ shall exist on the interval $[a, b]$ with boundary conditions $y(a) = y_a$ and $y(b) = y_b$.

Usage

bvp(f, a, b, ya, yb, N, cc, ...)

Arguments

f
function on the right side of the differential equation.
a, b
interval borders where the solution shall be computed.
ya, yb
boundary conditions such that y(a) = ya, y(b) = yb.
N
number of intermediate grid points.
cc
contains the coefficients cc[1], cc[2], cc[3] of the equation.
...
additional arguments to be passed to the function f.

Value

  • Returns a list list(xh, yh) with the grid points xh and the values yh of the solution at these points.

Details

Computes the solution as a least-squares approximation.

References

Quarteroni, A., and F. Saleri (2006). Scientific Computing with MATLAB and Octave. Springer-Verlag, Berlin Heidelberg.

See Also

feuler

Examples

Run this code
##  Solve -y'' + 0.1*y = 1 + sin(4*pi*x) on [0, 1] with y(0) = y(1) = 0.
fun <- function(x) 1 + sin(4*pi*x)
sol <- bvp(fun, 0, 1, 0, 0, 40, c(1, 0, 0.1))
plot(sol$xh, sol$yh, type="l", col="blue")
grid()

Run the code above in your browser using DataLab