Approximating solutions of boundary value problems

### 23.4.3 Approximating solutions of boundary value problems

The bvpsolve command finds an approximate solution ŷ(t) of a boundary value problem

y′′=f(t,y,y′), y(a)=α, y(b)=β

on the interval [a,b]. The procedure uses the method of nonlinear shooting which is based on Newton and Runge-Kutta methods. Values of y and its first derivative y′ are approximated at points tk=a+k δ, where δ=b−a/N and k=0,1,…,N.

- bvpsolve takes three mandatory arguments and four optional arguments:
  - f(t,y,y′), an expression defining y′′.
  - [t=a..b,y], a list specifying the variable t, its range [a,b] and the sought function y.
  - [α,β], a list of the boundary values of y.
  - Optionally, A, an initial guess for y′(a) (by default, (β−α)/(b−a)).
  - Optionally, N, an integer greater than or equal to 2 (by default 100).
  - Optionally, output=type or Output=type, the type of the output, where type can be one of: list (the default), diff, piecewise or spline.
  - Optionally, limit=M, a positive integer for a limit for the number of iterations before the procedure is stopped (by default there is no limit).
- bvpsolve(f(t,y,y′),[t=a..b,y],[α,β] ⟨,A,N, output=type,limit=M ⟩) returns:
  - with type=list, a list of pairs [tk,yk] where yk≈ y(tk),
  - with type=diff, a list of triples [tk,yk,y′k], where y′k≈ y′(tk),
  - with type=piecewise, a piecewise linear interpolation of the points (tk,yk),
  - with type=spline, a piecewise spline interpolation of the points (tk,yk), based on the values y′k computed in the process.

Note that the shooting method is sensitive to roundoff errors and may fail to converge in some cases, especially when y is a rapidly increasing function. In the absence of convergence or if the maximum number of iterations is exceeded, bvpsolve returns undef. However, if the output type is list or piecewise and if N>2, a slower but more stable finite-difference method (which approximates only the function y) is tried first.

Sometimes setting an initial guess A for y′(a) to a suitable value may help the shooting algorithm to converge or to converge faster.

#### Examples

Solve y′′=1/8 (32+2 t3−y y′) with 1≤ t≤ 3 and boundary conditions y(1)=17 and y(3)=43/3 (the exact solution is y(t)=t2+16/t). Use N=20, which gives an t-step of 0.01. To display approximated and exact values together, enter:

aprx:=bvpsolve((32+2t^3-y*y')/8,[t=1..3,y],[17,43/3],20):; exct:=apply(t->t^2+16/t,linspace(1.0,3.0,21)):; prepend(border(aprx,exct),[t,y_k,y(t_k)])

| ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |
t | yk |
y | ⎛ ⎝ | tk | ⎞ ⎠
1.0 | 17.0 | 17.0
1.1 | 15.7554961579 | 15.7554545455
1.2 | 14.7733911821 | 14.7733333333
1.3 | 13.9977543159 | 13.9976923077
1.4 | 13.388631813 | 13.3885714286
⋮ | ⋮ | ⋮
2.8 | 13.5542890043 | 13.5542857143
2.9 | 13.9272429048 | 13.9272413793
3.0 | 14.3333333333 | 14.3333333333
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

As another example, solve t5 y′′=t2 y′2−9 y2+4 t6 with 1≤ t≤ 2 and boundary conditions y(1)=0 and y(2)=ln256. Obtain the solution as a piecewise spline interpolation for N=10 and estimate the absolute error err of the approximation using the exact solution y=t3 lnt and the romberg command for numerical integration. You need to explicitly set an initial guess A for the value y′(1) because the algorithm fails to converge with the default guess A=ln256≈ 5.545. Therefore let A=1 instead.

f:=(t^2*diff(y(t),t)^2-9*y(t)^2+4*t^6)/t^5:; p:=bvpsolve(f,[t=1..2,y],[0,ln(256),1],10,output=spline):; err:=sqrt(romberg((p-t^3*ln(t))^2,t=1..2))

3.27751904973×10−6 |  |  |  |  |  |  |  |  |  |

Note that, if the output type was set to list or piecewise, the solution would have been found even without specifying an initial guess for y′(1) because the algorithm would automatically apply the alternative finite-difference method, which converges.