1. [Thomas Problem 1.2.1] Write a code to approximately solve the boundary value problem

\{ \begin{matrix}v_{t} & = νv_{xx}, x ∈ (0, 1), t > 0 \\ v(x, 0) & = f(x), x ∈ [0, 1] \\ v(0, t) & = a(t), t ≥ 0 \\ v(1, t) & = b(t), t ≥ 0 \end{matrix}

Use f(x) = sin 2πx, a(t) = b(t) = 0, K = 10 and ν = 1/6. Find solutions at t = 0.06, t = 0.1, t = 0.9 and t = 50.0. For the first three values of t, use Δt = 0.02. To speed the solution of the last value of t, you might use a larger value for Δt. Determine how large you can choose Δt and still get results that might still be correct. Compare and contrast your solutions to the exact solutions.

We compute the exact solution using separation of variables. First look for eigenfunctions X(x) of the operator ∂^{2}/∂x^{2} such that X(0) = X(1) = 0. Solving

X′′(x) = λX(x)

yields

X(x) = A exp(\sqrt{λ}x) + B exp(−\sqrt{λ}x).

Now X(0) = 0 implies B = −A so that

X(t) = A exp(\sqrt{λ}x) − A exp(−\sqrt{λ}x),

and on the other hand X(1) = 0 implies exp(\sqrt{λ}) = exp(−\sqrt{λ}). Therefore exp(2\sqrt{λ}) = 1 implies 2\sqrt{λ} = 2nπi and we obtain eigenfunctions X_{n}(x) with eigenvalues λ_{n} given by

X_{n}(x) = sin(nπx)  and  λ_{n} = −n^{2}π^{2}  for  n ∈ N.

Consider a solution of the form

v(x, t) = ∑_{n∈N} T_{n}(t)X_{n}(x).

Plugging this into the differential equation obtains

∑_{n∈N} T′_{n}(t)X_{n}(x) = ∑_{n∈N} νλ_{n}T_{n}(t)X_{n}(x)

and since the eigenfunctions X_{n}(x) are linearly independent, it follows that

T′_{n}(t) = νλ_{n}T_{n}(t)  for all  n ∈ N.

Solving this system yields that T_{n}(t) = T_{n}(0) exp(−νn^{2}π^{2}t) and consequently

v(x, t) = ∑_{n∈N} T_{n}(0) exp(−νn^{2}π^{2}t) sin(nπx).

The initial condition

v(x, 0) = ∑_{n∈N} T_{n}(0) sin(nπx) = f(x) = sin(2πx)

implies

T_{n}(0) = \{ \begin{matrix}1 & if n = 2, \\ 0 & otherwise. \end{matrix}

Therefore, the exact solution is

v(x, t) = exp(−ν4π^{2}t) sin(2πx).

We use the finite difference scheme

u_{k}^{n+1} = u_{k}^{n} + ρδ^{2}u_{k}^{n} for n = 0, …, N − 1 and k = 1, …, K − 1
u_{k}^{0} = f(x_{k})  for k = 0, …, K
u_{0}^{n} = a(t_{n})  for n = 1, …, N
u_{K}^{n} = b(t_{n})  for n = 1, …, N

where x_{k} = kΔx, t_{n} = nΔt, Δx = 1/K, Δt = T/N and ρ = νΔt/Δx^{2}. We chose the values of K, N and T given in the table

\begin{matrix}K & N & T & Δx & Δt & ρ \\ 10 & 3 & 0.06 & 0.1 & 0.02 & 0.333333 \\ 10 & 5 & 0.1 & 0.1 & 0.02 & 0.333333 \\ 10 & 45 & 0.9 & 0.1 & 0.02 & 0.333333 \\ 10 & 2000 & 50 & 0.1 & 0.025 & 0.416667 \\ 10 & 1750 & 50 & 0.1 & 0.0285714 & 0.47619 \\ 10 & 1500 & 50 & 0.1 & 0.0333333 & 0.555556 \end{matrix}

In the following program, and all other programs included in this homework assignment, the output will be displayed in four columns. This output describes the approximation obtained by the numerical scheme, the exact solution and the error between the approximation and the exact solution. Specifically we have

1. The column xk gives the value of x_{k}.

2. The column uk gives the approximation u_{k}^{N} for v(x_{k}, T).

3. The column vk gives the exact value of v(x_{k}, T).

4. The column vk-uk gives the error u_{k}^{N} − v(x_{k}, T).

The program is

   1 /*  prog1.c -- Thomas Problem 1.2.1
   2  Written May 2013 by Eric Olson */

3

   4 #include <stdio.h>
   5 #include <math.h>

 6 #define NU (1.0/6.0)

7

 8 double dt,dx,rho;

9

10 double v(double x,double t){
11  return exp(-NU*4*M_PI*M_PI*t)*sin(2*M_PI*x);

12 }

13 double f(double x){
14  return sin(2*M_PI*x);

15 }

16 double a(double x){
17  return 0.0;

18 }

19 double b(double x){
20  return 0.0;

21 }

22 void doinit(int K,double u[K+1]){
23  int k;
24  for(k=0;k<=K;k++){
25  double xk=k*dx;
26  u[k]=f(xk);

27 } 28 }

29 void doprint(int K,double u[K+1],double tn){
30  int k;
31  printf("#%4s %23s %23s %23s\n","xk","uk","vk","uk-vk");
32  for(k=0;k<=K;k++){
33  double xk=k*dx;
34  double vk=v(xk,tn);
35  printf("%5g %23.14e %23.14e %23.14e\n",xk,u[k],vk,u[k]-vk);

36 } 37 }

38 void dosolve(int K,double u[K+1],int N,double T){
39  int n;
40  for(n=0;;n++){
41  double tn=n*dt;
42  u[0]=a(tn); u[K]=b(tn);
43  if(n>=N) break;
44  int k;
45  double w[K+1];
46  for(k=1;k<K;k++) w[k]=u[k-1]-2*u[k]+u[k+1];
47  for(k=1;k<K;k++) u[k]+=rho*w[k];

48 } 49 }

50 main(){

51  printf("# prog1 -- Thomas Problem 1.2.1\n"
52  "# Written May 2013 by Eric Olson\n#\n");
53  int KK[]={10,10,10,10,10,10};
54  int NN[]={3,5,45,2000,1750,1500};
55  double TT[]={0.06,0.1,0.9,50,50,50};
56  int J=sizeof(TT)/sizeof(double);
57  int j;
58  for(j=0;j<J;j++){
59  int K=KK[j],N=NN[j];
60  double T=TT[j],u[K+1];
61  dx=1.0/K; dt=T/N;
62  rho=NU*dt/dx/dx;
63  printf("#\tK=%d N=%d T=%g\n"
64  "#\tdx=%g dt=%g rho=%g\n",
65  K,N,T,dx,dt,rho);
66  doinit(K,u);
67  dosolve(K,u,N,T);
68  doprint(K,u,T);
69  printf("\n\n");

70 }

71  return 0;

72 }

The output is

# prog1 -- Thomas Problem 1.2.1
# Written May 2013 by Eric Olson
#
# K=10 N=3 T=0.06
# dx=0.1 dt=0.02 rho=0.333333
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.90643644141615e-01    3.96064662853158e-01   -5.42101871154310e-03
0.2    6.32074693710251e-01    6.40846086239177e-01   -8.77139252892589e-03
0.3    6.32074693710251e-01    6.40846086239177e-01   -8.77139252892589e-03
0.4    3.90643644141615e-01    3.96064662853158e-01   -5.42101871154316e-03
0.5    1.27574455629128e-17    8.25170928945244e-17   -6.97596473316116e-17
0.6   -3.90643644141615e-01   -3.96064662853158e-01    5.42101871154332e-03
0.7   -6.32074693710251e-01   -6.40846086239177e-01    8.77139252892589e-03
0.8   -6.32074693710251e-01   -6.40846086239177e-01    8.77139252892600e-03
0.9   -3.90643644141615e-01   -3.96064662853158e-01    5.42101871154316e-03
  1    0.00000000000000e+00   -1.65034185789049e-16    1.65034185789049e-16

# K=10 N=5 T=0.1
# dx=0.1 dt=0.02 rho=0.333333
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    2.97501263268220e-01    3.04413823505703e-01   -6.91256023748293e-03
0.2    4.81367155664011e-01    4.92551913077540e-01   -1.11847574135285e-02
0.3    4.81367155664011e-01    4.92551913077540e-01   -1.11847574135284e-02

0.4    2.97501263268220e-01    3.04413823505703e-01   -6.91256023748299e-03
0.5    7.58941520739856e-18    6.34223300095584e-17   -5.58329148021599e-17
0.6   -2.97501263268220e-01   -3.04413823505703e-01    6.91256023748310e-03
0.7   -4.81367155664011e-01   -4.92551913077540e-01    1.11847574135284e-02
0.8   -4.81367155664011e-01   -4.92551913077540e-01    1.11847574135285e-02
0.9   -2.97501263268220e-01   -3.04413823505703e-01    6.91256023748299e-03
  1    0.00000000000000e+00   -1.26844660019117e-16    1.26844660019117e-16

# K=10 N=45 T=0.9
# dx=0.1 dt=0.02 rho=0.333333
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    1.28129710652919e-03    1.57554150100023e-03   -2.94244394471033e-04
0.2    2.07318226805113e-03    2.54927969930439e-03   -4.76097431253263e-04
0.3    2.07318226805113e-03    2.54927969930439e-03   -4.76097431253263e-04
0.4    1.28129710652919e-03    1.57554150100023e-03   -2.94244394471033e-04
0.5    2.62738974131952e-32    3.28252218869158e-19   -3.28252218869132e-19
0.6   -1.28129710652919e-03   -1.57554150100023e-03    2.94244394471034e-04
0.7   -2.07318226805113e-03   -2.54927969930439e-03    4.76097431253263e-04
0.8   -2.07318226805113e-03   -2.54927969930439e-03    4.76097431253263e-04
0.9   -1.28129710652919e-03   -1.57554150100023e-03    2.94244394471033e-04
  1    0.00000000000000e+00   -6.56504437738316e-19    6.56504437738316e-19

# K=10 N=2000 T=50
# dx=0.1 dt=0.025 rho=0.416667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1   1.59841078802718e-151   7.79939687131992e-144  -7.79939671147884e-144
0.2   2.58628298301247e-151   1.26196892295452e-143  -1.26196889709169e-143
0.3   2.58628298301247e-151   1.26196892295452e-143  -1.26196889709169e-143
0.4   1.59841078802718e-151   7.79939687131992e-144  -7.79939671147884e-144
0.5   1.42629035223595e-171   1.62494566295247e-159  -1.62494566295104e-159
0.6  -1.59841078802718e-151  -7.79939687131993e-144   7.79939671147885e-144
0.7  -2.58628298301247e-151  -1.26196892295452e-143   1.26196889709169e-143
0.8  -2.58628298301247e-151  -1.26196892295452e-143   1.26196889709169e-143
0.9  -1.59841078802718e-151  -7.79939687131992e-144   7.79939671147885e-144
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

# K=10 N=1750 T=50
# dx=0.1 dt=0.0285714 rho=0.47619
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1   -2.10725407775984e-54   7.79939687131992e-144   -2.10725407775984e-54
0.2   -4.00823544428607e-54   1.26196892295452e-143   -4.00823544428607e-54
0.3   -5.51686279850709e-54   1.26196892295452e-143   -5.51686279850709e-54
0.4   -6.48546118376690e-54   7.79939687131992e-144   -6.48546118376690e-54
0.5   -6.81921744149448e-54   1.62494566295247e-159   -6.81921744149448e-54
0.6   -6.48546118376690e-54  -7.79939687131993e-144   -6.48546118376690e-54
0.7   -5.51686279850709e-54  -1.26196892295452e-143   -5.51686279850709e-54
0.8   -4.00823544428607e-54  -1.26196892295452e-143   -4.00823544428607e-54
0.9   -2.10725407775984e-54  -7.79939687131992e-144   -2.10725407775984e-54
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

# K=10 N=1500 T=50
# dx=0.1 dt=0.0333333 rho=0.555556
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    1.21019810833957e+84   7.79939687131992e-144    1.21019810833957e+84
0.2   -2.30193359388883e+84   1.26196892295452e-143   -2.30193359388883e+84
0.3    3.16833978075383e+84   1.26196892295452e-143    3.16833978075383e+84
0.4   -3.72460679475733e+84   7.79939687131992e-144   -3.72460679475733e+84
0.5    3.91628334482851e+84   1.62494566295247e-159    3.91628334482851e+84
0.6   -3.72460679475733e+84  -7.79939687131993e-144   -3.72460679475733e+84
0.7    3.16833978075383e+84  -1.26196892295452e-143    3.16833978075383e+84
0.8   -2.30193359388883e+84  -1.26196892295452e-143   -2.30193359388883e+84
0.9    1.21019810833957e+84  -7.79939687131992e-144    1.21019810833957e+84
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

Note that the last computation is clearly wrong because rather than decaying, the solution increases. In general, the scheme is unstable and therefore unreliable when ρ > 1/2.

2. [Thomas Problem 1.3.1] Solve Problem 1.2.1 using the leapfrog scheme

u_{k}^{n+1} = u_{k}^{n−1} + \frac{2νΔt}{Δx^{2}}(u_{k+1}^{n} − 2u_{k}^{n} + u_{k−1}^{n})

with Δt = 0.02. For convenience, use values from the exact solution at Δt to get the leapfrog scheme started.

The program is

 1 /*  prog2.c -- Thomas Problem 1.3.1
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #define NU (1.0/6.0)

7

 8 double dt,dx,rho;

9

10 double v(double x,double t){
11  return exp(-NU*4*M_PI*M_PI*t)*sin(2*M_PI*x);

12 }

13 double a(double x){
14  return 0.0;

15 }

16 double b(double x){
17  return 0.0;

18 }

19 void doinit(int K,double u[2][K+1]){
20  int n;
21  for(n=0;n<2;n++){
22  int k;
23  for(k=0;k<=K;k++){
24  double xk=k*dx, tn=n*dt;
25  u[n][k]=v(xk,tn);

26 } 27 } 28 }

29 void doprint(int K,double u[K+1],double tn){
30  int k;
31  printf("#%4s %23s %23s %23s\n","xk","uk","vk","uk-vk");
32  for(k=0;k<=K;k++){
33  double xk=k*dx;
34  double vk=v(xk,tn);
35  printf("%5g %23.14e %23.14e %23.14e\n",xk,u[k],vk,u[k]-vk);

36 } 37 }

38 void dosolve(int K,double u[2][K+1],int N,double T){
39  int n;
40  for(n=1;;n++){
41  double tn=n*dt;
42  u[1][0]=a(tn); u[1][K]=b(tn);
43  if(n>=N) break;
44  int k;
45  double w[K+1];
46  for(k=1;k<K;k++) w[k]=u[1][k-1]-2*u[1][k]+u[1][k+1];
47  for(k=1;k<K;k++) {
48  double tmp=u[1][k];
49  u[1][k]=u[0][k]+rho*w[k];
50  u[0][k]=tmp;

51 }

52  u[0][0]=u[1][0]; u[0][K]=u[1][K];

53 } 54 }

55 main(){
56  printf("# prog2 -- Thomas Problem 1.3.1\n"
57  "# Written May 2013 by Eric Olson\n#\n");
58  int KK[]={10,10,10,10};
59  int NN[]={3,5,45,2500};
60  double TT[]={0.06,0.1,0.9,50};
61  int J=sizeof(TT)/sizeof(double);
62  int j;
63  for(j=0;j<J;j++){
64  int K=KK[j],N=NN[j];
65  double T=TT[j],u[2][K+1];
66  dx=1.0/K; dt=T/N;
67  rho=2*NU*dt/dx/dx;
68  printf("#\tK=%d N=%d T=%g\n"
69  "#\tdx=%g dt=%g rho=%g\n",
70  K,N,T,dx,dt,rho);
71  doinit(K,u);
72  dosolve(K,u,N,T);
73  doprint(K,u[1],T);
74  printf("\n\n");

75 }

76  return 0;

77 }

The output is

   # prog2 -- Thomas Problem 1.3.1
   # Written May 2013 by Eric Olson
   #
   # K=10 N=3 T=0.06

# dx=0.1 dt=0.02 rho=0.666667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.99047602882670e-01    3.96064662853158e-01    2.98294002951238e-03
0.2    6.45672584593332e-01    6.40846086239177e-01    4.82649835415450e-03
0.3    6.45672584593331e-01    6.40846086239177e-01    4.82649835415372e-03
0.4    3.99047602882670e-01    3.96064662853158e-01    2.98294002951266e-03
0.5    3.44656492339396e-16    8.25170928945244e-17    2.62139399444871e-16
0.6   -3.99047602882671e-01   -3.96064662853158e-01   -2.98294002951299e-03
0.7   -6.45672584593331e-01   -6.40846086239177e-01   -4.82649835415372e-03
0.8   -6.45672584593331e-01   -6.40846086239177e-01   -4.82649835415405e-03
0.9   -3.99047602882671e-01   -3.96064662853158e-01   -2.98294002951272e-03
  1    0.00000000000000e+00   -1.65034185789049e-16    1.65034185789049e-16

# K=10 N=5 T=0.1
# dx=0.1 dt=0.02 rho=0.666667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.08661764863157e-01    3.04413823505703e-01    4.24794135745360e-03
0.2    4.99425226576122e-01    4.92551913077540e-01    6.87331349858250e-03
0.3    4.99425226576117e-01    4.92551913077540e-01    6.87331349857701e-03
0.4    3.08661764863159e-01    3.04413823505703e-01    4.24794135745582e-03
0.5    2.25554475130889e-15    6.34223300095584e-17    2.19212242129933e-15
0.6   -3.08661764863162e-01   -3.04413823505703e-01   -4.24794135745893e-03
0.7   -4.99425226576116e-01   -4.92551913077540e-01   -6.87331349857678e-03
0.8   -4.99425226576120e-01   -4.92551913077540e-01   -6.87331349858034e-03
0.9   -3.08661764863159e-01   -3.04413823505703e-01   -4.24794135745582e-03
  1    0.00000000000000e+00   -1.26844660019117e-16    1.26844660019117e-16

# K=10 N=45 T=0.9
# dx=0.1 dt=0.02 rho=0.666667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    4.61343688561026e+02    1.57554150100023e-03    4.61342113019525e+02
0.2   -1.09542685827749e+03    2.54927969930439e-03   -1.09542940755719e+03
0.3    1.96646303659455e+03    2.54927969930439e-03    1.96646048731485e+03
0.4   -2.98546825065064e+03    1.57554150100023e-03   -2.98546982619214e+03
0.5    3.91067459871360e+03    3.28252218869158e-19    3.91067459871360e+03
0.6   -4.44089303435913e+03   -1.57554150100023e-03   -4.44089145881763e+03
0.7    4.32364338351472e+03   -2.54927969930439e-03    4.32364593279442e+03
0.8   -3.45023526760994e+03   -2.54927969930439e-03   -3.45023271833024e+03
0.9    1.91808811081291e+03   -1.57554150100023e-03    1.91808968635441e+03
  1    0.00000000000000e+00   -6.56504437738316e-19    6.56504437738316e-19

# K=10 N=2500 T=50
# dx=0.1 dt=0.02 rho=0.666667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1                    -inf   7.79939687131992e-144                    -inf
0.2                     inf   1.26196892295452e-143                     inf
0.3                    -inf   1.26196892295452e-143                    -inf
0.4                     inf   7.79939687131992e-144                     inf

0.5                    -inf   1.62494566295247e-159                    -inf
0.6                     inf  -7.79939687131993e-144                     inf
0.7                    -inf  -1.26196892295452e-143                    -inf
0.8                     inf  -1.26196892295452e-143                     inf
0.9                    -inf  -7.79939687131992e-144                    -inf
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

Note that this method oscillates between ±∞ at T = 50 which is a noticably poor result as the solution is supposed to converge to 0.

3. [Thomas Problem 1.3.2] Use Δt = Δx^{2}/(6ν) for the solution to Problem 1.2.1.

The program is

 1 /*  prog3.c -- Thomas Problem 1.3.2
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #define NU (1.0/6.0)

7

 8 double dt,dx,rho;

9

10 double v(double x,double t){
11  return exp(-NU*4*M_PI*M_PI*t)*sin(2*M_PI*x);

12 }

13 double f(double x){
14  return sin(2*M_PI*x);

15 }

16 double a(double x){
17  return 0.0;

18 }

19 double b(double x){
20  return 0.0;

21 }

22 void doinit(int K,double u[K+1]){
23  int k;
24  for(k=0;k<=K;k++){
25  double xk=k*dx;
26  u[k]=f(xk);

27 } 28 }

29 void doprint(int K,double u[K+1],double tn){
30  int k;
31  printf("#%4s %23s %23s %23s\n","xk","uk","vk","uk-vk");
32  for(k=0;k<=K;k++){
33  double xk=k*dx;
34  double vk=v(xk,tn);
35  printf("%5g %23.14e %23.14e %23.14e\n",xk,u[k],vk,u[k]-vk);

36 } 37 }

38 void dosolve(int K,double u[K+1],int N,double T){
39  int n;
40  for(n=0;;n++){
41  double tn=n*dt;
42  u[0]=a(tn); u[K]=b(tn);

43  if(n>=N) break;
44  int k;
45  double w[K+1];
46  for(k=1;k<K;k++) w[k]=u[k-1]-2*u[k]+u[k+1];
47  for(k=1;k<K;k++) u[k]+=rho*w[k];

48 } 49 }

50 main(){
51  printf("# prog3 -- Thomas Problem 1.3.2\n"
52  "# Written May 2013 by Eric Olson\n#\n");
53  int KK[]={10,10,10,10,10,10};
54  double TT[]={0.06,0.1,0.9,50,50,50};
55  int J=sizeof(TT)/sizeof(double);
56  int NN[J];
57  int j;
58  for(j=0;j<J;j++) NN[j]=KK[j]*KK[j]*TT[j]+0.5;
59  for(j=0;j<J;j++){
60  int K=KK[j],N=NN[j];
61  double T=TT[j],u[K+1];
62  dx=1.0/K; dt=T/N;
63  rho=NU*dt/dx/dx;
64  printf("#\tK=%d N=%d T=%g\n"
65  "#\tdx=%g dt=%g rho=%g\n",
66  K,N,T,dx,dt,rho);
67  doinit(K,u);
68  dosolve(K,u,N,T);
69  doprint(K,u,T);
70  printf("\n\n");

71 }

72  return 0;

73 }

The output is

# prog3 -- Thomas Problem 1.3.2
# Written May 2013 by Eric Olson
#
# K=10 N=6 T=0.06
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.96111414113491e-01    3.96064662853158e-01    4.67512603332665e-05
0.2    6.40921731367413e-01    6.40846086239177e-01    7.56451282361015e-05
0.3    6.40921731367413e-01    6.40846086239177e-01    7.56451282361015e-05
0.4    3.96111414113491e-01    3.96064662853158e-01    4.67512603332110e-05
0.5    4.65755183263568e-18    8.25170928945244e-17   -7.78595410618887e-17
0.6   -3.96111414113491e-01   -3.96064662853158e-01   -4.67512603331555e-05
0.7   -6.40921731367413e-01   -6.40846086239177e-01   -7.56451282362125e-05
0.8   -6.40921731367413e-01   -6.40846086239177e-01   -7.56451282361015e-05

0.9   -3.96111414113491e-01   -3.96064662853158e-01   -4.67512603332110e-05
  1    0.00000000000000e+00   -1.65034185789049e-16    1.65034185789049e-16

# K=10 N=10 T=0.1
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.04473713936096e-01    3.04413823505703e-01    5.98904303928949e-05
0.2    4.92648817829516e-01    4.92551913077540e-01    9.69047519764898e-05
0.3    4.92648817829516e-01    4.92551913077540e-01    9.69047519765454e-05
0.4    3.04473713936096e-01    3.04413823505703e-01    5.98904303928394e-05
0.5   -2.13542652889124e-17    6.34223300095584e-17   -8.47765952984708e-17
0.6   -3.04473713936096e-01   -3.04413823505703e-01   -5.98904303927839e-05
0.7   -4.92648817829516e-01   -4.92551913077540e-01   -9.69047519766564e-05
0.8   -4.92648817829516e-01   -4.92551913077540e-01   -9.69047519766009e-05
0.9   -3.04473713936096e-01   -3.04413823505703e-01   -5.98904303928394e-05
  1    0.00000000000000e+00   -1.26844660019117e-16    1.26844660019117e-16

# K=10 N=90 T=0.9
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    1.57833344829746e-03    1.57554150100023e-03    2.79194729723635e-06
0.2    2.55379716492612e-03    2.54927969930439e-03    4.51746562172553e-06
0.3    2.55379716492611e-03    2.54927969930439e-03    4.51746562172292e-06
0.4    1.57833344829745e-03    1.57554150100023e-03    2.79194729722702e-06
0.5   -1.43150156272752e-17    3.28252218869158e-19   -1.46432678461444e-17
0.6   -1.57833344829748e-03   -1.57554150100023e-03   -2.79194729725391e-06
0.7   -2.55379716492614e-03   -2.54927969930439e-03   -4.51746562174634e-06
0.8   -2.55379716492613e-03   -2.54927969930439e-03   -4.51746562174244e-06
0.9   -1.57833344829747e-03   -1.57554150100023e-03   -2.79194729724480e-06
  1    0.00000000000000e+00   -6.56504437738316e-19    6.56504437738316e-19

# K=10 N=5000 T=50
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1   -3.78571845702551e-53   7.79939687131992e-144   -3.78571845702551e-53
0.2   -7.20086441482590e-53   1.26196892295452e-143   -7.20086441482590e-53
0.3   -9.91113959233060e-53   1.26196892295452e-143   -9.91113959233060e-53
0.4   -1.16512433715679e-52   7.79939687131992e-144   -1.16512433715679e-52
0.5   -1.22508422706102e-52   1.62494566295247e-159   -1.22508422706102e-52
0.6   -1.16512433715679e-52  -7.79939687131993e-144   -1.16512433715679e-52
0.7   -9.91113959233060e-53  -1.26196892295452e-143   -9.91113959233060e-53
0.8   -7.20086441482590e-53  -1.26196892295452e-143   -7.20086441482590e-53
0.9   -3.78571845702551e-53  -7.79939687131992e-144   -3.78571845702551e-53
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

# K=10 N=5000 T=50
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk

  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1   -3.78571845702551e-53   7.79939687131992e-144   -3.78571845702551e-53
0.2   -7.20086441482590e-53   1.26196892295452e-143   -7.20086441482590e-53
0.3   -9.91113959233060e-53   1.26196892295452e-143   -9.91113959233060e-53
0.4   -1.16512433715679e-52   7.79939687131992e-144   -1.16512433715679e-52
0.5   -1.22508422706102e-52   1.62494566295247e-159   -1.22508422706102e-52
0.6   -1.16512433715679e-52  -7.79939687131993e-144   -1.16512433715679e-52
0.7   -9.91113959233060e-53  -1.26196892295452e-143   -9.91113959233060e-53
0.8   -7.20086441482590e-53  -1.26196892295452e-143   -7.20086441482590e-53
0.9   -3.78571845702551e-53  -7.79939687131992e-144   -3.78571845702551e-53
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

# K=10 N=5000 T=50
# dx=0.1 dt=0.01 rho=0.166667
#  xk                      uk                      vk                   uk-vk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1   -3.78571845702551e-53   7.79939687131992e-144   -3.78571845702551e-53
0.2   -7.20086441482590e-53   1.26196892295452e-143   -7.20086441482590e-53
0.3   -9.91113959233060e-53   1.26196892295452e-143   -9.91113959233060e-53
0.4   -1.16512433715679e-52   7.79939687131992e-144   -1.16512433715679e-52
0.5   -1.22508422706102e-52   1.62494566295247e-159   -1.22508422706102e-52
0.6   -1.16512433715679e-52  -7.79939687131993e-144   -1.16512433715679e-52
0.7   -9.91113959233060e-53  -1.26196892295452e-143   -9.91113959233060e-53
0.8   -7.20086441482590e-53  -1.26196892295452e-143   -7.20086441482590e-53
0.9   -3.78571845702551e-53  -7.79939687131992e-144   -3.78571845702551e-53
  1    0.00000000000000e+00  -3.24989132590493e-159   3.24989132590493e-159

Note that this choice of Δt results in significantly more accurate accurate solutions than the choices used in Problem 1.2.1.

4. [Thomas Problem 1.5.1] Solve the problem

\{ \begin{matrix}v_{t} + av_{x} & = νv_{xx}, x ∈ (0, 1), t > 0 \\ v(x, 0) & = f(x), x ∈ [0, 1] \\ v(0, t) & = v(1, t) = 0, t ≥ 0 \end{matrix}

using the difference scheme

u_{k}^{n+1} = u_{k}^{n} − Rδ_{0}u_{k}^{n} + ρδ^{2}u_{k}^{n} for n = 0, …, N and k = 1, …, K − 1
u_{k}^{0} = f(x_{k})  for k = 0, …, K
u_{0}^{n} = u_{K}^{n} = 0  for n = 1, …, N

where R = aΔt/(2Δx) and ρ = νΔt/Δx^{2}. Use ν = 1.0, a = 2, K = 20 and f(x) = sin 4πx. Find solutions at t = 0.06, t = 0.1, t = 0.9 using Δt = 0.001.

We first find the exact solution. We begin by finding eigenfunctions X(x) so that

νX′′(x) − aX′(x) = λX(x)  and  X(0) = X(1) = 0.

The characteristic equation is

νr^{2} − ar − λ = 0

from which we determine that

r_{1} = \frac{a + \sqrt{a^{2} + 4νλ}}{2ν}  and  r_{2} = \frac{a − \sqrt{a^{2} + 4νλ}}{2ν}.

It follows that

X(x) = A exp(r_{1}x) + B exp(r_{2}x).

Since X(0) = 0 we obtain B = −A. Consequently

X(x) = A exp(r_{1}x) − A exp(r_{2}x).

Now X(1) = 0 implies exp(r_{1}) = exp(r_{2}) or that exp(r_{1} − r_{2}) = 1. It follows that

r_{1} − r_{2} = \frac{\sqrt{a^{2} + 4νλ}}{ν} = 2nπi

and so we obtain eigenfunction X_{n}(x) with eigenvalues λ_{n} given by

X_{n}(x) = exp(ax/2) sin(nπx) and λ_{n} = −νn^{2}π^{2} − \frac{a^{2}}{4ν} for n ∈ N.

Consider a solution of the form

v(x, t) = ∑_{n∈N} T_{n}(t)X_{n}(x).

Plugging this into the differential equation obtains

∑_{n∈N} T′_{n}(t)X_{n}(x) = ∑_{n∈N} λ_{n}T_{n}(t)X_{n}(x)

and since the eigenfunctions X_{n}(x) are linearly independent, it follows that

T′_{n}(t) = λ_{n}T_{n}(t)  for all  n ∈ N.

Solving this system yields that

T_{n}(t) = T_{n}(0) exp ( − νn^{2}π^{2}t − \frac{a^{2}t}{4ν})

and consequently

v(x, t) = ∑_{n∈N} T_{n}(0) exp ( − νn^{2}π^{2}t − \frac{a^{2}t}{4ν}) exp(ax/2) sin(nπx).

The initial condition

v(x, 0) = ∑_{n∈N} T_{n}(0) exp(ax/2) sin(nπx) = f(x) = sin(4πx)

implies

∑_{n∈N} T_{n}(0) sin(nπx) = exp(−ax/2) sin(4πx)

Multiplying by sin(mπx) and integrating yields that

T_{m}(0) = 2 ∫_{0}^{1} exp(−ax/2) sin(4πx) sin(mπx) dx

= \frac{128am(−1 + (−1)^{m} exp(−a/2))}{16m^{4}π^{4} + (8a^{2}π^{2} − 512π^{4})m^{2} + a^{4} + 128a^{2}π^{2} + 4096π^{4}} .

Therefore, the exact solution is a complicated series. We turn to Maple to help with this series. The maple script

1 restart;
2 R1:=2*exp(-a*x/2)*sin(4*Pi*x)*sin(m*Pi*x);
3 a:=2;
4 R1;
5 R2:=int(R1,x=0..1) assuming m::integer;
6 R3:=collect(R2,m);
7 with(codegen):
8 Digits:=15;
9 R4:=[optimize([TM0=evalf(R3)])];

10 C(R4);

produces the output

                           a x
             R1 := 2 exp(- ---) sin(4 Pi x) sin(m Pi x)
                            2
                               a := 2
                 2 exp(-x) sin(4 Pi x) sin(m Pi x)
                              2                   m
                       16 m Pi  (-1 + exp(-1) (-1) )
    R2 := - ----------------------------------------------------
                     2      2   2         4        4  2    4   4
            1 + 32 Pi  + 2 m  Pi  + 256 Pi  - 32 Pi  m  + m  Pi
                              2                   m
                       16 m Pi  (-1 + exp(-1) (-1) )
    R3 := - ---------------------------------------------------
             4   4        2        4   2            2         4
            m  Pi  + (2 Pi  - 32 Pi ) m  + 1 + 32 Pi  + 256 Pi
Warning, the protected name MathML has been redefined and unprotected
                            Digits := 15
           m        2         2
R4 := [t1 = (-1.) , t5 = m , t6 = t5 ,
            157.913670417429 m (-1. + 0.367879441171442 t1)
TM0 = - ------------------------------------------------------------]
      97.4090910340020 t6 - 3097.35170428588 t5 + 25253.5546455394
t1 = pow(-1.0,1.0*m);
t5 = m*m;
t6 = t5*t5;
TM0 = -0.157913670417429E3*m*(-1.0+0.367879441171442*t1)/(
0.97409091034002E2*t6-0.309735170428588E4*t5+0.252535546455394E5);

We replace pow(-1.0,1.0*m) with (1-2*(m%2)) to obtain the exact solution which, for convenience, we keep in a separate file of utility programs

1 /*  util4.c -- Utility routines for prog4.c, prog5.c and prog6.c
2  Written May 2013 by Eric Olson */

3

4 #include <stdio.h>
5 #include <math.h>
6 #include "util4.h"

7

8 double dt,dx,R,rho,nu;

9

10 static double Tn0(int m){

11  double t1,t5,t6,TM0;
12  t1 = 1-2*(m%2);
13  t5 = m*m;
14  t6 = t5*t5;
15  TM0 = -0.157913670417429E3*m*(-1.0+0.367879441171442*t1)/(
16 0.97409091034002E2*t6-0.309735170428588E4*t5+0.252535546455394E5);
17  return TM0;

18 }

19 static double v(double x,double t){
20  int m;
21  double r=0;
22  for(m=100;m>=0;m--){
23  r+=Tn0(m)*exp(-t*(nu*m*m*M_PI*M_PI+A*A/4/nu))
24  *exp(A*x/2)*sin(m*M_PI*x);

25 }

26  return r;

27 }

28 static double f(double x){
29  return sin(4*M_PI*x);

30 }

31 void doinit(int K,double u[K+1]){
32  int k;
33  for(k=0;k<=K;k++){
34  double xk=k*dx;
35  u[k]=f(xk);

36 } 37 }

38 void doprint(int K,double u[K+1],double tn){
39  int k;
40  printf("#%4s %23s %23s %23s\n","xk","uk","vk","vk-uk");
41  for(k=0;k<=K;k++){
42  double xk=k*dx;
43  double vk=v(xk,tn);
44  printf("%5g %23.14e %23.14e %23.14e\n",xk,u[k],vk,vk-u[k]);

45 } 46 }

47 void dosolve(int K,double u[K+1],int N,double T){
48  int n;
49  for(n=0;;n++){
50  double tn=n*dt;
51  u[0]=0; u[K]=0;
52  if(n>=N) break;
53  int k;
54  double w[K+1];
55  for(k=1;k<K;k++) w[k]=-R*(u[k+1]-u[k-1])

56  +rho*(u[k+1]-2*u[k]+u[k-1]);
57  for(k=1;k<K;k++) u[k]+=w[k];

58 } 59 }

with headers

 1 /*  util4.h -- Utility routines for prog4.c, prog5.c and prog6.c
 2  Written May 2013 by Eric Olson */

3

 4 #ifndef _UTIL4_H
 5 #define _UTIL4_H

6

 7 #define A 2.0

8

 9 extern double dt,dx,R,rho,nu;
10 extern void doinit(int K,double u[K+1]);
11 extern void doprint(int K,double u[K+1],double tn);
12 extern void dosolve(int K,double u[K+1],int N,double T);

13

14 #endif

The main routine is

 1 /*  prog4.c -- Thomas Problem 1.5.1
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #include "util4.h"

7

 8 main(){
 9  printf("# prog4 -- Thomas Problem 1.5.1\n"
10  "# Written May 2013 by Eric Olson\n#\n");
11  nu=1.0;
12  int KK[]={20,20,20};
13  double TT[]={0.06,0.1,0.9};
14  int NN[]={60,100,900};
15  int J=sizeof(TT)/sizeof(double);
16  int j;
17  for(j=0;j<J;j++){
18  int K=KK[j],N=NN[j];
19  double T=TT[j],u[K+1];
20  dx=1.0/K; dt=T/N;
21  R=A*dt/(2*dx); rho=nu*dt/dx/dx;
22  printf("#\tK=%d N=%d T=%g A=%g nu=%g\n"
23  "#\tdx=%g dt=%g R=%g rho=%g\n",

24  K,N,T,A,nu,dx,dt,R,rho);
25  doinit(K,u);
26  dosolve(K,u,N,T);
27  doprint(K,u,T);
28  printf("\n\n");

29 }

30  return 0;

31 }

The output is

# prog4 -- Thomas Problem 1.5.1
# Written May 2013 by Eric Olson
#
# K=20 N=60 T=0.06 A=2 nu=1
# dx=0.05 dt=0.001 R=0.02 rho=0.4
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05    1.46623413685960e-03    1.52411165668599e-03    5.78775198263879e-05
 0.1    2.96140439292754e-03    3.06944515101641e-03    1.08040758088868e-04
0.15    4.37029190625183e-03    4.50864167696056e-03    1.38349770708739e-04
 0.2    5.59138981384089e-03    5.73237428059674e-03    1.40984466755851e-04
0.25    6.55255511765887e-03    6.66730132115240e-03    1.14746203493528e-04
 0.3    7.22059773237988e-03    7.28616730215376e-03    6.55695697738866e-05
0.35    7.60270056556878e-03    7.60773429567998e-03    5.03373011120304e-06
 0.4    7.73950472930428e-03    7.68679002453340e-03   -5.27147047708846e-05
0.45    7.69167545470254e-03    7.59696280546681e-03   -9.47126492357297e-05
 0.5    7.52325815947266e-03    7.41077410707977e-03   -1.12484052392886e-04
0.55    7.28575688199937e-03    7.18181728070921e-03   -1.03939601290156e-04
 0.6    7.00649166875928e-03    6.93309534797398e-03   -7.33963207852966e-05
0.65    6.68357370731331e-03    6.65370952611011e-03   -2.98641812032010e-05
 0.7    6.28815293167090e-03    6.30386451572086e-03    1.57115840499523e-05
0.75    5.77290814513533e-03    5.82620604176428e-03    5.32978966289507e-05
 0.8    5.08447201949534e-03    5.16032546934095e-03    7.58534498456163e-05
0.85    4.17684973176715e-03    4.25703694928099e-03    8.01872175138427e-05
 0.9    3.02292757475456e-03    3.08960309001853e-03    6.66755152639743e-05
0.95    1.62173455201314e-03    1.66008307516332e-03    3.83485231501752e-05
   1    0.00000000000000e+00    1.37079784627557e-18    1.37079784627557e-18

# K=20 N=100 T=0.1 A=2 nu=1
# dx=0.05 dt=0.001 R=0.02 rho=0.4
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05    6.17817145957152e-04    6.24271147151420e-04    6.45400119426813e-06
 0.1    1.27607371097953e-03    1.28883246373243e-03    1.27587527528994e-05
0.15    1.95343279265092e-03    1.97160491314917e-03    1.81721204982424e-05
 0.2    2.62678834145056e-03    2.64883289500422e-03    2.20445535536657e-05
0.25    3.27253689609076e-03    3.29646327789337e-03    2.39263818026130e-05
 0.3    3.86781273108086e-03    3.89145589804292e-03    2.36431669620590e-05
0.35    4.39155461145447e-03    4.41287807446811e-03    2.13234630136363e-05
 0.4    4.82530184617355e-03    4.84267452746652e-03    1.73726812929620e-05
0.45    5.15366199665063e-03    5.16605981039609e-03    1.23978137454624e-05
 0.5    5.36444430241762e-03    5.37154240064203e-03    7.09809822440916e-06

0.55    5.44850226944188e-03    5.45064622321818e-03    2.14395377629798e-06
 0.6    5.39936726558439e-03    5.39743622815100e-03   -1.93103743339421e-06
0.65    5.21277623005713e-03    5.20797290977389e-03   -4.80332028323944e-06
 0.7    4.88619836136673e-03    4.87981454722936e-03   -6.38381413736299e-06
0.75    4.41844975405689e-03    4.41165898743486e-03   -6.79076662202845e-06
 0.8    3.80945696254658e-03    3.80317694700718e-03   -6.28001553939746e-06
0.85    3.06019825135991e-03    3.05504657453517e-03   -5.15167682474133e-06
 0.9    2.17282307586214e-03    2.16916491087679e-03   -3.65816498534887e-06
0.95    1.15093261982319e-03    1.14899388963470e-03   -1.93873018848579e-06
   1    0.00000000000000e+00    9.44092120664098e-19    9.44092120664098e-19

# K=20 N=900 T=0.9 A=2 nu=1
# dx=0.05 dt=0.001 R=0.02 rho=0.4
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05    8.78925634351604e-08    9.00670446937724e-08    2.17448125861201e-09
 0.1    1.82530271892983e-07    1.87038305638134e-07    4.50803374515054e-09
0.15    2.81924064740487e-07    2.88874817732295e-07    6.95075299180805e-09
 0.2    3.83739862589602e-07    3.93184445797730e-07    9.44458320812892e-09
0.25    4.85328817686116e-07    4.97252951916199e-07    1.19241342300834e-08
 0.3    5.83769725772004e-07    5.98087514749589e-07    1.43177889775848e-08
0.35    6.75923669986131e-07    6.92472769495930e-07    1.65490995097982e-08
 0.4    7.58500625937397e-07    7.77039087336565e-07    1.85384613991681e-08
0.45    8.28137387438453e-07    8.48342434658105e-07    2.02050472196516e-08
 0.5    8.81485782099602e-07    9.02954752758228e-07    2.14689706586262e-08
0.55    9.15309744009434e-07    9.37563387351391e-07    2.22536433419570e-08
 0.6    9.26589407305591e-07    9.49077684466671e-07    2.24882771610797e-08
0.65    9.12629990918799e-07    9.34740466904159e-07    2.21104759853595e-08
 0.7    8.71172873421566e-07    8.92241725846328e-07    2.10688524247628e-08
0.75    8.00505920654273e-07    8.19831518733828e-07    1.93255980795553e-08
 0.8    6.99569840919900e-07    7.16428770700332e-07    1.68589297804317e-08
0.85    5.68057116337059e-07    5.81722446320546e-07    1.36653299834868e-08
 0.9    4.06499907363295e-07    4.16261404387515e-07    9.76149702421930e-09
0.95    2.16343262724872e-07    2.21529183338179e-07    5.18592061330660e-09
   1    0.00000000000000e+00    1.82309683727663e-22    1.82309683727663e-22

5. [Thomas Problem 1.5.2] Repeat Problem 1.5.1 with ν = 0.01.

The program is

 1 /*  prog5.c -- Thomas Problem 1.5.2
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #include "util4.h"

7

 8 main(){
 9  printf("# prog5 -- Thomas Problem 1.5.2\n"
10  "# Written May 2013 by Eric Olson\n#\n");
11  nu=0.01;
12  int KK[]={20,20,20};
13  double TT[]={0.06,0.1,0.9};
14  int NN[]={60,100,900};
15  int J=sizeof(TT)/sizeof(double);
16  int j;
17  for(j=0;j<J;j++){
18  int K=KK[j],N=NN[j];
19  double T=TT[j],u[K+1];
20  dx=1.0/K; dt=T/N;
21  R=A*dt/(2*dx); rho=nu*dt/dx/dx;
22  printf("#\tK=%d N=%d T=%g A=%g nu=%g\n"
23  "#\tdx=%g dt=%g R=%g rho=%g\n",
24  K,N,T,A,nu,dx,dt,R,rho);
25  doinit(K,u);
26  dosolve(K,u,N,T);
27  doprint(K,u,T);
28  printf("\n\n");

29 }

30  return 0;

31 }

The output is

   # prog5 -- Thomas Problem 1.5.2
   # Written May 2013 by Eric Olson
   #
   # K=20 N=60 T=0.06 A=2 nu=0.01
   # dx=0.05 dt=0.001 R=0.02 rho=0.004
   #  xk                      uk                      vk                   vk-uk
       0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
    0.05   -3.66160688906034e-02    1.30037164365576e-03    3.79164405342592e-02
     0.1    1.41033226496769e-01    2.13488161551833e-03   -1.38898344881251e-01
    0.15    5.20102633220556e-01    2.15588150061455e-03   -5.17946751719941e-01
     0.2    8.53605901727816e-01    1.35343281898829e-03   -8.52252468908828e-01

0.25    9.21967139223049e-01    3.40188567416987e-05   -9.21933120366307e-01
 0.3    6.56302514259971e-01   -1.29838915250333e-03   -6.57600903412474e-01
0.35    1.44253176488393e-01   -2.13485663611623e-03   -1.46388033124510e-01
 0.4   -4.22051975922827e-01   -2.15588144584100e-03    4.19896094476986e-01
0.45   -8.27006946578637e-01   -1.35343281896978e-03    8.25653513759667e-01
 0.5   -9.16053076685987e-01   -3.40188567416988e-05    9.16019057829245e-01
0.55   -6.55195588718864e-01    1.29838915250327e-03    6.56493977871367e-01
 0.6   -1.44074257692972e-01    2.13485663611614e-03    1.46209114329089e-01
0.65    4.22066502486374e-01    2.15588144584090e-03   -4.19910621040533e-01
 0.7    8.27107213876885e-01    1.35343281896972e-03   -8.25753781057915e-01
0.75    9.15274661543513e-01    3.40188567416989e-05   -9.15240642686771e-01
 0.8    6.60449047432807e-01   -1.29838915249082e-03   -6.61747436585298e-01
0.85    1.15030577143323e-01   -2.13485659553884e-03   -1.17165433738862e-01
 0.9   -2.95362045538957e-01   -2.15586099443615e-03    2.93206184544521e-01
0.95   -1.23939634661129e+00   -1.35163898679403e-03    1.23804470762450e+00
   1    0.00000000000000e+00   -1.14739460755934e-18   -1.14739460755934e-18

# K=20 N=100 T=0.1 A=2 nu=0.01
# dx=0.05 dt=0.001 R=0.02 rho=0.004
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05   -2.63084605264710e-02    2.21408302683046e-05    2.63306013567393e-02
 0.1   -7.02940031400941e-02    3.66012401000233e-05    7.03306043801941e-02
0.15    4.17282994455560e-02    3.71973461843038e-05   -4.16911020993717e-02
 0.2    3.52498465430278e-01    2.35918633298297e-05   -3.52474873566949e-01
0.25    7.09180810204167e-01    9.75219953555280e-07   -7.09179834984214e-01
 0.3    8.99757619415463e-01   -2.20139234423312e-05   -8.99779633338905e-01
0.35    7.93457658961539e-01   -3.65944963071668e-05   -7.93494253457846e-01
 0.4    4.01110907392467e-01   -3.71972153838459e-05   -4.01148104607851e-01
0.45   -1.39221499735007e-01   -2.35918624707464e-05    1.39197907872536e-01
 0.5   -6.24988951315169e-01   -9.75219951735159e-07    6.24987976095218e-01
0.55   -8.71723674998390e-01    2.20139234423315e-05    8.71745688921832e-01
 0.6   -7.85322839148934e-01    3.65944963071652e-05    7.85359433645242e-01
0.65   -3.99554002518141e-01    3.71972153838442e-05    3.99591199733525e-01
 0.7    1.42135464869813e-01    2.35918624707460e-05   -1.42111873007342e-01
0.75    6.14006671200832e-01    9.75219952839121e-07   -6.14005695980879e-01
 0.8    9.13767658112682e-01   -2.20139228664701e-05   -9.13789672035549e-01
0.85    6.54793908186113e-01   -3.65943994078017e-05   -6.54830502585520e-01
 0.9    7.16910068116009e-01   -3.71916940332391e-05   -7.16947259810043e-01
0.95   -7.03287965884016e-01   -2.34770324260008e-05    7.03264488851590e-01
   1    0.00000000000000e+00   -2.01080853901805e-20   -2.01080853901805e-20

# K=20 N=900 T=0.9 A=2 nu=0.01
# dx=0.05 dt=0.001 R=0.02 rho=0.004
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05   -8.11561198052876e-05    1.11340650376665e-40    8.11561198052876e-05
 0.1   -2.60651946725292e-04    1.92263668825717e-40    2.60651946725292e-04
0.15    4.21163581407451e-04    2.10483169779242e-40   -4.21163581407451e-04
 0.2   -7.53110622485622e-04    1.56189542823066e-40    7.53110622485622e-04
0.25    1.19319596362230e-03    4.71644314004358e-41   -1.19319596362230e-03
 0.3   -1.23291234388256e-03   -7.72216104333435e-41    1.23291234388256e-03
0.35    9.45781420422263e-04   -1.70871084303654e-40   -9.45781420422263e-04

0.4    1.22642083529880e-04   -1.98748635243617e-40   -1.22642083529880e-04
0.45   -8.56280089345500e-04   -1.50531340252608e-40    8.56280089345500e-04
0.5    1.80578185852223e-03   -4.47591518289244e-41   -1.80578185852223e-03
0.55   -2.75191311881464e-03    7.81310041861009e-41    2.75191311881464e-03
0.6    9.51019088111692e-04    1.71207503603697e-40   -9.51019088111692e-04
0.65    1.87194122487970e-03    1.98982993595506e-40   -1.87194122487970e-03
0.7   -2.41820931262331e-03    1.51047496818956e-40    2.41820931262331e-03
0.75    2.67723179539364e-03    4.62207356998431e-41   -2.67723179539364e-03
0.8   -3.21841620843348e-03   -7.43432877196221e-41    3.21841620843348e-03
0.85   -4.45160751947331e-03   -1.62539465301124e-40    4.45160751947331e-03
0.9    7.67405525760697e-03   -1.81563981832394e-40   -7.67405525760697e-03
0.95    1.93376654716871e-03   -1.20495500508405e-40   -1.93376654716871e-03
  1    0.00000000000000e+00   -1.06147935096202e-55   -1.06147935096202e-55

6. [Thomas Problem 1.5.3] Repeat Problem 1.5.1 and 1.5.2 with K=40.

The program is

 1 /*  prog6.c -- Thomas Problem 1.5.3
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #include "util4.h"

7

 8 main(){
 9  printf("# prog6 -- Thomas Problem 1.5.3\n"
10  "# Written May 2013 by Eric Olson\n#\n");
11  int KK[]={40,40,40,40,40,40,40,40,40,40,40,40};
12  double TT[]={0.06,0.06,0.1,0.1,0.9,0.9,0.06,0.06,0.1,0.1,0.9,0.9};
13  int NN[]={60,600,100,1000,900,9000,60,600,100,1000,900,9000};
14  double NU[]={1,1,1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01};
15  int J=sizeof(TT)/sizeof(double);
16  int j;
17  for(j=0;j<J;j++){
18  nu=NU[j];
19  int K=KK[j],N=NN[j];
20  double T=TT[j],u[K+1];
21  dx=1.0/K; dt=T/N;
22  R=A*dt/(2*dx); rho=nu*dt/dx/dx;
23  printf("#\tK=%d N=%d T=%g A=%g nu=%g\n"
24  "#\tdx=%g dt=%g R=%g rho=%g\n",
25  K,N,T,A,nu,dx,dt,R,rho);
26  doinit(K,u);
27  dosolve(K,u,N,T);
28  doprint(K,u,T);
29  printf("\n\n");

30 }

31  return 0;

32 }

The output is

   # prog6 -- Thomas Problem 1.5.3
   # Written May 2013 by Eric Olson
   #
   # K=40 N=60 T=0.06 A=2 nu=1
   # dx=0.025 dt=0.001 R=0.04 rho=1.6
   #  xk                      uk                      vk                   vk-uk
       0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
   0.025    3.40618843526207e+38    7.51325964408646e-04   -3.40618843526207e+38
    0.05   -6.69593287459587e+38    1.52411165668599e-03    6.69593287459587e+38
   0.075    9.59777492301421e+38    2.30226100030866e-03   -9.59777492301421e+38

  0.1   -1.18881458358899e+39    3.06944515101641e-03    1.18881458358899e+39
0.125    1.34195715032897e+39    3.80980600342571e-03   -1.34195715032897e+39
 0.15   -1.41354392853401e+39    4.50864167696056e-03    1.41354392853401e+39
0.175    1.40694679348159e+39    5.15303314832775e-03   -1.40694679348159e+39
  0.2   -1.33313012778473e+39    5.73237428059674e-03    1.33313012778473e+39
0.225    1.20823219875280e+39    6.23877324061957e-03   -1.20823219875280e+39
 0.25   -1.05072434780705e+39    6.66730132115240e-03    1.05072434780705e+39
0.275    8.78707067888556e+38    7.01607493260423e-03   -8.78707067888556e+38
  0.3   -7.07782085954383e+38    7.28616730215376e-03    7.07782085954383e+38
0.325    5.49745762542403e+38    7.48135742991628e-03   -5.49745762542403e+38
 0.35   -4.12141647441791e+38    7.60773429567998e-03    4.12141647441791e+38
0.375    2.98540847031290e+38    7.67318342211199e-03   -2.98540847031290e+38
  0.4   -2.09318784617957e+38    7.68679002453340e-03    2.09318784617957e+38
0.425    1.42671749281719e+38    7.65819761716095e-03   -1.42671749281719e+38
 0.45   -9.56514283709219e+37    7.59696280546681e-03    9.56514283709219e+37
0.475    6.50641063613344e+37    7.51194600149380e-03   -6.50641063613344e+37
  0.5   -4.81558151198805e+37    7.41077410707977e-03    4.81558151198805e+37
0.525    4.30643230036509e+37    7.29940518146321e-03   -4.30643230036509e+37
 0.55   -4.90526677423843e+37    7.18181728070921e-03    4.90526677423843e+37
0.575    6.65467202465366e+37    7.05983468601469e-03   -6.65467202465366e+37
  0.6   -9.69890109030230e+37    6.93309534797398e-03    9.69890109030230e+37
0.625    1.42505538944490e+38    6.79915428360826e-03   -1.42505538944490e+38
 0.65   -2.05375337744338e+38    6.65370952611011e-03    2.05375337744338e+38
0.675    2.87305381763018e+38    6.49093057685101e-03   -2.87305381763018e+38
  0.7   -3.88551169948815e+38    6.30386451572086e-03    3.88551169948815e+38
0.725    5.06982405456966e+38    6.08489217268453e-03   -5.06982405456966e+38
 0.75   -6.37259983923886e+38    5.82620604176428e-03    6.37259983923886e+38
0.775    7.70342740832074e+38    5.52028274222164e-03   -7.70342740832074e+38
  0.8   -8.93554082258662e+38    5.16032546934095e-03    8.93554082258662e+38
0.825    9.91388096892215e+38    4.74065559951786e-03   -9.91388096892215e+38
 0.85   -1.04711425942684e+39    4.25703694928099e-03    1.04711425942684e+39
0.875    1.04506304400283e+39    3.70692067879109e-03   -1.04506304400283e+39
  0.9   -9.73278560852171e+38    3.08960309001853e-03    9.73278560852171e+38
0.925    8.26062340799465e+38    2.40629232384582e-03   -8.26062340799465e+38
 0.95   -6.05860440947375e+38    1.66008307516332e-03    6.05860440947375e+38
0.975    3.24003291920665e+38    8.55840936326871e-04   -3.24003291920665e+38
    1    0.00000000000000e+00    1.37079784627557e-18    1.37079784627557e-18

# K=40 N=600 T=0.06 A=2 nu=1
# dx=0.025 dt=0.0001 R=0.004 rho=0.16
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    7.51996991590100e-04    7.51325964408646e-04   -6.71027181454726e-07
 0.05    1.52546528620609e-03    1.52411165668599e-03   -1.35362952010396e-06
0.075    2.30427871554019e-03    2.30226100030866e-03   -2.01771523153371e-06
  0.1    3.07207866982140e-03    3.06944515101641e-03   -2.63351880499174e-06
0.125    3.81297945043462e-03    3.80980600342571e-03   -3.17344700891077e-06
 0.15    4.51225550218488e-03    4.50864167696056e-03   -3.61382522431983e-06
0.175    5.15696956335095e-03    5.15303314832775e-03   -3.93641502320543e-06
  0.2    5.73650386885673e-03    5.73237428059674e-03   -4.12958825998701e-06
0.225    6.24296230756765e-03    6.23877324061957e-03   -4.18906694807635e-06
 0.25    6.67141949121091e-03    6.66730132115240e-03   -4.11817005851241e-06
0.275    7.02000247817540e-03    7.01607493260423e-03   -3.92754557117063e-06
  0.3    7.28980170772069e-03    7.28616730215376e-03   -3.63440556692268e-06

0.325    7.48461875045898e-03    7.48135742991628e-03   -3.26132054270095e-06
 0.35    7.61056895884714e-03    7.60773429567998e-03   -2.83466316715851e-06
0.375    7.67556624052862e-03    7.67318342211199e-03   -2.38281841662656e-06
  0.4    7.68872431863527e-03    7.68679002453340e-03   -1.93429410187684e-06
0.425    7.65971348888346e-03    7.65819761716095e-03   -1.51587172251156e-06
 0.45    7.59811373733743e-03    7.59696280546681e-03   -1.15093187062851e-06
0.475    7.51280407310092e-03    7.51194600149380e-03   -8.58071607117220e-07
  0.5    7.41142421200477e-03    7.41077410707977e-03   -6.50104924998854e-07
0.525    7.29993868550500e-03    7.29940518146321e-03   -5.33504041792289e-07
 0.55    7.18232558263088e-03    7.18181728070921e-03   -5.08301921670583e-07
0.575    7.06040312458214e-03    7.05983468601469e-03   -5.68438567451722e-07
  0.6    6.93379784668707e-03    6.93309534797398e-03   -7.02498713094253e-07
0.625    6.80004904335106e-03    6.79915428360826e-03   -8.94759742807276e-07
 0.65    6.65483597459749e-03    6.65370952611011e-03   -1.12644848737978e-06
0.675    6.49230767249425e-03    6.49093057685101e-03   -1.37709564324191e-06
  0.7    6.30549039323797e-03    6.30386451572086e-03   -1.62587751711615e-06
0.725    6.08674501878385e-03    6.08489217268453e-03   -1.85284609931571e-06
 0.75    5.82824601029631e-03    5.82620604176428e-03   -2.03996853203464e-06
0.775    5.52245466561031e-03    5.52028274222164e-03   -2.17192338866461e-06
  0.8    5.16256210004251e-03    5.16032546934095e-03   -2.23663070155703e-06
0.825    4.74288112146817e-03    4.74065559951786e-03   -2.22552195031089e-06
 0.85    4.25917053117877e-03    4.25703694928099e-03   -2.13358189777527e-06
0.875    3.70887989211731e-03    3.70692067879109e-03   -1.95921332622794e-06
  0.9    3.09130707626578e-03    3.08960309001853e-03   -1.70398624724710e-06
0.925    2.40766465778395e-03    2.40629232384582e-03   -1.37233393813184e-06
 0.95    1.66105432445317e-03    1.66008307516332e-03   -9.71249289851133e-07
0.975    8.56350954073910e-04    8.55840936326871e-04   -5.10017747038980e-07
    1    0.00000000000000e+00    1.37079784627557e-18    1.37079784627557e-18

# K=40 N=100 T=0.1 A=2 nu=1
# dx=0.025 dt=0.001 R=0.04 rho=1.6
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    3.10315866557873e+67    3.05821339524153e-04   -3.10315866557873e+67
 0.05   -6.20430247910561e+67    6.24271147151420e-04    6.20430247910561e+67
0.075    9.14760413452547e+67    9.52840265494388e-04   -9.14760413452547e+67
  0.1   -1.17877382493598e+68    1.28883246373243e-03    1.17877382493598e+68
0.125    1.40017580202047e+68    1.62940382814589e-03   -1.40017580202047e+68
 0.15   -1.56985699496927e+68    1.97160491314917e-03    1.56985699496927e+68
0.175    1.68250084277222e+68    2.31242439169945e-03   -1.68250084277222e+68
  0.2   -1.73679868655905e+68    2.64883289500422e-03    1.73679868655905e+68
0.225    1.73527319896549e+68    2.97782573685322e-03   -1.73527319896549e+68
 0.25   -1.68376062024665e+68    3.29646327789337e-03    1.68376062024665e+68
0.275    1.59064132042703e+68    3.60190779725900e-03   -1.59064132042703e+68
  0.3   -1.46593115564962e+68    3.89145589804292e-03    1.46593115564962e+68
0.325    1.32035081787015e+68    4.16256567163794e-03   -1.32035081787015e+68
 0.35   -1.16447798448423e+68    4.41287807446811e-03    1.16447798448423e+68
0.375    1.00806134429867e+68    4.64023221802582e-03   -1.00806134429867e+68
  0.4   -8.59541998732333e+67    4.84267452746652e-03    8.59541998732333e+67
0.425    7.25792337963791e+67    5.01846197303120e-03   -7.25792337963791e+67
 0.45   -6.12050748585540e+67    5.16605981039609e-03    6.12050748585540e+67
0.475    5.22006557865821e+67    5.28413446983959e-03   -5.22006557865821e+67
  0.5   -4.57975850486211e+67    5.37154240064203e-03    4.57975850486211e+67
0.525    4.21105830508991e+67    5.42731579928773e-03   -4.21105830508991e+67

 0.55   -4.11552366241213e+67    5.45064622321818e-03    4.11552366241213e+67
0.575    4.28590280419018e+67    5.44086711423556e-03   -4.28590280419018e+67
  0.6   -4.70636199641417e+67    5.39743622815100e-03    4.70636199641417e+67
0.625    5.35186405350948e+67    5.31991889364165e-03   -5.35186405350948e+67
 0.65   -6.18694110515670e+67    5.20797290977389e-03    6.18694110515670e+67
0.675    7.16428993813855e+67    5.06133574665621e-03   -7.16428993813855e+67
  0.7   -8.22373984658163e+67    4.87981454722936e-03    8.22373984658163e+67
0.725    9.29218007352843e+67    4.66327925134288e-03   -9.29218007352843e+67
 0.75   -1.02849723287553e+68    4.41165898743486e-03    1.02849723287553e+68
0.775    1.11092105501525e+68    4.12494171343100e-03   -1.11092105501525e+68
  0.8   -1.16689366763702e+68    3.80317694700718e-03    1.16689366763702e+68
0.825    1.18721057231520e+68    3.44648131457678e-03   -1.18721057231520e+68
 0.85   -1.16387592434738e+68    3.05504657453517e-03    1.16387592434738e+68
0.875    1.09095673467859e+68    2.62914973706271e-03   -1.09095673467859e+68
  0.9   -9.65369245464861e+67    2.16916491087679e-03    9.65369245464861e+67
0.925    7.87486147424057e+67    1.67557655440888e-03   -7.87486147424057e+67
 0.95   -5.61463676441038e+67    1.14899388963470e-03    5.61463676441038e+67
0.975    2.95215226265739e+67    5.90166343093643e-04   -2.95215226265739e+67
    1    0.00000000000000e+00    9.44092120664098e-19    9.44092120664098e-19

# K=40 N=1000 T=0.1 A=2 nu=1
# dx=0.025 dt=0.0001 R=0.004 rho=0.16
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    3.05976854556274e-04    3.05821339524153e-04   -1.55515032120685e-07
 0.05    6.24590550263002e-04    6.24271147151420e-04   -3.19403111581911e-07
0.075    9.53329451366152e-04    9.52840265494388e-04   -4.89185871763295e-07
  0.1    1.28949468678490e-03    1.28883246373243e-03   -6.62223052474509e-07
0.125    1.63023961926961e-03    1.62940382814589e-03   -8.35791123713443e-07
 0.15    1.97261207836128e-03    1.97160491314917e-03   -1.00716521210823e-06
0.175    2.31359809251378e-03    2.31242439169945e-03   -1.17370081433379e-06
  0.2    2.65016580674095e-03    2.64883289500422e-03   -1.33291173672187e-06
0.225    2.97930827769127e-03    2.97782573685322e-03   -1.48254083805286e-06
 0.25    3.29808389836261e-03    3.29646327789337e-03   -1.62062046924014e-06
0.275    3.60365331724405e-03    3.60190779725900e-03   -1.74551998504248e-06
  0.3    3.89331187636794e-03    3.89145589804292e-03   -1.85597832502325e-06
0.325    4.16451679202904e-03    4.16256567163794e-03   -1.95112039110077e-06
 0.35    4.41490853121623e-03    4.41287807446811e-03   -2.03045674812118e-06
0.375    4.64232608502404e-03    4.64023221802582e-03   -2.09386699821616e-06
  0.4    4.84481609545037e-03    4.84267452746652e-03   -2.14156798385764e-06
0.425    5.02063604174514e-03    5.01846197303120e-03   -2.17406871394401e-06
 0.45    5.16825192493691e-03    5.16605981039609e-03   -2.19211454081675e-06
0.475    5.28633109344821e-03    5.28413446983959e-03   -2.19662360861992e-06
  0.5    5.37373101955998e-03    5.37154240064203e-03   -2.18861891795093e-06
0.525    5.42948495877834e-03    5.42731579928773e-03   -2.16915949061060e-06
 0.55    5.45278549728304e-03    5.45064622321818e-03   -2.13927406485931e-06
0.575    5.44296701474561e-03    5.44086711423556e-03   -2.09990051005821e-06
  0.6    5.39948806188598e-03    5.39743622815100e-03   -2.05183373497720e-06
0.625    5.32191457794292e-03    5.31991889364165e-03   -1.99568430127219e-06
 0.65    5.20990475905006e-03    5.20797290977389e-03   -1.93184927617471e-06
0.675    5.06319624276237e-03    5.06133574665621e-03   -1.86049610616246e-06
  0.7    4.88159610673994e-03    4.87981454722936e-03   -1.78155951057607e-06
0.725    4.66497400196994e-03    4.66327925134288e-03   -1.69475062705964e-06
 0.75    4.41325856436960e-03    4.41165898743486e-03   -1.59957693474187e-06

0.775    4.12643708430974e-03    4.12494171343100e-03   -1.49537087874678e-06
  0.8    3.80455827166491e-03    3.80317694700718e-03   -1.38132465773034e-06
0.825    3.44773784292131e-03    3.44648131457678e-03   -1.25652834452464e-06
 0.85    3.05616658294396e-03    3.05504657453517e-03   -1.12000840879175e-06
0.875    2.63012050087300e-03    2.62914973706271e-03   -9.70763810293103e-07
  0.9    2.16997270800790e-03    2.16916491087679e-03   -8.07797131108321e-07
0.925    1.67620669311132e-03    1.67557655440888e-03   -6.30138702440537e-07
 0.95    1.14943075196863e-03    1.14899388963470e-03   -4.36862333930100e-07
0.975    5.90393435129974e-04    5.90166343093643e-04   -2.27092036331460e-07
    1    0.00000000000000e+00    9.44092120664098e-19    9.44092120664098e-19

# K=40 N=900 T=0.9 A=2 nu=1
# dx=0.025 dt=0.001 R=0.04 rho=1.6
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025                    -nan    4.40574551492635e-08                    -nan
 0.05                    -nan    9.00670446937724e-08                    -nan
0.075                    -nan    1.37808525795432e-07                    -nan
  0.1                    -nan    1.87038305638134e-07                    -nan
0.125                    -nan    2.37489940206277e-07                    -nan
 0.15                    -nan    2.88874817732295e-07                    -nan
0.175                    -nan    3.40883031523022e-07                    -nan
  0.2                    -nan    3.93184445797730e-07                    -nan
0.225                    -nan    4.45429957013086e-07                    -nan
 0.25                    -nan    4.97252951916199e-07                    -nan
0.275                    -nan    5.48270962260868e-07                    -nan
  0.3                    -nan    5.98087514749589e-07                    -nan
0.325                    -nan    6.46294173330988e-07                    -nan
 0.35                    -nan    6.92472769495930e-07                    -nan
0.375                    -nan    7.36197814683292e-07                    -nan
  0.4                    -nan    7.77039087336565e-07                    -nan
0.425                    -nan    8.14564385554046e-07                    -nan
 0.45                    -nan    8.48342434658105e-07                    -nan
0.475                    -nan    8.77945937383140e-07                    -nan
  0.5                    -nan    9.02954752758228e-07                    -nan
0.525                    -nan    9.22959188150546e-07                    -nan
 0.55                    -nan    9.37563387351391e-07                    -nan
0.575                    -nan    9.46388796040246e-07                    -nan
  0.6                    -nan    9.49077684466671e-07                    -nan
0.625                    -nan    9.45296705757803e-07                    -nan
 0.65                    -nan    9.34740466904159e-07                    -nan
0.675                    -nan    9.17135088211605e-07                    -nan
  0.7                    -nan    8.92241725846328e-07                    -nan
0.725                    -nan    8.59860031055625e-07                    -nan
 0.75                    -nan    8.19831518733828e-07                    -nan
0.775                    -nan    7.72042817232526e-07                    -nan
  0.8                    -nan    7.16428770700332e-07                    -nan
0.825                    -nan    6.52975364791892e-07                    -nan
 0.85                    -nan    5.81722446320546e-07                    -nan
0.875                    -nan    5.02766207354951e-07                    -nan
  0.9                    -nan    4.16261404387515e-07                    -nan
0.925                    -nan    3.22423283541064e-07                    -nan
 0.95                    -nan    2.21529183338179e-07                    -nan
0.975                    -nan    1.13919787342593e-07                    -nan

    1    0.00000000000000e+00    1.82309683727663e-22    1.82309683727663e-22

# K=40 N=9000 T=0.9 A=2 nu=1
# dx=0.025 dt=0.0001 R=0.004 rho=0.16
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    4.41457150206448e-08    4.40574551492635e-08   -8.82598713813266e-11
 0.05    9.02479453448831e-08    9.00670446937724e-08   -1.80900651110668e-10
0.075    1.38086035203123e-07    1.37808525795432e-07   -2.77509407691082e-10
  0.1    1.87415927106211e-07    1.87038305638134e-07   -3.77621468076951e-10
0.125    2.37970661023975e-07    2.37489940206277e-07   -4.80720817698138e-10
 0.15    2.89461058623160e-07    2.88874817732295e-07   -5.86240890865102e-10
0.175    3.41576597290909e-07    3.40883031523022e-07   -6.93565767886827e-10
  0.2    3.93986477590964e-07    3.93184445797730e-07   -8.02031793233560e-10
0.225    4.46340886639947e-07    4.45429957013086e-07   -9.10929626860611e-10
 0.25    4.98272458654583e-07    4.97252951916199e-07   -1.01950673838350e-09
0.275    5.49397932612028e-07    5.48270962260868e-07   -1.12697035116057e-09
  0.3    5.99320005590099e-07    5.98087514749589e-07   -1.23249084051005e-09
0.325    6.47629378918256e-07    6.46294173330988e-07   -1.33520558726796e-09
 0.35    6.93906992780622e-07    6.92472769495930e-07   -1.43422328469238e-09
0.375    7.37726443376653e-07    7.36197814683292e-07   -1.52862869336094e-09
  0.4    7.78656575171757e-07    7.77039087336565e-07   -1.61748783519114e-09
0.425    8.16264239168112e-07    8.14564385554046e-07   -1.69985361406566e-09
 0.45    8.50117206504892e-07    8.48342434658105e-07   -1.77477184678772e-09
0.475    8.79787225067370e-07    8.77945937383140e-07   -1.84128768422949e-09
  0.5    9.04853205156844e-07    9.02954752758228e-07   -1.89845239861586e-09
0.525    9.24904518659452e-07    9.22959188150546e-07   -1.94533050890612e-09
 0.55    9.39544394563633e-07    9.37563387351391e-07   -1.98100721224176e-09
0.575    9.48393392125685e-07    9.46388796040246e-07   -2.00459608543830e-09
  0.6    9.51092931483216e-07    9.49077684466671e-07   -2.01524701654486e-09
0.625    9.47308860080405e-07    9.45296705757803e-07   -2.01215432260158e-09
 0.65    9.36735031910093e-07    9.34740466904159e-07   -1.99456500593486e-09
0.675    9.19096875309270e-07    9.17135088211605e-07   -1.96178709766504e-09
  0.7    8.94154923879929e-07    8.92241725846328e-07   -1.91319803360016e-09
0.725    8.61708284060011e-07    8.59860031055625e-07   -1.84825300438577e-09
 0.75    8.21598011952535e-07    8.19831518733828e-07   -1.76649321870690e-09
0.775    7.73710371248068e-07    7.72042817232526e-07   -1.66755401554238e-09
  0.8    7.17979943459278e-07    7.16428770700332e-07   -1.55117275894684e-09
0.825    6.54392561238593e-07    6.52975364791892e-07   -1.41719644670105e-09
 0.85    5.82988035282889e-07    5.81722446320546e-07   -1.26558896234271e-09
0.875    5.03862645253675e-07    5.02766207354951e-07   -1.09643789872384e-09
  0.9    4.17171365267794e-07    4.16261404387515e-07   -9.09960880278871e-10
0.925    3.23129794851754e-07    3.22423283541064e-07   -7.06511310689892e-10
 0.95    2.22015766810853e-07    2.21529183338179e-07   -4.86583472673758e-10
0.975    1.14170604249725e-07    1.13919787342593e-07   -2.50816907132067e-10
    1    0.00000000000000e+00    1.82309683727663e-22    1.82309683727663e-22

# K=40 N=60 T=0.06 A=2 nu=0.01
# dx=0.025 dt=0.001 R=0.04 rho=0.016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025   -2.16569580025298e-03    6.74482781277200e-04    2.84017858153018e-03
 0.05   -1.50719828677355e-02    1.30037164365576e-03    1.63723545113912e-02

0.075   -7.85988037906078e-03    1.80523803757166e-03    9.66511841663244e-03
  0.1    6.45456916935109e-02    2.13488161551833e-03   -6.24108100779925e-02
0.125    2.15900801916273e-01    2.25577597283107e-03   -2.13645025943442e-01
 0.15    4.19399368045152e-01    2.15588150061455e-03   -4.17243486544538e-01
0.175    6.28924891058794e-01    1.84495569249225e-03   -6.27079935366302e-01
  0.2    8.01060918865144e-01    1.35343281898829e-03   -7.99707486046156e-01
0.225    9.05099224920890e-01    7.29426512483536e-04   -9.04369798408407e-01
 0.25    9.24294456246690e-01    3.40188567416987e-05   -9.24260437389948e-01
0.275    8.54200318621397e-01   -6.64718801721162e-04   -8.54865037423118e-01
  0.3    7.00821660253234e-01   -1.29838915250333e-03   -7.02120049405737e-01
0.325    4.78923645752567e-01   -1.80496412662929e-03   -4.80728609879196e-01
 0.35    2.10163489935116e-01   -2.13485663611623e-03   -2.12298346571233e-01
0.375   -7.91652613404142e-02   -2.25577450363929e-03    7.69094868367749e-02
  0.4   -3.60744093429384e-01   -2.15588144584100e-03    3.58588211983543e-01
0.425   -6.07010667871775e-01   -1.84495569121451e-03    6.05165712180561e-01
 0.45   -7.93858791621192e-01   -1.35343281896978e-03    7.92505358802222e-01
0.475   -9.02998483274516e-01   -7.29426512483346e-04    9.02269056762033e-01
  0.5   -9.23746391507410e-01   -3.40188567416988e-05    9.23712372650668e-01
0.525   -8.54071566781730e-01    6.64718801721132e-04    8.54736285583451e-01
 0.55   -7.00794266428659e-01    1.29838915250327e-03    7.02092655581163e-01
0.575   -4.78918340556343e-01    1.80496412662922e-03    4.80723304682973e-01
  0.6   -2.10162550690008e-01    2.13485663611614e-03    2.12297407326124e-01
0.625    7.91654139259427e-02    2.25577450363920e-03   -7.69096394223035e-02
 0.65    3.60744116256481e-01    2.15588144584090e-03   -3.58588234810640e-01
0.675    6.07010670935424e-01    1.84495569121442e-03   -6.05165715244210e-01
  0.7    7.93858793075645e-01    1.35343281896972e-03   -7.92505360256676e-01
0.725    9.02998471787475e-01    7.29426512483309e-04   -9.02269045274992e-01
 0.75    9.23746506080844e-01    3.40188567416989e-05   -9.23712487224102e-01
0.775    8.54070542118058e-01   -6.64718801720993e-04   -8.54735260919779e-01
  0.8    7.00802463269192e-01   -1.29838915249082e-03   -7.02100852421683e-01
0.825    4.78860145174661e-01   -1.80496412572876e-03   -4.80665109300390e-01
 0.85    2.10526001960841e-01   -2.13485659553884e-03   -2.12660858556380e-01
0.875   -8.11423699138815e-02   -2.25577335943143e-03    7.88865965544500e-02
  0.9   -3.51476574545122e-01   -2.15586099443615e-03    3.49320713550686e-01
0.925   -6.44091074593528e-01   -1.84471993388145e-03    6.42246354659647e-01
 0.95   -6.67909801165711e-01   -1.35163898679403e-03    6.66558162178917e-01
0.975   -1.26810099945739e+00   -7.20138727829358e-04    1.26738086072956e+00
    1    0.00000000000000e+00   -1.14739460755934e-18   -1.14739460755934e-18

# K=40 N=600 T=0.06 A=2 nu=0.01
# dx=0.025 dt=0.0001 R=0.004 rho=0.0016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025   -2.76735708309760e-03    6.74482781277200e-04    3.44183986437480e-03
 0.05   -1.30478218829001e-02    1.30037164365576e-03    1.43481935265559e-02
0.075    1.41859209161105e-04    1.80523803757166e-03    1.66337882841055e-03
  0.1    7.63954479361775e-02    2.13488161551833e-03   -7.42605663206591e-02
0.125    2.25856801736794e-01    2.25577597283107e-03   -2.23601025763963e-01
 0.15    4.23066987373473e-01    2.15588150061455e-03   -4.20911105872858e-01
0.175    6.25282987900664e-01    1.84495569249225e-03   -6.23438032208172e-01
  0.2    7.91482476779465e-01    1.35343281898829e-03   -7.90129043960477e-01
0.225    8.91797039054137e-01    7.29426512483536e-04   -8.91067612541654e-01
 0.25    9.09453674552235e-01    3.40188567416987e-05   -9.09419655695493e-01
0.275    8.39729524385699e-01   -6.64718801721162e-04   -8.40394243187421e-01

  0.3    6.88329317940860e-01   -1.29838915250333e-03   -6.89627707093363e-01
0.325    4.69701467999588e-01   -1.80496412662929e-03   -4.71506432126217e-01
 0.35    2.05135825078686e-01   -2.13485663611623e-03   -2.07270681714803e-01
0.375   -7.95002274554946e-02   -2.25577450363929e-03    7.72444529518553e-02
  0.4   -3.56352047205362e-01   -2.15588144584100e-03    3.54196165759521e-01
0.425   -5.98321182466988e-01   -1.84495569121451e-03    5.96476226775773e-01
 0.45   -7.81722380109942e-01   -1.35343281896978e-03    7.80368947290973e-01
0.475   -8.88603127598654e-01   -7.29426512483346e-04    8.87873701086171e-01
  0.5   -9.08501206712875e-01   -3.40188567416988e-05    9.08467187856133e-01
0.525   -8.39468857318638e-01    6.64718801721132e-04    8.40133576120359e-01
 0.55   -6.88263447168534e-01    1.29838915250327e-03    6.89561836321038e-01
0.575   -4.69686015384469e-01    1.80496412662922e-03    4.71490979511099e-01
  0.6   -2.05132443917802e-01    2.13485663611614e-03    2.07267300553918e-01
0.625    7.95009203991104e-02    2.25577450363920e-03   -7.72451458954712e-02
 0.65    3.56352180739905e-01    2.15588144584090e-03   -3.54196299294064e-01
0.675    5.98321206476518e-01    1.84495569121442e-03   -5.96476250785304e-01
  0.7    7.81722386810874e-01    1.35343281896972e-03   -7.80368953991904e-01
0.725    8.88603104926141e-01    7.29426512483309e-04   -8.87873678413657e-01
 0.75    9.08501405923523e-01    3.40188567416989e-05   -9.08467387066781e-01
0.775    8.39467299462450e-01   -6.64718801720993e-04   -8.40132018264171e-01
  0.8    6.88274555267422e-01   -1.29838915249082e-03   -6.89572944419912e-01
0.825    4.69614415704568e-01   -1.80496412572876e-03   -4.71419379830297e-01
 0.85    2.05545835396506e-01   -2.13485659553884e-03   -2.07680691992045e-01
0.875   -8.16169719966392e-02   -2.25577335943143e-03    7.93611986372078e-02
  0.9   -3.46854571703070e-01   -2.15586099443615e-03    3.44698710708634e-01
0.925   -6.35304742048683e-01   -1.84471993388145e-03    6.33460022114802e-01
 0.95   -6.57703187800303e-01   -1.35163898679403e-03    6.56351548813509e-01
0.975   -1.24718948552957e+00   -7.20138727829358e-04    1.24646934680174e+00
    1    0.00000000000000e+00   -1.14739460755934e-18   -1.14739460755934e-18

# K=40 N=100 T=0.1 A=2 nu=0.01
# dx=0.025 dt=0.001 R=0.04 rho=0.016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    3.60751546065551e-04    1.14507808794966e-05   -3.49300765186055e-04
 0.05    2.27596215346268e-03    2.21408302683046e-05   -2.25382132319437e-03
0.075   -2.19847835154666e-04    3.08452524794874e-05    2.50693087634153e-04
  0.1   -1.15896308264578e-02    3.66012401000233e-05    1.16262320665578e-02
0.125   -1.96346959010294e-02    3.87956697613830e-05    1.96734915707908e-02
 0.15    3.46476573449652e-03    3.71973461843038e-05   -3.42756838831221e-03
0.175    8.26100545044820e-02    3.19587216849241e-05   -8.25780957827971e-02
  0.2    2.22249038170805e-01    2.35918633298297e-05   -2.22225446307475e-01
0.225    4.03226281327381e-01    1.29156796091483e-05   -4.03213365647771e-01
 0.25    5.91956900459210e-01    9.75219953555280e-07   -5.91955925239257e-01
0.275    7.52663785062320e-01   -1.10607009836022e-05   -7.52674845763303e-01
  0.3    8.56153624979782e-01   -2.20139234423312e-05   -8.56175638903224e-01
0.325    8.83837058854760e-01   -3.08122696944493e-05   -8.83867871124455e-01
 0.35    8.28485258402670e-01   -3.65944963071668e-05   -8.28521852898977e-01
0.375    6.93405192908746e-01   -3.87945986524906e-05   -6.93443987507398e-01
  0.4    4.90941080056996e-01   -3.71972153838459e-05   -4.90978277272380e-01
0.425    2.40581940147234e-01   -3.19587095051914e-05   -2.40613898856739e-01
 0.45   -3.32779254423097e-02   -2.35918624707464e-05    3.32543335798390e-02
0.475   -3.03866489601200e-01   -1.29156795634936e-05    3.03853573921637e-01
  0.5   -5.44706861841828e-01   -9.75219951735159e-07    5.44705886621876e-01

0.525   -7.32226644737041e-01    1.10607009836560e-05    7.32237705438025e-01
 0.55   -8.48070778705660e-01    2.20139234423315e-05    8.48092792629103e-01
0.575   -8.80899792260996e-01    3.08122696944480e-05    8.80930604530690e-01
  0.6   -8.27500187549985e-01    3.65944963071652e-05    8.27536782046292e-01
0.625   -6.93099098408899e-01    3.87945986524889e-05    6.93137893007551e-01
 0.65   -4.90852631282371e-01    3.71972153838442e-05    4.90889828497755e-01
0.675   -2.40558151054139e-01    3.19587095051899e-05    2.40590109763644e-01
  0.7    3.32842463001241e-02    2.35918624707460e-05   -3.32606544376534e-02
0.725    3.03866080142089e-01    1.29156795635242e-05   -3.03853164462526e-01
 0.75    5.44717055042780e-01    9.75219952839121e-07   -5.44716079822827e-01
0.775    7.32178247598187e-01   -1.10607009545449e-05   -7.32189308299142e-01
  0.8    8.48285855603224e-01   -2.20139228664701e-05   -8.48307869526090e-01
0.825    8.80041589647625e-01   -3.08122611115345e-05   -8.80072401908737e-01
 0.85    8.30563175352486e-01   -3.65943994078017e-05   -8.30599769751894e-01
0.875    6.83361973167794e-01   -3.87937644720436e-05   -6.83400766932266e-01
  0.9    5.18378150585345e-01   -3.71916940332391e-05   -5.18415342279378e-01
0.925    1.71233442182747e-01   -3.19303209590219e-05   -1.71265372503706e-01
 0.95    1.22902202524302e-01   -2.34770324260008e-05   -1.22925679556728e-01
0.975   -6.17833966434710e-01   -1.25446240886633e-05    6.17821421810621e-01
    1    0.00000000000000e+00   -2.01080853901805e-20   -2.01080853901805e-20

# K=40 N=1000 T=0.1 A=2 nu=0.01
# dx=0.025 dt=0.0001 R=0.004 rho=0.0016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    4.57483064188449e-04    1.14507808794966e-05   -4.46032283308952e-04
 0.05    1.65736351688063e-03    2.21408302683046e-05   -1.63522268661233e-03
0.075   -1.61831889870745e-03    3.08452524794874e-05    1.64916415118694e-03
  0.1   -1.10076517826551e-02    3.66012401000233e-05    1.10442530227551e-02
0.125   -1.33155133096975e-02    3.87956697613830e-05    1.33543089794589e-02
 0.15    1.62870053830123e-02    3.71973461843038e-05   -1.62498080368280e-02
0.175    9.82934713826226e-02    3.19587216849241e-05   -9.82615126609377e-02
  0.2    2.34998845295275e-01    2.35918633298297e-05   -2.34975253431945e-01
0.225    4.08348186294659e-01    1.29156796091483e-05   -4.08335270615050e-01
 0.25    5.87584810723574e-01    9.75219953555280e-07   -5.87583835503620e-01
0.275    7.39606314445531e-01   -1.10607009836022e-05   -7.39617375146514e-01
  0.3    8.36846572786573e-01   -2.20139234423312e-05   -8.36868586710015e-01
0.325    8.61333488438590e-01   -3.08122696944493e-05   -8.61364300708284e-01
 0.35    8.05824951262833e-01   -3.65944963071668e-05   -8.05861545759140e-01
0.375    6.73298199285116e-01   -3.87945986524906e-05   -6.73336993883768e-01
  0.4    4.75604420578336e-01   -3.71972153838459e-05   -4.75641617793719e-01
0.425    2.31628278488035e-01   -3.19587095051914e-05   -2.31660237197540e-01
 0.45   -3.49271908967726e-02   -2.35918624707464e-05    3.49035990343019e-02
0.475   -2.98033366072985e-01   -1.29156795634936e-05    2.98020450393422e-01
  0.5   -5.31956722486831e-01   -9.75219951735159e-07    5.31955747266880e-01
0.525   -7.13805795127301e-01    1.10607009836560e-05    7.13816855828284e-01
 0.55   -8.25781860688862e-01    2.20139234423315e-05    8.25803874612305e-01
0.575   -8.56924457245383e-01    3.08122696944480e-05    8.56955269515078e-01
  0.6   -8.04185270977713e-01    3.65944963071652e-05    8.04221865474020e-01
0.625   -6.72726818665235e-01    3.87945986524889e-05    6.72765613263887e-01
 0.65   -4.75417160642466e-01    3.71972153838442e-05    4.75454357857850e-01
0.675   -2.31570454254425e-01    3.19587095051899e-05    2.31602412963930e-01
  0.7    3.49445561458448e-02    2.35918624707460e-05   -3.49209642833740e-02
0.725    2.98035757894370e-01    1.29156795635242e-05   -2.98022842214807e-01

 0.75    5.31969592846141e-01    9.75219952839121e-07   -5.31968617626188e-01
0.775    7.13752302619943e-01   -1.10607009545449e-05   -7.13763363320897e-01
  0.8    8.26009620942493e-01   -2.20139228664701e-05   -8.26031634865359e-01
0.825    8.56048488392254e-01   -3.08122611115345e-05   -8.56079300653366e-01
 0.85    8.07232069705842e-01   -3.65943994078017e-05   -8.07268664105250e-01
0.875    6.63192876712722e-01   -3.87937644720436e-05   -6.63231670477194e-01
  0.9    5.02175767741027e-01   -3.71916940332391e-05   -5.02212959435060e-01
0.925    1.64243075024821e-01   -3.19303209590219e-05   -1.64275005345780e-01
 0.95    1.17034515521942e-01   -2.34770324260008e-05   -1.17057992554368e-01
0.975   -6.04151036834756e-01   -1.25446240886633e-05    6.04138492210668e-01
    1    0.00000000000000e+00   -2.01080853901805e-20   -2.01080853901805e-20

# K=40 N=900 T=0.9 A=2 nu=0.01
# dx=0.025 dt=0.001 R=0.04 rho=0.016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    1.84985662554915e-15    5.69176277006497e-41   -1.84985662554915e-15
 0.05   -7.90716713626364e-15    1.11340650376665e-40    7.90716713626364e-15
0.075    2.87615393814742e-15    1.58017751053719e-40   -2.87615393814742e-15
  0.1   -5.56174322549976e-15    1.92263668825717e-40    5.56174322549976e-15
0.125    8.72665830375415e-14    2.10464432075706e-40   -8.72665830375415e-14
 0.15   -1.97601518388646e-13    2.10483169779242e-40    1.97601518388646e-13
0.175    1.87593333226661e-13    1.91919224298881e-40   -1.87593333226661e-13
  0.2   -4.70767977513962e-13    1.56189542823066e-40    4.70767977513962e-13
0.225    1.59445669413877e-12    1.06421154639127e-40   -1.59445669413877e-12
 0.25   -2.50190115111478e-12    4.71644314004358e-41    2.50190115111478e-12
0.275    2.72491078449753e-12   -1.60437102664431e-41   -2.72491078449753e-12
  0.3   -6.30934969206897e-12   -7.72216104333435e-41    6.30934969206897e-12
0.325    1.27304097943712e-11   -1.30533871696575e-40   -1.27304097943712e-11
 0.35   -1.04251829002714e-11   -1.70871084303654e-40    1.04251829002714e-11
0.375    5.29984151708115e-12   -1.94359402177743e-40   -5.29984151708115e-12
  0.4   -1.70621253080506e-11   -1.98748635243617e-40    1.70621253080506e-11
0.425    1.13526502639279e-12   -1.83640058601396e-40   -1.13526502639279e-12
 0.45    8.09360288905410e-11   -1.50531340252608e-40   -8.09360288905410e-11
0.475   -9.92920503554501e-11   -1.02674229618592e-40    9.92920503554501e-11
  0.5    6.33927560215971e-11   -4.47591518289244e-41   -6.33927560215971e-11
0.525   -2.47379696920964e-10    1.75421591516285e-41    2.47379696920964e-10
 0.55    2.18741042264656e-10    7.81310041861009e-41   -2.18741042264656e-10
0.575    5.58813447742500e-10    1.31078661081580e-40   -5.58813447742500e-10
  0.6   -7.08522570454663e-10    1.71207503603697e-40    7.08522570454663e-10
0.625    3.73907482914940e-10    1.94599559343500e-40   -3.73907482914940e-10
 0.65   -2.23088994590210e-09    1.98982993595506e-40    2.23088994590210e-09
0.675    1.10377126427539e-09    1.83959037602844e-40   -1.10377126427539e-09
  0.7    6.12480707887974e-09    1.51047496818956e-40   -6.12480707887974e-09
0.725   -4.41536004699204e-09    1.03546593743996e-40    4.41536004699204e-09
 0.75    2.53284247981476e-09    4.62207356998431e-41   -2.53284247981476e-09
0.775   -1.52649394448943e-08   -1.51539394551704e-41    1.52649394448943e-08
  0.8   -1.70531317052818e-08   -7.43432877196221e-41    1.70531317052818e-08
0.825    5.89944605206133e-08   -1.25256468927404e-40   -5.89944605206133e-08
 0.85    4.39923795754995e-09   -1.62539465301124e-40   -4.39923795754995e-09
0.875    1.01802768093377e-08   -1.82106858894987e-40   -1.01802768093377e-08
  0.9    3.23728802457661e-09   -1.81563981832394e-40   -3.23728802457661e-09
0.925   -3.50076814542272e-07   -1.60481333543321e-40    3.50076814542272e-07
 0.95    6.51048631759363e-08   -1.20495500508405e-40   -6.51048631759363e-08

0.975    4.84945305516637e-07   -6.52245490673213e-41   -4.84945305516637e-07
    1    0.00000000000000e+00   -1.06147935096202e-55   -1.06147935096202e-55

# K=40 N=9000 T=0.9 A=2 nu=0.01
# dx=0.025 dt=0.0001 R=0.004 rho=0.0016
#  xk                      uk                      vk                   vk-uk
    0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.025    6.37880293192940e-16    5.69176277006497e-41   -6.37880293192940e-16
 0.05   -3.05180547784293e-15    1.11340650376665e-40    3.05180547784293e-15
0.075    9.53159648881081e-15    1.58017751053719e-40   -9.53159648881081e-15
  0.1   -2.06172359349070e-14    1.92263668825717e-40    2.06172359349070e-14
0.125    4.49155417022674e-14    2.10464432075706e-40   -4.49155417022674e-14
 0.15   -1.27170874497623e-13    2.10483169779242e-40    1.27170874497623e-13
0.175    2.91223949643237e-13    1.91919224298881e-40   -2.91223949643237e-13
  0.2   -5.54334424933615e-13    1.56189542823066e-40    5.54334424933615e-13
0.225    1.12015865028539e-12    1.06421154639127e-40   -1.12015865028539e-12
 0.25   -2.36793527702918e-12    4.71644314004358e-41    2.36793527702918e-12
0.275    4.31513048497107e-12   -1.60437102664431e-41   -4.31513048497107e-12
  0.3   -7.06927511202427e-12   -7.72216104333435e-41    7.06927511202427e-12
0.325    1.20819515777097e-11   -1.30533871696575e-40   -1.20819515777097e-11
 0.35   -1.96459457825331e-11   -1.70871084303654e-40    1.96459457825331e-11
0.375    2.58956128671561e-11   -1.94359402177743e-40   -2.58956128671561e-11
  0.4   -3.00870750098630e-11   -1.98748635243617e-40    3.00870750098630e-11
0.425    3.44939206100727e-11   -1.83640058601396e-40   -3.44939206100727e-11
 0.45   -2.01730735777953e-11   -1.50531340252608e-40    2.01730735777953e-11
0.475   -3.43035490997512e-11   -1.02674229618592e-40    3.43035490997512e-11
  0.5    9.70722347858007e-11   -4.47591518289244e-41   -9.70722347858007e-11
0.525   -1.67629452270044e-10    1.75421591516285e-41    1.67629452270044e-10
 0.55    3.09242889817446e-10    7.81310041861009e-41   -3.09242889817446e-10
0.575   -3.27416593742614e-10    1.31078661081580e-40    3.27416593742614e-10
  0.6   -2.43783791425553e-11    1.71207503603697e-40    2.43783791425553e-11
0.625    3.68018738664143e-10    1.94599559343500e-40   -3.68018738664143e-10
 0.65   -8.36580752430367e-10    1.98982993595506e-40    8.36580752430367e-10
0.675    2.11176392167967e-09    1.83959037602844e-40   -2.11176392167967e-09
  0.7   -1.75020630951350e-09    1.51047496818956e-40    1.75020630951350e-09
0.725   -1.45392903845798e-09    1.03546593743996e-40    1.45392903845798e-09
 0.75    2.57610114619530e-09    4.62207356998431e-41   -2.57610114619530e-09
0.775   -6.26095637242355e-09   -1.51539394551704e-41    6.26095637242355e-09
  0.8    1.33161978308293e-08   -7.43432877196221e-41   -1.33161978308293e-08
0.825    3.90237834018097e-09   -1.25256468927404e-40   -3.90237834018097e-09
 0.85   -2.34615533728966e-08   -1.62539465301124e-40    2.34615533728966e-08
0.875    1.27951854272766e-08   -1.82106858894987e-40   -1.27951854272766e-08
  0.9   -4.84169976329102e-08   -1.81563981832394e-40    4.84169976329102e-08
0.925    6.90213163557153e-09   -1.60481333543321e-40   -6.90213163557153e-09
 0.95    1.80478096887369e-07   -1.20495500508405e-40   -1.80478096887369e-07
0.975   -4.13670845659603e-08   -6.52245490673213e-41    4.13670845659603e-08
    1    0.00000000000000e+00   -1.06147935096202e-55   -1.06147935096202e-55

Note that in order to verify the answers with K = 40 one needs also to decrease the Δt time steps.

7. [Thomas Problem 1.5.7] Solve the following initial boundary value problem

v_{t} = νv_{xx} + F (x, t), for x ∈ (0, 1) and t > 0
v(x, 0) = f(x),  for x ∈ [0, 1]
v(0, t) = a(t),  for t ≥ 0
v(1, t) = b(t),  for t ≥ 0

where ν = 0.1, f(x) = 0, a(t) = b(t) = 0 and F (x, t) = sin(2πx) sin(4πt). Use K = 10 and Δt = 0.05 and find solutions at t = 0.1, t = 0.9 and t = 2.0. Resolve the problem in the above choice of parameters using K = 20 and Δt = 0.01.

First we derive the exact solution. Following the techniques used in Problem 1.2.1 let X_{n}(x) = sin(nπx) and λ_{n} = −n^{2}π^{2} and write

v(x, t) = ∑_{n∈N} T_{n}(t)X_{n}(x).

Plugging this into the differential equations yields

∑_{n∈N} T′_{n}(t)X_{n}(x) = ∑_{n∈N} νλ_{n}T_{n}(t)X_{n}(x) + sin(4πt)X_{2}(x).

Therefore

\{ \begin{matrix}T′_{n}(t) = νλ_{n}T_{n}(t) & for n ≠ 2 \\ T′_{2}(t) = νλ_{2}T_{2}(t) + sin(4πt) & for n = 2. \end{matrix}

Solution for T_{n}(t) when n ≠ 2 is the same as in Problem 1.2.1. When n = 2 we procede as follows:

\frac{d}{dt}(T_{2}(t) exp(−νλ_{2}t)) = sin(4πt) exp(−νλ_{2}t).

Therefore

T_{2}(t) exp(−νλ_{2}t) − T_{2}(0) = ∫_{0}^{t} sin(4πs) exp(−νλ_{2}s) ds

= \frac{1 − (cos(4πt) − νπ sin(4πt)) exp(ν4π^{2}t)}{4π(ν^{2}π^{2} + 1)}.

It follows that

T_{n}(t) = T_{n}(0) exp(−νn^{2}π^{2}t)  for n ≠ 2
T_{2}(t) = T_{2}(0) exp(−ν4π^{2}t) + \frac{exp(−ν4π^{2}t) − cos(4πt) + νπ sin(4πt)}{4π(ν^{2}π^{2} + 1)} for n = 2.

Solving for the initial condition

∑_{n∈N} T_{n}(0) sin(nπx) = 0.

yields than T_{n}(0) = 0 for all n. Therefore the solution is

v(x, t) = \frac{exp(−ν4π^{2}t) − cos(4πt) + νπ sin(4πt)}{4π(ν^{2}π^{2} + 1)} sin(2πx).

Integrating both sides of the equation from t_{n} to t_{n+1} yields

v(x, t_{n+1}) = v(x, t_{n}) + ∫_{t_{n}}^{t_{n+1}} (νv_{xx}(x, s) + F (x, s)) ds

Approximating integral using the left endpoint yields

v(x, t_{n+1}) ≈ v(x, t_{n}) + Δt(νv_{xx}(x, t_{n}) + F (x, t_{n}))

and the explicit method

u_{k}^{n+1} = u_{k}^{n} + Rδ^{2}u_{k}^{n} + F (x_{k}, t_{n}).

Alternatively, for better accuracy, we can approximate the second term in the intergral using the midpoint method. This yields an explicit scheme of the form

u_{k}^{n+1} = u_{k}^{n} + Rδ^{2}u_{k}^{n} + F (x_{k}, t_{n+1/2}).

The program is

 1 /*  prog7.c -- Thomas Problem 1.5.7
 2  Written May 2013 by Eric Olson */

3

 4 #include <stdio.h>
 5 #include <math.h>
 6 #define NU 0.1

7

 8 double dt,dx,R,rho;

9

10 double v(double x,double t){
11  return (exp(-NU*4*M_PI*M_PI*t)
12  -cos(4*M_PI*t)+NU*M_PI*sin(4*M_PI*t))
13  /(4*M_PI*(NU*NU*M_PI*M_PI+1))*sin(2*M_PI*x);

14 }

15

16 double F(double x,double t){
17  return sin(2*M_PI*x)*sin(4*M_PI*t);

18 }

19 double f(double x){
20  return 0;

21 }

22 void doinit(int K,double u[K+1]){
23  int k;

24  for(k=0;k<=K;k++){
25  double xk=k*dx;
26  u[k]=f(xk);

27 } 28 }

29 void doprint(int K,double u[K+1],double tn){
30  int k;
31  printf("#%4s %23s %23s %23s\n","xk","uk","vk","vk-uk");
32  for(k=0;k<=K;k++){
33  double xk=k*dx;
34  double vk=v(xk,tn);
35  printf("%5g %23.14e %23.14e %23.14e\n",xk,u[k],vk,vk-u[k]);

36 } 37 }

38 void dosolve(int K,double u[K+1],int N,double T){
39  int n;
40  printf("# SCHEME=Left\n");
41  for(n=0;;n++){
42  double tn=n*dt;
43  u[0]=0; u[K]=0;
44  if(n>=N) break;
45  int k;
46  double w[K+1];
47  for(k=1;k<K;k++) {
48  double xk=k*dx;
49  w[k]=rho*(u[k+1]-2*u[k]+u[k-1])+dt*F(xk,tn);

50 }

51  for(k=1;k<K;k++) u[k]+=w[k];

52 } 53 }

54 void dosolvemp(int K,double u[K+1],int N,double T){
55  int n;
56  printf("# SCHEME=Midpoint\n");
57  for(n=0;;n++){
58  double tn=n*dt;
59  u[0]=0; u[K]=0;
60  if(n>=N) break;
61  int k;
62  double w[K+1];
63  for(k=1;k<K;k++) {
64  double xk=k*dx;
65  w[k]=rho*(u[k+1]-2*u[k]+u[k-1])+dt*F(xk,tn+dt/2);

66 }

67  for(k=1;k<K;k++) u[k]+=w[k];

68 }

70 main(){
71  printf("# prog7 -- Thomas Problem 1.5.7\n"
72  "# Written May 2013 by Eric Olson\n#\n");
73  int KK[]={10,10,10,20,20,20};
74  double TT[]={0.1,0.9,2.0,0.1,0.9,2.0};
75  int NN[]={2,18,40,10,90,200};
76  int J=sizeof(TT)/sizeof(double);
77  int j;
78  for(j=0;j<J;j++){
79  int K=KK[j],N=NN[j];
80  double T=TT[j],u[K+1];
81  dx=1.0/K; dt=T/N;
82  rho=NU*dt/dx/dx;
83  printf("#\tK=%d N=%d T=%g NU=%g\n"
84  "#\tdx=%g dt=%g rho=%g\n",
85  K,N,T,NU,dx,dt,rho);
86  doinit(K,u);
87  dosolve(K,u,N,T);
88  doprint(K,u,T);
89  printf("\n\n");
90  printf("#\tK=%d N=%d T=%g NU=%g\n"
91  "#\tdx=%g dt=%g rho=%g\n",
92  K,N,T,NU,dx,dt,rho);
93  doinit(K,u);
94  dosolvemp(K,u,N,T);
95  doprint(K,u,T);
96  printf("\n\n");

97 }

98  return 0;

99 }

The output is

   # prog7 -- Thomas Problem 1.5.7
   # Written May 2013 by Eric Olson
   #
   # K=10 N=2 T=0.1 NU=0.1
   # dx=0.1 dt=0.05 rho=0.5
   # SCHEME=Left
   #  xk                      uk                      vk                   vk-uk
       0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
     0.1    1.72745751406263e-02    2.82508935294770e-02    1.09763183888507e-02
     0.2    2.79508497187474e-02    4.57109059432483e-02    1.77600562245009e-02
     0.3    2.79508497187474e-02    4.57109059432483e-02    1.77600562245009e-02
     0.4    1.72745751406263e-02    2.82508935294770e-02    1.09763183888507e-02
     0.5    3.59902777320226e-18    5.88586113421955e-18    2.28683336101730e-18
     0.6   -1.72745751406263e-02   -2.82508935294770e-02   -1.09763183888507e-02
     0.7   -2.79508497187474e-02   -4.57109059432483e-02   -1.77600562245009e-02

0.8   -2.79508497187474e-02   -4.57109059432483e-02   -1.77600562245009e-02
0.9   -1.72745751406263e-02   -2.82508935294770e-02   -1.09763183888507e-02
  1    0.00000000000000e+00   -1.17717222684391e-17   -1.17717222684391e-17

# K=10 N=2 T=0.1 NU=0.1
# dx=0.1 dt=0.05 rho=0.5
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.1    3.11237285610348e-02    2.82508935294770e-02   -2.87283503155776e-03
0.2    5.03592506683801e-02    4.57109059432483e-02   -4.64834472513182e-03
0.3    5.03592506683801e-02    4.57109059432483e-02   -4.64834472513182e-03
0.4    3.11237285610348e-02    2.82508935294770e-02   -2.87283503155776e-03
0.5    4.08612428990798e-18    5.88586113421955e-18    1.79973684431158e-18
0.6   -3.11237285610348e-02   -2.82508935294770e-02    2.87283503155775e-03
0.7   -5.03592506683801e-02   -4.57109059432483e-02    4.64834472513183e-03
0.8   -5.03592506683801e-02   -4.57109059432483e-02    4.64834472513183e-03
0.9   -3.11237285610348e-02   -2.82508935294770e-02    2.87283503155776e-03
  1    0.00000000000000e+00   -1.17717222684391e-17   -1.17717222684391e-17

# K=10 N=18 T=0.9 NU=0.1
# dx=0.1 dt=0.05 rho=0.5
# SCHEME=Left
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.1   -1.43487837117188e-02   -2.46565476862823e-02   -1.03077639745635e-02
0.2   -2.32168197427819e-02   -3.98951322016374e-02   -1.66783124588554e-02
0.3   -2.32168197427819e-02   -3.98951322016374e-02   -1.66783124588554e-02
0.4   -1.43487837117188e-02   -2.46565476862823e-02   -1.03077639745635e-02
0.5   -9.29281593288540e-18   -5.13700621820321e-18    4.15580971468219e-18
0.6    1.43487837117188e-02    2.46565476862823e-02    1.03077639745635e-02
0.7    2.32168197427819e-02    3.98951322016374e-02    1.66783124588554e-02
0.8    2.32168197427819e-02    3.98951322016374e-02    1.66783124588554e-02
0.9    1.43487837117188e-02    2.46565476862823e-02    1.03077639745635e-02
  1    0.00000000000000e+00    1.02740124364064e-17    1.02740124364064e-17

# K=10 N=18 T=0.9 NU=0.1
# dx=0.1 dt=0.05 rho=0.5
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.1   -2.83411355572518e-02   -2.46565476862823e-02    3.68458787096949e-03
0.2   -4.58569206114016e-02   -3.98951322016374e-02    5.96178840976424e-03
0.3   -4.58569206114016e-02   -3.98951322016374e-02    5.96178840976425e-03
0.4   -2.83411355572518e-02   -2.46565476862823e-02    3.68458787096949e-03
0.5   -1.30619518481369e-17   -5.13700621820321e-18    7.92494562993373e-18
0.6    2.83411355572518e-02    2.46565476862823e-02   -3.68458787096949e-03
0.7    4.58569206114016e-02    3.98951322016374e-02   -5.96178840976424e-03
0.8    4.58569206114016e-02    3.98951322016374e-02   -5.96178840976425e-03
0.9    2.83411355572518e-02    2.46565476862823e-02   -3.68458787096949e-03
  1    0.00000000000000e+00    1.02740124364064e-17    1.02740124364064e-17

# K=10 N=40 T=2 NU=0.1
# dx=0.1 dt=0.05 rho=0.5
# SCHEME=Left
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.1   -4.99895941924932e-02   -4.25568546447194e-02    7.43273954777381e-03
0.2   -8.08848624872684e-02   -6.88584372694449e-02    1.20264252178236e-02
0.3   -8.08848624872684e-02   -6.88584372694449e-02    1.20264252178236e-02
0.4   -4.99895941924933e-02   -4.25568546447194e-02    7.43273954777382e-03
0.5   -7.06764291188987e-18   -8.86640050823986e-18   -1.79875759634999e-18
0.6    4.99895941924933e-02    4.25568546447194e-02   -7.43273954777381e-03
0.7    8.08848624872684e-02    6.88584372694449e-02   -1.20264252178236e-02
0.8    8.08848624872684e-02    6.88584372694449e-02   -1.20264252178236e-02
0.9    4.99895941924933e-02    4.25568546447194e-02   -7.43273954777381e-03
  1    0.00000000000000e+00    1.77328010164797e-17    1.77328010164797e-17

# K=10 N=40 T=2 NU=0.1
# dx=0.1 dt=0.05 rho=0.5
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.1   -4.75429293037211e-02   -4.25568546447194e-02    4.98607465900163e-03
0.2   -7.69260755381541e-02   -6.88584372694449e-02    8.06763826870918e-03
0.3   -7.69260755381541e-02   -6.88584372694449e-02    8.06763826870918e-03
0.4   -4.75429293037211e-02   -4.25568546447194e-02    4.98607465900163e-03
0.5   -1.89213925526808e-18   -8.86640050823986e-18   -6.97426125297178e-18
0.6    4.75429293037211e-02    4.25568546447194e-02   -4.98607465900162e-03
0.7    7.69260755381541e-02    6.88584372694449e-02   -8.06763826870918e-03
0.8    7.69260755381541e-02    6.88584372694449e-02   -8.06763826870920e-03
0.9    4.75429293037211e-02    4.25568546447194e-02   -4.98607465900162e-03
  1    0.00000000000000e+00    1.77328010164797e-17    1.77328010164797e-17

# K=20 N=10 T=0.1 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Left
#  xk                      uk                      vk                   vk-uk
  0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05    1.39026556150158e-02    1.48523736736112e-02    9.49718058595349e-04
0.1    2.64444224329364e-02    2.82508935294770e-02    1.80647109654057e-03
0.15    3.63976249339960e-02    3.88840190911282e-02    2.48639415713219e-03
0.2    4.27879743093513e-02    4.57109059432483e-02    2.92293163389695e-03
0.25    4.49899386379604e-02    4.80632908350341e-02    3.07335219707367e-03
0.3    4.27879743093513e-02    4.57109059432483e-02    2.92293163389695e-03
0.35    3.63976249339960e-02    3.88840190911282e-02    2.48639415713219e-03
0.4    2.64444224329364e-02    2.82508935294770e-02    1.80647109654058e-03
0.45    1.39026556150158e-02    1.48523736736112e-02    9.49718058595351e-04
0.5   -3.52638561434571e-19    5.88586113421955e-18    6.23849969565412e-18
0.55   -1.39026556150158e-02   -1.48523736736112e-02   -9.49718058595356e-04
0.6   -2.64444224329364e-02   -2.82508935294770e-02   -1.80647109654058e-03
0.65   -3.63976249339960e-02   -3.88840190911282e-02   -2.48639415713218e-03
0.7   -4.27879743093513e-02   -4.57109059432483e-02   -2.92293163389695e-03
0.75   -4.49899386379604e-02   -4.80632908350341e-02   -3.07335219707368e-03

 0.8   -4.27879743093513e-02   -4.57109059432483e-02   -2.92293163389695e-03
0.85   -3.63976249339960e-02   -3.88840190911282e-02   -2.48639415713218e-03
 0.9   -2.64444224329364e-02   -2.82508935294770e-02   -1.80647109654059e-03
0.95   -1.39026556150158e-02   -1.48523736736112e-02   -9.49718058595356e-04
   1    0.00000000000000e+00   -1.17717222684391e-17   -1.17717222684391e-17

# K=20 N=10 T=0.1 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00    0.00000000000000e+00    0.00000000000000e+00
0.05    1.51297961830220e-02    1.48523736736112e-02   -2.77422509410789e-04
 0.1    2.87785825001612e-02    2.82508935294770e-02   -5.27688970684174e-04
0.15    3.96103206500099e-02    3.88840190911282e-02   -7.26301558881731e-04
 0.2    4.65647246333037e-02    4.57109059432483e-02   -8.53818690055436e-04
0.25    4.89610489339759e-02    4.80632908350341e-02   -8.97758098941888e-04
 0.3    4.65647246333037e-02    4.57109059432483e-02   -8.53818690055436e-04
0.35    3.96103206500099e-02    3.88840190911282e-02   -7.26301558881731e-04
 0.4    2.87785825001612e-02    2.82508935294770e-02   -5.27688970684170e-04
0.45    1.51297961830220e-02    1.48523736736112e-02   -2.77422509410787e-04
 0.5   -1.58935183328642e-19    5.88586113421955e-18    6.04479631754820e-18
0.55   -1.51297961830220e-02   -1.48523736736112e-02    2.77422509410780e-04
 0.6   -2.87785825001612e-02   -2.82508935294770e-02    5.27688970684163e-04
0.65   -3.96103206500099e-02   -3.88840190911282e-02    7.26301558881738e-04
 0.7   -4.65647246333037e-02   -4.57109059432483e-02    8.53818690055436e-04
0.75   -4.89610489339759e-02   -4.80632908350341e-02    8.97758098941888e-04
 0.8   -4.65647246333037e-02   -4.57109059432483e-02    8.53818690055429e-04
0.85   -3.96103206500099e-02   -3.88840190911282e-02    7.26301558881745e-04
 0.9   -2.87785825001612e-02   -2.82508935294770e-02    5.27688970684163e-04
0.95   -1.51297961830220e-02   -1.48523736736112e-02    2.77422509410782e-04
   1    0.00000000000000e+00   -1.17717222684391e-17   -1.17717222684391e-17

# K=20 N=90 T=0.9 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Left
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.05   -1.20424883029356e-02   -1.29627142361276e-02   -9.20225933192017e-04
 0.1   -2.29061739458302e-02   -2.46565476862823e-02   -1.75037374045211e-03
0.15   -3.15276436862085e-02   -3.39368264566343e-02   -2.40918277042579e-03
 0.2   -3.70629679965706e-02   -3.98951322016374e-02   -2.83216420506681e-03
0.25   -3.89703107665458e-02   -4.19482244410133e-02   -2.97791367446755e-03
 0.3   -3.70629679965706e-02   -3.98951322016374e-02   -2.83216420506681e-03
0.35   -3.15276436862085e-02   -3.39368264566343e-02   -2.40918277042579e-03
 0.4   -2.29061739458302e-02   -2.46565476862823e-02   -1.75037374045212e-03
0.45   -1.20424883029356e-02   -1.29627142361277e-02   -9.20225933192024e-04
 0.5    7.93880769078472e-18   -5.13700621820321e-18   -1.30758139089879e-17
0.55    1.20424883029356e-02    1.29627142361277e-02    9.20225933192013e-04
 0.6    2.29061739458302e-02    2.46565476862823e-02    1.75037374045211e-03
0.65    3.15276436862085e-02    3.39368264566343e-02    2.40918277042578e-03
 0.7    3.70629679965706e-02    3.98951322016374e-02    2.83216420506680e-03
0.75    3.89703107665458e-02    4.19482244410133e-02    2.97791367446754e-03
 0.8    3.70629679965706e-02    3.98951322016374e-02    2.83216420506680e-03

0.85    3.15276436862085e-02    3.39368264566343e-02    2.40918277042577e-03
 0.9    2.29061739458302e-02    2.46565476862823e-02    1.75037374045212e-03
0.95    1.20424883029356e-02    1.29627142361277e-02    9.20225933192020e-04
   1    0.00000000000000e+00    1.02740124364064e-17    1.02740124364064e-17

# K=20 N=90 T=0.9 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.05   -1.33024402287967e-02   -1.29627142361276e-02    3.39725992669061e-04
 0.1   -2.53027449244478e-02   -2.46565476862823e-02    6.46197238165502e-04
0.15   -3.48262406523037e-02   -3.39368264566343e-02    8.89414195669402e-04
 0.2   -4.09407012964254e-02   -3.98951322016374e-02    1.04556909478809e-03
0.25   -4.30476008470140e-02   -4.19482244410133e-02    1.09937640600068e-03
 0.3   -4.09407012964254e-02   -3.98951322016374e-02    1.04556909478809e-03
0.35   -3.48262406523037e-02   -3.39368264566343e-02    8.89414195669402e-04
 0.4   -2.53027449244478e-02   -2.46565476862823e-02    6.46197238165506e-04
0.45   -1.33024402287967e-02   -1.29627142361277e-02    3.39725992669064e-04
 0.5   -6.56083137450032e-18   -5.13700621820321e-18    1.42382515629712e-18
0.55    1.33024402287967e-02    1.29627142361277e-02   -3.39725992669047e-04
 0.6    2.53027449244478e-02    2.46565476862823e-02   -6.46197238165488e-04
0.65    3.48262406523037e-02    3.39368264566343e-02   -8.89414195669389e-04
 0.7    4.09407012964254e-02    3.98951322016374e-02   -1.04556909478808e-03
0.75    4.30476008470140e-02    4.19482244410133e-02   -1.09937640600066e-03
 0.8    4.09407012964254e-02    3.98951322016374e-02   -1.04556909478808e-03
0.85    3.48262406523037e-02    3.39368264566343e-02   -8.89414195669402e-04
 0.9    2.53027449244478e-02    2.46565476862823e-02   -6.46197238165488e-04
0.95    1.33024402287967e-02    1.29627142361277e-02   -3.39725992669054e-04
   1    0.00000000000000e+00    1.02740124364064e-17    1.02740124364064e-17

# K=20 N=200 T=2 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Left
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.05   -2.32029785933465e-02   -2.23734625206607e-02    8.29516072685874e-04
 0.1   -4.41346879773184e-02   -4.25568546447194e-02    1.57783333259893e-03
0.15   -6.07461865976175e-02   -5.85744853251115e-02    2.17170127250593e-03
 0.2   -7.14114252301725e-02   -6.88584372694449e-02    2.55298796072757e-03
0.25   -7.50864160085418e-02   -7.24020456089017e-02    2.68437039964013e-03
 0.3   -7.14114252301725e-02   -6.88584372694449e-02    2.55298796072757e-03
0.35   -6.07461865976175e-02   -5.85744853251115e-02    2.17170127250593e-03
 0.4   -4.41346879773184e-02   -4.25568546447194e-02    1.57783333259892e-03
0.45   -2.32029785933465e-02   -2.23734625206607e-02    8.29516072685863e-04
 0.5    8.72181355458280e-18   -8.86640050823986e-18   -1.75882140628227e-17
0.55    2.32029785933466e-02    2.23734625206607e-02   -8.29516072685870e-04
 0.6    4.41346879773184e-02    4.25568546447194e-02   -1.57783333259894e-03
0.65    6.07461865976175e-02    5.85744853251115e-02   -2.17170127250597e-03
 0.7    7.14114252301725e-02    6.88584372694449e-02   -2.55298796072760e-03
0.75    7.50864160085419e-02    7.24020456089017e-02   -2.68437039964016e-03
 0.8    7.14114252301725e-02    6.88584372694449e-02   -2.55298796072760e-03
0.85    6.07461865976175e-02    5.85744853251115e-02   -2.17170127250599e-03

 0.9    4.41346879773184e-02    4.25568546447194e-02   -1.57783333259892e-03
0.95    2.32029785933465e-02    2.23734625206607e-02   -8.29516072685860e-04
   1    0.00000000000000e+00    1.77328010164797e-17    1.77328010164797e-17

# K=20 N=200 T=2 NU=0.1
# dx=0.05 dt=0.01 rho=0.4
# SCHEME=Midpoint
#  xk                      uk                      vk                   vk-uk
   0    0.00000000000000e+00   -0.00000000000000e+00   -0.00000000000000e+00
0.05   -2.27937029174531e-02   -2.23734625206607e-02    4.20240396792389e-04
 0.1   -4.33561993802792e-02   -4.25568546447194e-02    7.99344735559718e-04
0.15   -5.96746889673597e-02   -5.85744853251115e-02    1.10020364224821e-03
 0.2   -7.01518042203088e-02   -6.88584372694449e-02    1.29336695086392e-03
0.25   -7.37619720998134e-02   -7.24020456089017e-02    1.35992649091166e-03
 0.3   -7.01518042203088e-02   -6.88584372694449e-02    1.29336695086392e-03
0.35   -5.96746889673597e-02   -5.85744853251115e-02    1.10020364224821e-03
 0.4   -4.33561993802792e-02   -4.25568546447194e-02    7.99344735559711e-04
0.45   -2.27937029174531e-02   -2.23734625206607e-02    4.20240396792379e-04
 0.5    4.64438223495781e-18   -8.86640050823986e-18   -1.35107827431977e-17
0.55    2.27937029174531e-02    2.23734625206607e-02   -4.20240396792376e-04
 0.6    4.33561993802792e-02    4.25568546447194e-02   -7.99344735559718e-04
0.65    5.96746889673597e-02    5.85744853251115e-02   -1.10020364224823e-03
 0.7    7.01518042203088e-02    6.88584372694449e-02   -1.29336695086393e-03
0.75    7.37619720998134e-02    7.24020456089017e-02   -1.35992649091166e-03
 0.8    7.01518042203088e-02    6.88584372694449e-02   -1.29336695086392e-03
0.85    5.96746889673597e-02    5.85744853251115e-02   -1.10020364224824e-03
 0.9    4.33561993802792e-02    4.25568546447194e-02   -7.99344735559704e-04
0.95    2.27937029174531e-02    2.23734625206607e-02   -4.20240396792372e-04
   1    0.00000000000000e+00    1.77328010164797e-17    1.77328010164797e-17

Note that our numeric output verifies that the midpoint is generally more accurate than the left endpoint for approximating the contribution of the force F (x, t).