Solution of a nonlinear BVP by Newton`s method

advertisement
Solution of a nonlinear BVP by Newton’s method
We’ll solve the equation
u’’ = 16 u2 + x2 + 1
with boundary conditions
uH0L = uH1L = 0.
The Galerkin weak problem is
1
2
2
1
Ù0 Av’ u’ + 16 v u + v + v x E â x = 0 " v Î H0 .
This is nonlinear so we linearize. The weak problem for the Newton step w is
2
1
HnL
HnL
HnL
2
Ù0 Bv’ w’ + 32 v u w + v’ Iu M’ + 16 v Iu M + v + v x F â x
= 0 " v Î H01
Ÿ Define a basis
In[2]:=
M = 2;
In[3]:=
Φ@x_D = Table@Sin@n Pi xD, 8n, 1, M<D
Out[3]=
8sinHΠ xL, sinH2 Π xL<
Ÿ Write a function that evaluates the current step
Let uHnL
j , j = 1, 2, ..., M be the coefficients of the basis functions.
HnL
uHnL HxL = ÚM
j=1 u j Φ j HxL
In[4]:=
uSum@uCoeff_, x_D := Sum@uCoeff@@iDD Φ@xD@@iDD, 8i, 1, M<D
Ÿ Form the residual and Jacobian
The residual elements are
1
2
bi = Ù0 BΦi ’ IuHnL HxLM’ + 16 Φi IuHnL HxLM + Φi + x2 Φi F â x
In[5]:=
b@uCoeff_D := Table@Integrate@
D@uSum@uCoeff, xD, xD Φ ’@xD@@iDD + x ^ 2 Φ@xD@@iDD + Φ@xD@@iDD
+ 16 Φ@xD@@iDD uSum@uCoeff, xD ^ 2 ,
8x, 0, 1<D, 8i, 1, M<D
The Jacobian matrix elements are
1
Ji j = Ù0 AΦi ’ Φ j ’ + 32 Φi Φ j uHnL HxLE â x
2
NewtonGalerkin.nb
In[6]:=
J@uCoeff_D := Table@
Integrate@Φ ’@xD@@iDD Φ ’@xD@@jDD
+ 32 Φ@xD@@iDD uSum@uCoeff, xD Φ@xD@@jDD,
8x, 0, 1<D,
8i, 1, M<, 8j, 1, M<D
Ÿ Write a function that does a single Newton step
The Newton step is
uHn+1L = uHnL - J -1 IuHnL M bIuHnL M
In[7]:=
newtStep@u0_D := Block@
8Jac = J@u0D, resid = Chop@b@u0DD<,
Print@"u=", u0D;
Print@"J=", JacD;
Print@"resid=", residD;
u0 + LinearSolve@N@JacD, -residD
D
Ÿ Get an accurate solution for comparison
Exact solution is impossible, so use NDSolve to get a very good approximation.
In[8]:=
Out[8]=
uEx@x_D = u@xD . NDSolve@8u ’’@xD Š 16 u@xD ^ 2 + x ^ 2 + 1, u@0D Š 0, u@1D Š 0<, u@xD, xD@@1DD
InterpolatingFunction@H 0. 1. L, <>D@xD
Ÿ Run several Newton steps
Instead of doing a careful convergence test we’ll just do a few steps.
In[9]:=
nSteps = 6;
Use a vector of zeros as the initial guess.
In[10]:=
guess = Table@0, 8M<D;
Use NestList to run several steps, with the output from each step used as the input to the next step. We’ll print
the residual vector and Jacobian at each step.
In[11]:=
newtTab = NestList@newtStep, guess, nStepsD
NewtonGalerkin.nb
u=80, 0<
2
ij Π€€€€€€€
J=jjjj 2
j
k0
yz
zz
zzz
2
2Π {
0
-4 + 3 Π2
1
resid=: €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ , - €€€€€€€€€€€ >
2Π
Π3
u=8-0.167367, 0.00806288<
i 2.66175 0.087603 yz
J=jj
z
k 0.087603 17.9208 {
resid=80.19057, -0.0146619<
u=8-0.239001, 0.00923121<
i 1.68887 0.100297 yz
J=jj
z
k 0.100297 17.1425 {
resid=80.0348531, -0.000909309<
u=8-0.259648, 0.00940505<
i 1.40846 0.102186 zy
J=jj
z
k 0.102186 16.9181 {
resid=80.00289505, -0.0000389993<
u=8-0.261705, 0.00941978<
i 1.38053 0.102346 yz
J=jj
z
k 0.102346 16.8958 {
-7
resid=90.0000287212, -3.29059 ´ 10 =
u=8-0.261726, 0.00941993<
i 1.38025 0.102347 yz
J=jj
z
k 0.102347 16.8956 {
-9
resid=92.94234 ´ 10 , 0=
Out[11]=
ij 0
jj
jj -0.167367
jj
jj
jjj -0.239001
jj
jj -0.259648
jj
jj
jjj -0.261705
jj
jj -0.261726
jj
j
k -0.261726
0
0.00806288
0.00923121
0.00940505
0.00941978
0.00941993
0.00941993
yz
zz
zz
zz
zz
zz
zz
zz
zz
zz
zz
zz
zz
zz
zz
z
{
The n-th row of this list is the vector of coefficients uHnL obtained by the n-th Newton step. As you can see, the
sequence of iterations converges very quickly.
Ÿ Plot the last Newton step
Let’s look at the final step, compared to the "exact" solution
In[12]:=
Out[12]=
uNewt@x_D = uSum@Last@newtTabD, xD
0.00941993 sinH2 Π xL - 0.261726 sinHΠ xL
3
4
NewtonGalerkin.nb
In[13]:=
Plot@8uEx@xD, uNewt@xD<, 8x, 0, 1<D
0.2
0.4
0.6
0.8
1.0
-0.05
-0.10
Out[13]=
-0.15
-0.20
-0.25
Ÿ Plot the sequence of Newton approximations
In[14]:=
Out[14]=
In[15]:=
uNewtSequence@x_D = Map@uSum@ð, xD &, newtTabD
80, 0.00806288 sinH2 Π xL - 0.167367 sinHΠ xL, 0.00923121 sinH2 Π xL - 0.239001 sinHΠ xL, 0.00940505 sinH2 Π xL - 0.259648 sinHΠ xL,
0.00941978 sinH2 Π xL - 0.261705 sinHΠ xL, 0.00941993 sinH2 Π xL - 0.261726 sinHΠ xL, 0.00941993 sinH2 Π xL - 0.261726 sinHΠ xL<
Plot@uNewtSequence@xD, 8x, 0, 1<D
0.2
-0.05
-0.10
Out[15]=
-0.15
-0.20
-0.25
0.4
0.6
0.8
1.0
Download