Previous Up Next

8.3.6  Approximate solution of a nonlinear second-order boundary value problem : bvpsolve

bvpsolve finds an approximate solution of a boundary value problem

y″=f(x,y,y′),   y(a)=α, y(b)=β 

on the interval [a,b]. It takes the following mandatory arguments :

One or more of the additional arguments below can optionally follow (in no particular order) :

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 xk=a+k δ, where δ=ba/N and k=0,1,…,N. For the numeric tolerance (precision) threshold, the algorithm uses epsilon specified in the session settings in Xcas. If the output type is

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 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 for y′(a) to a suitable value may help the shooting algorithm to converge or to converge faster. The default initial guess y0′ for the value y′(a) is

y0′=
β−α
ba
Examples.

In the first example we solve the problem

y″=
1
8
 (32+2 x3y y′),   1≤ x≤ 3

with boundary conditions y(1)=17 and y(3)=43/3. We use N=20, which gives x-step of 0.01. Input :

bvpsolve((32+2x^3-y*y’)/8,[x=1..3,y],[17,43/3],20)

The output is shown in Table 8.1 (the middle two columns) alongside with the values y(xk) of the exact solution y=x2+16/x (the fourth column).


kxkyky(xk)
01.017.017.0
11.115.755496157915.7554545455
21.214.773391182114.7733333333
31.313.997754315913.9976923077
41.413.38863181313.3885714286
51.512.916722742412.9166666667
61.612.560050648312.56
71.712.301809610112.3017647059
81.812.128928141412.1288888889
91.912.031086527412.0310526316
102.012.000028926812.0
112.112.029071998112.029047619
122.212.112747527812.1127272727
132.312.246538280312.2465217391
142.412.426679882512.4266666667
152.512.65001025412.65
162.612.913853783412.9138461538
172.713.215931242613.2159259259
182.813.554289004313.5542857143
192.913.927242904813.9272413793
203.014.333333333314.3333333333
Table 8.1: approximate and true values of the function y=x2+16/x on [1,3]

In the next example we solve the problem

y″=
x2 (y′)2−9 y2+4 x6
x5
,   1≤ x≤ 2, 

with the boundary conditions y(1)=0 and y(2)=ln256. We 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=x3 lnx and romberg command for numerical integration. We also need to explicitly set an initial guess y0′ for the value y′(1) because the algorithm fails to converge with the default guess y0′=ln256≈ 5.545. Therefore let y0′=1 instead. Input :

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

Output :

3.27720911686e-06

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.


Previous Up Next