web viewone thing worthy of note is that the dimensionless shear at the wall, i.e....

39
[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com [100] 007 revised on 2012.10.30 cemmath The Simple is the Best Chapter 7 Boundary Value Problems 7-1 Syntax of Umbrella ‘bvp’ 7-2 2nd-Order BVPs 7-3 Examples of Using Spokes 7-4 3rd-Order BVPs 7-5 4th-Order BVPs 7-6 Hub Field 7-7 Conservative Form and Eigenvalue BVPs 7-8 System of BVPs 7-9 Summary of Syntax 7-10 References Boundary value problems (BVPs) are characterized by the existence of more than one point of independent variable at which conditions for the dependent variables are specified. In this chapter, we introduce the Umbrella ‘bvp’ which can treat ordinary differential equations (ODEs) and parabolic- elliptic partial differential equations (i.e., initial-boundary value problems). 1

Upload: nguyenxuyen

Post on 05-Feb-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

[100] 007 revised on 2012.10.30 cemmath

The Simple is the Best

Chapter 7 Boundary Value Problems

7-1 Syntax of Umbrella ‘bvp’7-2 2nd-Order BVPs7-3 Examples of Using Spokes7-4 3rd-Order BVPs7-5 4th-Order BVPs7-6 Hub Field7-7 Conservative Form and Eigenvalue BVPs 7-8 System of BVPs7-9 Summary of Syntax 7-10 References

Boundary value problems (BVPs) are characterized by the existence of more than one point of independent variable at which conditions for the dependent variables are specified. In this chapter, we introduce the Umbrella ‘bvp’ which can treat ordinary differential equations (ODEs) and parabolic-elliptic partial differential equations (i.e., initial-boundary value problems).

Section 7-1 Syntax of Umbrella ‘bvp’

In this section, we discuss the syntax of Umbrella ‘bvp’ for the case of ODEs. For practical purpose, a single ODE up to at most fourth order is considered with its boundary conditions (BCs).

■ A heuristic approach. Before we state the basic syntax of Umbrella ‘bvp’, let us consider a simple BVP written as

0≤ x≤ π , y ''+ y=0 , y (0 )=0 , y ' (π )=−1

1

Page 2: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

the exact solution of which is y=sin x . The question at present is how simple it can be to describe this system of BVP as far as possible. Concluded here it is that a heuristic approach would be the best way of presenting our use of Umbrella ‘bvp’.

○ Given BVP: 0 ≤ x≤ π , y ''+ y=0 , y (0 )=0 , y ' (π )=−1○Cemmath : #> bvp .x(0,pi) ( {y''}+{y} = 0, [ {y}=0, {y'}=-1 ] ).plot;

where the result is shown in Figure 1.

Figure 1 A heuristic approach to BVP

Although there exist some discrepancies between the system of BVP and the Cemmath command, it is predictable in a heuristic manner what the Umbrella ‘bvp’ would look like. Indeed, this is our motive of developing the Umbrella ‘bvp’ which can treat most of BVPs as they appear. In the above case, Spoke ‘plot’ delivers a command to draw the default result (i.e. the curve for y).

■ Standard BVP. The Umbrella ‘bvp’ is designed to solve BVPs up to fourth order the general forms of which are

DE : L f +cs=0BCs : bw f ' ' '+bv f ' '+bu f '+b f f =br

where a differential operator L is defined as

2

Page 3: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

L ≡c zd4

d x 4 +(cw+c fw f +cuw f '+cvw f ' '+cww f ' ' ' ) d3

d x3

+(cv+c fv+cuv f '+cvv f ' ' ) d2

d x2

+(cu+c fu f +cuu f ') ddx

+(c f +c ff f )

For second-order BVPs, it would be clear that

c z=0 , cw=c fw=cuw=cvw=cww=0cv=c p , cvv=0

bw=bv=0

Also, for third-order BVPs, we have

bw=0c z=0 , cw=cp , cww=0

Because most BVPs are of nonlinear nature, it is crucial to handle severe nonlinearities in both DE and BCs. The differential operator L suggested here implies that the discretization of DE is performed only for algebraic nonlinearities, and other types of nonlinearities are treated as coefficients or source terms. However, this observation does not limit the usefulness of Umbrella ‘bvp’, since specification of the standard form is just to improve the convergence rate of computation.

■ Syntax of ‘bvp’. The syntax of Umbrella ‘bvp’ is similar to other Umbrellas discussed so far. However, the Stem of ‘bvp’ is considerably different from the previous ones. A typical syntax of ‘bvp’ is

bvp .x[n=101,g=1](a,b) ( DE, [ BCs ] ) .Spoke.Spoke ...or

x = (a,b).span(n,g=1); bvp [x] ( DE, [BCs] ) .Spoke.Spoke ...

where DE and BCs are specific to each BVP. It goes without saying that Hub is exactly the same as the grid span, and thus no further discussion is given here.

3

Page 4: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Within the Stem, all the terms participating in the discretization process, called non-source terms, are enclosed by ‘{ }’, and are multiplied by proper coefficients if necessary. The differentiation with respect to the independent variable defined in the Hub is denoted by prime '. Referring to the differential operator L defined above, the general form of DE becomes

cz*{f''''} +cw*{f'''} +cfw*{ff'''} +cuw*{f'f'''} + cvw*{f''f'''} + cww*{f'''f'''}+cv*{f''} +cfv*{ff''} +cuv*{f'f''} + cvv*{f''f''} +cu*{f'} +cfu*{ff'} +cuu*{f'f'} +cf*{f} +cff*{ff} = cs

And the general form of BCs reads

bw*{f'''} + bv*{f''} + bu*{f'} + bf*{f} = bs

We now discuss rules that should be kept in describing Stem for ‘bvp’.

The highest-order term must be one of {y''}, {y'''}, {y''''} depending on the degree of BVP. A use of variable y here is just nominal and thus any variable can be used upon users’ choice.

No multiple use of non-source terms, e.g. {u''} + 3*{u} + {u} = 0 is illegal since {u} appears twice.

BCs must be stated from the starting to ending points. Non-source terms cannot be placed inside ‘( )’ and after ‘=’. Only ‘+’, ‘-’ or ‘=’ can follow right after ‘{ }’, e.g. {f}/2 is illegal while

0.5*{f} is acceptable. Any coefficient including ‘+’ and ‘-’ must be placed inside parentheses, e.g.

{f''}-1.23e-6*{f} is illegal whereas {f''}-(1.23e-6)*{f} is acceptable.

■ Spokes for ‘bvp’. As was in other Umbrellas, Spokes for ‘bvp’ are also very helpful to enhance the performance of ‘bvp’. Listed below are some Spokes for ‘bvp’.

.peep peep the iteration procedure .relax(relax=0.5) under-relaxation factor .tol/abstol(abstol=1.e-5) absolute tolerance .reltol(reltol=1.e-5) relative tolerance .maxiter(maxiter=500) maximum iteration count .shift(scalar) eigenvalue shift

4

Page 5: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

.plot plot default data

.plot(f,f',f'',...) plot user-defined data

.return (f,f',f'',...) return user-defined data

.togo (Y=y,Y1=y',...) takeout each field

When heavy nonlinearities cause trouble of convergence, use of Spoke ‘relax’ (an abbreviation of under-relaxation factor) can resolve such a problem.

Section 7-2 2nd-Order BVPs

■ 2nd-order BVP. The first example adopted from ref [1] has a shock near x=0 and is written as

−1 ≤ x ≤1 , ϵy ''+xy '=ϵ π 2cos ( πx )−πxsin ( πx ) ,

y (−1 )=−2 , y (1 )=0 , ϵ=10−4

the solution of which can be obtained by the following Cemmath commands

%> shock near at x = 0 #> eps = 1.e-4;; #> bvp .x(-1,1) ( // bvp .x[101,1](-1,1) equivalently eps*{y''}+x*{y'} = eps*pi^2*cos(pi*x)-pi*x*sin(pi*x), [ {y}=-2, {y}=0 ]

).plot .return(x,y);

The result is shown in Figure 2. Note that the default use of ‘.plot’ is the same as ‘.plot(y)’. Also, the discretization at x=0 is avoided by employing odd number of points, since discretization is performed at all x i−1 / 2 ,i=1,2,3 , …, n.

ans = [ -1 -2 ] …

[ -0.02 -0.0066525 ] [ 0 0.99335 ] [ 0.02 1.9933 ]

5

Page 6: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

[ 1 8.362e-009 ]

Figure 2 Shock near

The next example describing the shape of a droplet [ref. 2] is written as

−1≤ x ≤1 , h ''+ (1−h ) (1+h '2 )3 / 2=0

h (−1 )=h (1 )=0

This can be solved by

%> droplet shape #> bvp.x[21](-1,1) ( {h''} + (1+h'^2)^1.5 - (1+h'^2)^1.5*{h} = 0, [ {h}=0,{h}=0 ] )

.plot;

and the result is shown in Figure 3.

Figure 3 Droplet shape

6

0x

Page 7: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

To save computation time, the above problem can be alternatively solved by

#> a=0;; #> bvp.x[21](-1,1) ( {h''} - ( a=(1+h'^2)^1.5 )*{h} + a = 0, [ {h}=0,{h}=0 ] ).plot;

A special care should be taken in that the variable ‘a’ in this example must be pre-defined by any value.

Another example for 2nd-order BVP is the Emden’s equation [ref. 3] written as

0 ≤ x≤ 1, y ''+ 2x

y '+ y5=0 , y ' (0 )=0 , y (1 )=√32

Solving this equation requires a simple conversion for the non-source term y5 into y3 ( yy ) as follows

%> Emden's equation #> plot.x(0,1) ( (1+x*x/3)^-0.5 ); #> bvp.x[11](0,1) ( {y''}+(2/x)*{y'}+y^3*{yy}=0, [ {y'}=0, {y}=sqrt(3)/2 ] ).plot+;

The numerical solution is compared with the exact solution, as shown in Figure 4. In the above, Spoke ‘plot+’ is used to attach a pre-drawn exact solution.

Figure 4 Solution to the Emden’s equation

7

Page 8: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

■ Nonlinearities in BCs. Boundary conditions (BCs) for BVP can also involve nonlinearities which must be properly linearized. For example,

0≤ x≤ 1, 6 y ''+ y '2−4 y−1=0y (0 )=3 ,671 y ' (1 )+3 y4 (1 )=3888

where yex=x2+x+3. This example is solved by the following Cemmath commands

%> nonlinearity in BC #> bvp.x[10](0,1) (

6*{y''}+{y'y'}-4*{y}-1 = 0, [ {y}=3, 671*{y'}+3*y^3*{y} = 3888 ] ).plot(y, x*x+x+3);

The results are shown in Figure 5.

Figure 5 Nonlinearities in BCs

■ Characteristics of BVPs. Mathematically, it is well known that BVPs can have no solution at all, or multiple solutions. We begin with a strikingly absurd but numerically meaningful example. The BVP system of interest is

0 ≤ x≤ π , y ''+ y=0 , y (0 )=0 , y (π )=1

the solution of which cannot exist since the general solution y=A cos x+B sin x never satisfies the BCs given above. However, the following Cemmath commands

%> absurd solution

8

Page 9: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

#> bvp .x[10](0,pi) ( {y''}+{y}=0, [ {y}=0, {y}=1 ] ) .plot(y, 31.53*sin(x)); // mathematically no solution at all

surprisingly yield a numerical solution (?) shown in Figure 6.

Figure 6 Absurd numerical solution

However, this does not imply that it is indeed possible to get a numerical solution even when no mathematical solution is present. This absurd and weird result actually arose from the intrinsic nature of computation where only limited number of digits are allowed for computation. In other words, it can be easily understood that the right boundary x=π cannot be exactly assigned due to a use of finite number of digits to store π. Therefore, the actual boundary condition in the computation is replaced with x=π−ϵ where ϵ is sufficiently small. As a result, numerical solution so obtained takes the following form

0 ≤ x≤ π , y ''+ y=0 , y (0 )=0 , y (π−ϵ )=1⇒

y= sin xsin (π−ϵ )

which satisfies all the boundary conditions and the differential equation. The only discrepancy is that the boundary is not located exactly at x=π (the solution in Figure 6 approximately coincides with y=31.53 sin x). In this regard, it is emphasized that use of numerical approach should accompany with mathematical care to avoid absurdity otherwise unnoticeable.

Another example is multiplicity of solutions with

9

Page 10: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

0≤ x≤ π2

, y ''+ y=0 , y ' (0 )=1 , y ( π /2 )=1

⇒y=sin x+ A cos x

where A is an arbitrary number. The following commands

%> multiplicity in solutions #> bvp.x[10](0,pi/2) ( {y''}+{y}=0, [ {y'}=1, {y}=1 ] )

.plot(y,y', sin(x)+ 0.0019852*cos(x));

however result in a single numerical solution with A=0.0019852, as shown in Figure 7. This value may vary depending on the grid properties and the computer environment.

Figure 7 Multiplicity of solution

Section 7-3 Examples of Using Spokes

■ Using spokes. In order to illustrate the use of Spokes, let us start with a simple BVP

%> peep, y = sin(x) #> bvp.x[10](0,pi) ( {y''}+{y} = 0, [ {y'}=1, {y}=0 ] ) .peep.plot;

the execution of which shows the internal procedure of iteration (via Spoke ‘peep’) using an under-relaxation factor of 0.5 (default value)

(bvp) iter residue relax 1 12.21 0.5

10

Page 11: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

2 6.103 0.5 …

21 1.164e-005 0.5 22 5.82e-006 0.5

Since the given BVP is linear, there is no need of under-relaxation. Therefore, it is recommended to use a relaxation factor of 1 for efficiency in computation. In this case

%> relax, y = sin(x) #> bvp.x[10](0,pi) ( {y''}+{y} = 0, [ {y'}=1, {y}=0 ] ) .peep .relax(1).plot;

results in

(bvp) iter residue relax 1 12.21 1 2 1.45e-014 1

When extremely heavy nonlinearities are expected, much smaller relaxation than the default value of 0.5 may be helpful to obtain a converged solution. Other Spokes ‘abstol’, ‘reltol’, ‘maxiter’ also control tolerances, iteration count, and so on.

Another useful Spoke is ‘togo’ which extracts the field of interest and saves each field with corresponding named matrix. However, the Spoke ‘return’ returns a single unnamed matrix. The following commands

%> togo, return #> Sol = bvp.x[10](0,pi/2) ( {y''}+{y} = 0, [ {y}=0, {y}=1 ] )

.togo ( X=x, Y=y, Y1=y', Y0=y*y+y'*y'-1 )

.return(x,y,y'); #> Sol; X; Y; Y1; Y0;

indeed save the fields x, y, y' and y*y+y'*y'-1 in the matrices X,Y,Y1 and Y0, respectively

Sol = [ 0 2.6758e-007 1 ] [ 0.17453 0.17322 0.98489 ] [ 0.34907 0.34119 0.94 ]

11

Page 12: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

[ 0.5236 0.49886 0.86669 ] [ 0.69813 0.64144 0.76718 ] [ 0.87266 0.76463 0.64448 ] [ 1.0472 0.86471 0.50229 ] [ 1.2217 0.93864 0.34492 ] [ 1.3963 0.9842 0.17712 ] [ 1.5708 1 0.0039693 ] X =

[ 0 0.17453 0.34907 0.5236 0.69813 0.87266 1.0472 1.2217 1.3963 1.5708 ]

Y = [ 2.6758e-007 0.17322 0.34119 0.49886 0.64144

0.76463 0.86471 0.93864 0.9842 1 ] Y1 =

[ 1 0.98489 0.94 0.86669 0.76718 0.64448 0.50229 0.34492 0.17712 0.0039693 ]

Y0 = [ 1.5279e-005 1.5371e-005 1.5461e-005 1.5546e-005 1.5622e-005

1.5688e-005 1.5742e-005 1.5781e-005 1.5805e-005 1.5814e-005 ]

Also, Umbrella ‘bvp’ returns a matrix Sol = [ x, y, y' ] by the use of Spoke ‘return’.

Section 7-4 3rd-Order BVPs

■ 3rd-order BVP. Since there exist three BCs for 3rd-order BVPs, it happens to be ambiguous which point (left or right) has two BCs. To remove such an ambiguity, a rule is set up in such a way that the starting point of the grid span is associated with two BCs.

Our example for 3rd-order BVP is a Falkner-Skan BVP which reads

β=0.5 , 0≤ x<∞, f '''+ ff ''+β (1−f '2 )=0 ,

f (0 )=0 , f ' (0 )=0 , f ' (∞ )=1

Using Umbrella ‘bvp’, we solve this by

%> Falkner-Skan equations #> b = 0.5;;

12

Page 13: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

#> bvp .x[101](0,8) ( {f'''}+{ff''}+b-b*{f'f'} = 0, [ {f} = 0, {f'} = 0, {f'} = 1 ] ) .plot(f',f'') .return(f'')(1); //0.9280866

where x→ ∞ is replaced by a finite valuex≅ 8. Figure 8 shows the result of computation. Since the velocity and shear are of primary importance, only f' and f'' are shown by means of Spoke ‘.plot(f',f'')’.

One thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’. Since the field f'' is a vector, the value of return(f'')(1) corresponds to the first element.

Figure 8 A 3rd-order BVP, Falker-Skan

This example can be further extended to find shears for various values of β

%> multiple Falkner-Skan equations #> .hold;#> for(b = 0; b <= 1; b += 0.1) { bvp .x[101](0,8) ( {f'''}+{ff''}+b-b*{f'f'} = 0,

[ {f} = 0, {f'} = 0, {f'} = 1 ] ) .plot(f',f'') .return(f'')(1); }#> plot;

13

Page 14: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Displayed in Figure 9 are interesting results obtained from the above commands, and the variation of the dimensionless shear stress is

ans = 0.4698398 ans = 0.5872965 ans = 0.6870002 ans = 0.7750820 ans = 0.8547871 ans = 0.9280866 ans = 0.9962856 ans = 1.0603012 ans = 1.1208068 ans = 1.1783141 ans = 1.2332224

Figure 9 Variation of β in 3rd-order BVP, Falker-Skan

The next example is mainly to show the grid reversing, as stated below

f '''+ f '2+ f ' '− ff ''=x2+sin2 x−2sin xf (0 )=0 , f ' ( π )=−π , f '' (π )=−2

the exact solution of which is f ex=x sin x . Note that two BCs are specified at the boundary x=π . Therefore, we have to reverse the grid direction as

%> reverse grid direction #> bvp .x[21](pi,0) ( {f'''}+{f'f'}+{f'}-{ff''} = x*x+sin(x)^2-2*sin(x), [ {f'} = -pi, {f''} = -2, {f} = 0 ]

14

Page 15: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

) .plot( f, x*sin(x), f-x*sin(x) );

The results are shown in Figure 10.

Figure 10 Grid reversing for third-order BVP

Section 7-5 4th-Order BVPs

■ 4th-order BVP. Among four BCs pertinent to 4th-order BVP, two-and-two style can be handled by Cemmath, i.e. two BCs for one boundary and two BCs for the other boundary. Other types of BCs should be solved by trial and error, or by mean of the shooting method.

An example of 4th-order BVP is

0 ≤ x≤ ln (1+√2 ), y ( 4)+ y '' cos ( y )− y '2 sin ( y )=0

y (0 )=0 , y ' (0 )=2y [ ln (1+√2 ) ]=π / 2, y '[ ln (1+√2 ) ]=√2

where the exact solution is given by

1+cos ( y / 2 )+sin ( y / 2 )1+cos ( y / 2 )−sin ( y / 2 )

=ex

15

Page 16: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

This can be solved by

%> 4th-order BVP #> bvp .x[21](0,log(1+sqrt(2))) (

{y''''} +cos(y)*{y''} - sin(y)*{y'y'} = 0, [ {y}=0, {y'}=2, {y}=0.5*pi, {y'}=sqrt(2) ]

) .plot( y, (1+cos(0.5*y)+sin(0.5*y))/(1+cos(0.5*y)-sin(0.5*y)) / exp(x) );

The results are shown in Figure 11.

Figure 11 A 4th-order BVP

Another example of 4th-order BVP is

0≤ x≤ 1, y ( 4)−2a ey ( y ''+ y '2 )=0y (0 )=u (0 ) , y ' (0 )=u ' (0 )y (1 )=u (1 ) , y ' (1 )=u '(1)

where the exact solution is given by

u=ln asin2(ax+b)

, u '= −2 atan (ax+b)

For the case of a=b=1, this can be solved easily by

16

Page 17: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

%> 4th-order BVP #> a = b = 1;; c = 0;; // don't forget pre-defining c #> (y1,yp1) = ( log(a/sin(b)^2), -2*a/tan(b) );; #> (y2,yp2) = ( log(a/sin(a+b)^2), -2*a/tan(a+b) );;

#> bvp .x[11](0,1) ( {y''''} - ( c = 2*a*exp(y) )*{y''} - c*{y'y'} = 0, [ {y} = y1, {y'} = yp1, {y} = y2, {y'} = yp2 ] ) .plot(y,y',y'',y'''); #> plot+ .x(0,1) (log(a/sin(a*x+b)^2), -2*a/tan(a*x+b));

The results are shown in Figure 12.

Figure 12 A 4th-order BVP

Section 7-6 Hub Field

■ Definition of field. Consider a 2nd-order BVP with variable coefficients and variable source written as

m (x )=1+ x , c (x )=ex , k ( x )=1+sin x ,f ( x )=−cos x

17

Page 18: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

m (x ) d2ud x2 ( x )+c ( x ) du

dx( x )+k ( x )u ( x )=f (x)

where 0 ≤ x≤ 2, u (0 )=u (2 )=0. This can be easily solved by

%> field definition #> bvp.x[21](0,2) (

(1+x)*{u''}+(exp(x))*{u'}+(1+sin(x))*{u} = -cos(x), [ {u}=0, {u}=0 ] ).plot(u);

And the result is shown in Figure 13.

Figure 13 Variable coefficients and source

However, Cemmath supports another way of solving this problem via a concept of Hub field. Although the Hub field requires use of matrices, we will discuss only generic properties of matrices, and thus the concept of ‘less matrix, less function’ may not be severely damaged. The Hub field has a form

{ list of fields }

and is located between Hub and Stem. A few rules for Hub field are

(1) the first field must be the same as the dependent variable in DE.(2) other fields are matrices the dimensions of which must agree with the grid size.(3) fields behave as scalar variables inside Stem.

18

Page 19: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Using the above-described concept of Hub field, we rewrite the Cemmath commands as

%> Hub field approach #> x = (0,2).span(5);;#> bvp[x] ( (1+x)*{u''}+exp(x)*{u'}+(1+sin(x))*{u} = -cos(x), [ {u} = 0, {u} = 0 ] ) .plot(u);

#> bvp[x] { u, mx = 1+x, cx = exp(x), kx = 1+sin(x), fx = -cos(x) } ( mx*{u''}+cx*{u'}+kx*{u} = fx, [ {u} = 0, {u} = 0 ] ) .plot+(u); #> mx; cx; kx; fx; u;

In the above, variables x, mx, cx, kx and fx are all matrices of 1 ×5 dimension. But matrix u is of 5×2 dimension, since [ u, u' ] are contained in this example, as can be seen below.

mx = [ 1 1.5 2 2.5 3 ] cx = [ 1 1.6487 2.7183 4.4817 7.3891 ] kx = [ 1 1.4794 1.8415 1.9975 1.9093 ] fx = [ -1 -0.87758 -0.5403 -0.070737 0.41615 ] u =

[ 0 0.63837 ] [ 0.1698 0.040847 ]

[ 0.13308 -0.18774 ] [ 0.047049 -0.15639 ]

[ 0 -0.031802 ]

There is a slight difference between the ‘less matrix, less functios’ approach and Hub field approach. Umbrella ‘bvp’ discretizes DE at the mid-point x i+1 / 2 between two grids x i and x i+1. When ‘less matrix, less function’ approach is used, the function value at x i+1 / 2 is evaluated from the prescribed function. However, Hub field approach uses a mean value from matrix data. Unless the grid size is sufficient, these two approaches may entail significant differences in results. Figure 14 illustrates such a behavior, when the grid size is

19

Page 20: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

n=5. A usefulness of Hub field arises when one wants to assign the initial guess for steady problems, or the initial condition for transient problems, as can be seen later.

Figure 14 ‘less matrix’ approach and Hub field approach

Section 7-7 Conservative Form and Eigenvalue BVPs

■ Conservative Form. Conservative forms are encountered frequently in BVPs, and the most famous one would be the Sturm-Liouville equation written as

ddx ( p ( x ) dy

dx )+ [q ( x )+ λw (x ) ] y=0

In Cemmath, the syntax for the conservative term reads

\{ ( p ) y '\}'= ddx (p (x ) dy

dx )\{ ( p ) y ' '\}'= d

dx (p ( x ) d2 yd x2 )

\{ ( p ) y '''\}'= ddx ( p ( x ) d3 y

d x3 )and the conservative term must be the highest term in DE. There can be only three conservative terms since ‘bvp’ treats 2nd, 3rd and 4th-order BVPs.

20

Page 21: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

When a BVP is expressed in conservative form, it is natural to solve it via conservative discretization. An example is

( x2 y ' ¿ '+x2 y=0 , y ( π / 2 )=2π

, y ( π )=0 , yex=sin x

x

and the corresponding Cemmath commands are

%> conservative form #> x = (pi/2,pi).span(21);;#> bvp[x] ( {(x*x)y'}' + x*x*{y} = 0, [ {y} = 2/pi, {y} = 0 ] ) .peep .plot(y, sin(x)/x);

Note that prime ' appears outside of the conservative form. Numerical results are shown in Figure 15.

Figure 15 Conservative form of BVP

■ Eigenvalues of BVPs. Much like the Sturm-Liouville equations, some of BVPs can be characterized by eigenvalue BVP for which a non-trivial solution is possible only for certain eigenvalues. Of course, eigenvalue BVP must be homogeneous in both DE and BCs. Eigenvalue BVPs always contain a parameter, say . Although there exist an infinite number of eigenvalues, only finite number of eigenvalues can be obtained and this is an intrinsic nature of numerical procedure. However, by applying the shift theorem, large eigenvalues

21

Page 22: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

can be successively obtained until truncation effect becomes of importance.

The syntax for eigenvalue BVP is

// DE : ... +{%f} = 0 // must be homogeneous

This means that the term containing eigenvalue is denoted by ‘+{%f}’ which conceptually replaces the term λf . The plus sign is recommended in front of the eigenvalue term ‘{%f}’. As an example, let us find the smallest eigenvalue of the following eigenvalue BVP

0 ≤ x≤ π , y ''+ λy=0 , y (0 )= y ' (0 ) , y ( π )=0by

%> eigenvalue BVP #> lam1 = bvp.x[101](0,pi) ( {y''} + {%y} = 0, [ {y}-{y'}=0, {y}=0 ] ) .plot;#> lam1;

The subsequent result λ1=0.6214 agrees well withλ1ex=0.620373, and can be

further improved by increasing the grid size (the default value was 101). Higher eigenvalues can be found by applying the shift theorem. By using Spoke ‘shift’, a new eigenvalue closest to the shifted value can be obtained. For example,

#> lam2 = bvp.x[101](0,pi)( {y''} + {%y}=0, [ {y}-{y'}=0, {y}=0 ] ).shift(2).plot+;#> lam2;

yields the second smallest eigenvalue λ2=2.8039 which is closest to the shift value 2. Figure 16 shows the eigenvectors corresponding to the first and second smallest eigenvalues, respectively.

22

Page 23: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Figure 16 Eigenvectors for the first and second smallest eigenvalues

The next example is from the bending of a beam written as

d2

d x2 (EI d2 fd x2 )=ω2 mf ( x ) , EI

m=1000 , L=8

f (0 )=f ' (0 )=0 , f '' ( L )=f ''' ( L )=0

This can be solved by

%> Vibration of beam, eigenvalue BVP #> x = (0,8).span(101);; #> lam = bvp [x] ( -1000*{f''''} + {%f} = 0, [ {f} = 0, {f'} = 0, {f''} = 0, {f'''} = 0 ] ) .plot .togo( F = f ); #> F; sqrt(lam); // lam_num^0.5 = 1.7374164, lam_ex^0.5 = 1.737284...

from which ω1=1.7374164 is found to agree well with the exact value

ω1ex=1.737284 …. Figure 17 displays the profile of the corresponding

eigenvector.

23

Page 24: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Figure 17 Eigenvector for the bending of a beam

Section 7-8 System of BVPs

■ Coupled BVPs. Coupled BVPs can be treated by the following syntax

bvp .x[n=101,g=1](a,b) ( DE, [BCs], DE, [BCs], ... )

Each set of DE and BCs must have its own dependent variable, while other dependent variables must be included as a source term. Consider the following system of BVPs

f '''+3 ff ''−2 f '2+θ=0 , θ ''+3 fθ '=0x=0 : f =0 , f '=0 , θ=1

x→ ∞ : f → 0 ,θ → 0

where x∞≅ 8 is assigned for computation. This system can be solved by

%> Data extraction, system of BVPs #> Sol = bvp.x[21](0,8) { f,g } (

{f'''}+3*{ff''}-2*{f'f'} + g = 0, [ {f}=0, {f'}=0, {f}=0 ], {g''}+3*f*{g'} = 0, [ {g}=1, {g}=0 ]

) .peep .plot(f,g) .return(x,f,f',f'',g,g');

#> f; g;

Note that the final results of Hub field are the solution matrices for f and g, i.e.

24

Page 25: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

f = [ f, f', f'' ], g = [ g, g' ]

Also, the matrix Sol is constructed with the full solution fields

Sol = [ x, f, f', f'', g, g' ]

the list of which is

Sol = [ 0 0 0 0.64532 1 -0.5521 ][ 0.4 0.037234 0.18617 0.28554 0.7816 -0.5399 ]

…[ 7.6 0.029812 -0.079661 0.023734 0.00071945 -0.0018147 ][ 8 6.5775e-023 -0.069399 0.027575 0 -0.0017826 ]

f = [ 0 0 0.64532 ][ 0.037234 0.18617 0.28554 ]

…[ 0.029812 -0.079661 0.023734 ][ 6.5775e-023 -0.069399 0.027575 ]

g = [ 1 -0.5521 ][ 0.7816 -0.5399 ]

…[ 0.00071945 -0.0018147 ][ 0 -0.0017826 ]

The numerical results for f and g are shown in Figure 18.

25

Page 26: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Figure 18 System of BVPs

■ Initial Guess and Hub Field. Whenever properly prescribed a priori, the Hub field plays a role of serving as an initial guess. This fact can be utilized in solving complicated system of BVPs. Suppose that two BVPs are so complex that it is not easy to be included in the Stem of ‘bvp’. Then, our strategy is to write two BVPs separately and iterate consecutively the solutions.

For instance, if the example in Figure 18 is solved twice with Hub field, the iteration count for the second trial will be small, since converged solutions are again used as new initial guesses. This can be confirmed by the following commands.

%> initial guess and Hub field #> x = (0,8).span(21);;#> bvp[x] { f,g } ( {f'''}+3*{ff''}-2*{f'f'} + g = 0, [ {f} = 0, {f'} = 0, {f} = 0 ], {g''}+3*f*{g'} = 0, [ {g} = 1, {g} = 0 ] ) .peep; %> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #> bvp[x] { f,g } ( {f'''}+3*{ff''}-2*{f'f'} + g = 0, [ {f} = 0, {f'} = 0, {f} = 0 ], {g''}+3*f*{g'} = 0, [ {g} = 1, {g} = 0 ] ) .peep;

Readers can confirm that the first trial requires 21 iterations while the second trial with converged solutions requires 1 iteration (at least one iteration is automatically performed).

Under certain conditions, proper description of initial guesses are crucial in obtaining solutions. Bad guesses may fail to obtain converged solutions. Also, proper under-relaxation is important for heavily nonlinear systems. Let us consider

f '''+ f ' f '−2 f cos x−g cos2 x=sin2 x−3sin x−x cos x+4 x cos2 x

26

Page 27: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

g ''+g 'sin x−2 f =2−4 sin x

x=0 : f =0 , f '=0 , g=0x=1 : f =sin (1 ) , g '=−2

where exact solutions are f =x sin x , g=x2−4 x. The initial guesses are constructed to satisfy the given boundary conditions

f =x2sin (1 ) , g=−2 x

Then, the commands are written as follows.

%> system of BVPs (well-devised initial guess #> bvp.x[101](0,1) { f = x*x*sin(1), g = -2*x } (

{f'''}+{f'f'}-2*cos(x)*{f}-cos(x)^2*g = sin(x)^2-3*sin(x)-x*cos(x)+4*x*cos(x)^2, [ {f}=0, {f'}=0, {f}=sin(1) ],

{g''}+sin(x)*{g'} -2*f = 2-4*sin(x), [ {g}=0, {g'}=-2 ] ) .peep .relax(0.5) .maxiter(500)

.plot(f,g, x*sin(x),x*x-4*x);

Figure 19 shows the converged solutions and compares with the exact solutions. When one fails to get converged solutions, it is recommended to describe proper initial guesses, and to reduce under-relaxation factor.

Figure 19 Coupled BVPs with initial guesses

27

Page 28: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Section 7-9 Summary of Syntax

To aid understanding, the syntax is explained for specific cases, if possible.

■ DE

cz*{f''''} +cw*{f'''} +cfw*{ff'''} +cuw*{f'f'''} + cvw*{f''f'''} +

cww*{f'''f'''}+cv*{f''} +cfv*{ff''} +cuv*{f'f''} + cvv*{f''f''} +cu*{f'} +cfu*{ff'} +cuu*{f'f'} +cf*{f} +cff*{ff} = cs

■ BCs

bw*{f'''} + bv*{f''} + bu*{f'} + bf*{f} = bs

■ Hub and Stem

bvp .x[n=101,g=1](a,b) ( DE, [ BCs ] );

bvp .x[n=101,g=1](a,b) ( {y''}+{y}=0, [ {y}=0, {y'}-{y}=0 ] );bvp .x[n=101,g=1](a,b) ( {y'''}+0.5*{yy''} = 0, [ {y}=0,{y'}=0,{y'}=1 ] );bvp .x[n=101,g=1](a,b) ( {y''''}+{y} = 0, [ {y}=0,{y'}=0,{y}=1,{y'}=0 ] );

x=(a,b).span(n,g=1);bvp [x](a,b) ( {y''}+{y}=0, [ {y}=0, {y'}-{y}=0 ] );bvp [x](a,b) ( {y'''}+0.5*{yy''} = 0, [ {y}=0,{y'}=0,{y'}=1 ] );bvp [x](a,b) ( {y''''}+{y} = 0, [ {y}=0,{y'}=0,{y}=1,{y'}=0 ] );

■ Hub field

bvp .x[n=101,g=1](a,b) { y=y(x), f,g,… } ( {y''}+{y}=0, [ {y}=0, {y'}-{y}=0 ] );bvp .x[n=101,g=1](a,b) { y=[y,y'], f,g,… } ( {y''}+{y}=0, [ {y}=0, {y'}-{y}=0 ] );

■ Conservative Form

28

Page 29: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

{(p)y'}' {(p)y''}' {(p)y'''}'

■ Eigenvalue BVP

bvp .x[n=101,g=1](a,b) ( {y''}+{%y}=0, [ {y}=0, {y'}-{y}=0 ] );bvp .x[n=101,g=1](a,b) ( {y''}+{%y}=0, [ {y}=0, {y'}-{y}=0 ] ).shift(s);bvp .x[n=101,g=1](a,b) (

-1000*{f''''} + {%f} = 0, [ {f}=0, {f'}=0, {f''}=0, {f'''}=0 ] );

■ System of BVP

bvp .x[n=101,g=1](a,b) ( DE, [ BCs ], DE, [BCs], … );

bvp .x[n=101,g=1](a,b) { f,g } ( {f'''}+3*{ff''}-2*{f'f'}+g=0, [ {f}=0, {f'}=0, {f}=0 ],

{g''}+3*f*{g'}=0, [ {g}=1, {g}=0 ])

■ Several Spokes

.peep // peep the iteration procedure .relax(relax=0.5) // under-relaxation factor .tol/abstol(abstol=1.e-5) // absolute tolerance .reltol(reltol=1.e-5) // relative tolerance .maxiter(maxiter=500) // maximum iteration count

.shift(s) // eigenvalue shift

.plot // plot default data .plot(f,f',f'',...) // plot user-defined data

.return(f,f',f'',...) // return user-defined data

.togo(Y=y,Y1=y',...) // takeout each field

The following spokes will be discussed in Chapter 8

.plot2[n=5,g=1](f,f',…) // plot 2D curves for initial BVPs

.plot [n=5,g=1](f,f',…) // plot 3D surface for initial BVPs

Section 7-10 References

[1] MATLAB(R) 7, Mathematics, The MathWorks Inc. (2009).

[2] H.B. Wilson, L.H. Turcotte, Advanced Mathematics and Mechanics

29

Page 30: Web viewOne thing worthy of note is that the dimensionless shear at the wall, i.e. f''(x=0) is directly obtained by use of Spoke ‘return(f'')(1)’

[100] 007 Chapter 7 Boundary Value Problems, Tutorial by www.msharpmath.com

Applications Using MATLAB, 2ed., CRC Press (1997).

[3] D.J. Higham and N.J. Higham, MATLAB(R) Program GuideBook, 2ed., SIAM (2005).

30