title: Burgers equation solution rapidly increasing
body: <p>I got a problem implementing a simple subroutine for solving the Burgers 
  equation:</p>
  
  <p><a href="https://i.stack.imgur.com/2iRx8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2iRx8.png" alt="enter image description here"></a></p>
  
  <p>Boundary condition x=[0,5] t=[0,1] </p>
  
  <p>The problem is that the code well predicts all the values of the resulting vector in function <code>f(x,U(time,x))</code> if I change the time step, the size of domain and so on... the last 4 points of the vector (a columns of a matrix U) are out of range of the normal solution (generally rapidly increasing) </p>
  
  <p>Here is the code (module subroutines and simple main):</p>
  
  <pre><code>MODULE PARAM 
          IMPLICIT NONE 
          INTEGER, PARAMETER  :: SP = KIND(1.0)
          INTEGER, PARAMETER  :: DP = KIND(1.D0)
        END MODULE 
  !-----------------------------------------------------------------------
        MODULE BURGER_2
         USE PARAM 
         IMPLICIT NONE
  
         REAL(DP), PARAMETER   :: x0=0. , xF= 5.
         REAL(DP), PARAMETER   :: t0=0. , tF= 1.0
         REAL(DP), PARAMETER   :: dx=0.01, dt=0.1
         INTEGER , PARAMETER   :: N= CEILING((xF-x0)/dx)
         INTEGER , PARAMETER   :: M= CEILING((tF-t0)/dt)
         REAL(DP), PARAMETER   :: nu = 1D-4 
         REAL(DP), PARAMETER   :: pi=3.14159265358979323846 
  
  
        CONTAINS 
  !-----------------------------------------------------------------------
           SUBROUTINE BURGER_EXPLICIT (x,t,u) 
             USE PARAM 
             REAL(DP), DIMENSION(N+1)     :: x
             REAL(DP), DIMENSION(M+1)     :: t
             REAL(DP), DIMENSION(N+1,M+1) :: U
             REAL(DP)   :: r,k
             INTEGER    :: i,j,stat
  
  
  
             x(1:N+1)       = (/ ( x0+dx*(i-1) , i=1,N+1 ) /)       
             t(1:M+1)       = (/ (t0+ dt*(j-1) , j=1,M+1 ) /)
             U(1:N+1,1:M+1) = RESHAPE((/(((sin(2*pi*(i-1)/N)), i=1,N+1), j=1,M+1)/),(/N+1,M+1/)) 
  
             U(1,:)   = x0
             U(N+1,:) = xF
  
             U(:,1)   = t0
             U(:,M+1) = tF
  
  
  
             r = nu*DT/DX**2
             k = DT/(2*DX)
  
             DO J=2,M
              DO I=2,N
                U(i,j+1) = r*u(i+1,j)+(1-2*r)*u(i,j)+r*u(i-1,j) - k*u(i,j)*(u(i+1,j)-u(i-1,j))
              END DO
             END DO 
  
             !DO j=1,M+1  
             OPEN(10,file='bur1.dat',STATUS='UNKNOWN',IOSTAT=stat)
              IF (STAT .NE. 0) THEN 
               WRITE(6,FMT='(A)')'Error opening File ''bur1.dat'' (EXIT1)'
               STOP 
              ELSE     
                WRITE(10,FMT='(2F20.5)') (x(i), u(i,9), i=1,N)        !((u(i,j) , i=1,N+1), J=1,M+1)
                !WRITE(10,*)
                !WRITE(10,FMT='(2F20.5)') (x(i), u(i,2), i=1,N)        !((u(i,j) , i=1,N+1), J=1,M+1)
                WRITE(6,'(50("-"))') 
             !END DO 
              END IF
  
             RETURN   
           END SUBROUTINE 
  
  
  !-----------------------------------------------------------------------
  !-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        END MODULE
  </code></pre>
  
  <p>the main program is :</p>
  
  <pre><code>  PROGRAM main 
    USE BURGER_2
    IMPLICIT NONE 
  
    REAL(DP) , DIMENSION (N+1) :: xx
    REAL(DP) , DIMENSION (M+1) :: tt
    REAL(DP) , DIMENSION (n+1,M+1) :: UU
  
    CALL burger_EXPLICIT(xx,tt,UU)
  
  
    STOP 
    END
  </code></pre>
  
  <p>I want obtain a matrix (write into a file) for plotting a 3d surface with gnuplot .. but I don't know the right way for write these data</p>
  
  <p>here for exemple the vector that the program wrote for <strong>u(i,9) i=1,N+1</strong></p>
  
  <pre><code>   0.00000             0.00000
           0.01000             0.00637
           0.02000             0.01275
           0.03000             0.01912
           0.04000             0.02550
           0.05000             0.03187
           0.06000             0.03825
           0.07000             0.04462
           0.08000             0.05099
           0.09000             0.05736
           0.10000             0.06374
           0.11000             0.07011
           0.12000             0.07648
           0.13000             0.08285
           0.14000             0.08921
           0.15000             0.09558
           0.16000             0.10195
           0.17000             0.10831
           0.18000             0.11467
           0.19000             0.12104
           0.20000             0.12740
           0.21000             0.13375
           0.22000             0.14011
           0.23000             0.14647
           0.24000             0.15282
           0.25000             0.15917
           0.26000             0.16552
           0.27000             0.17187
           0.28000             0.17822
           0.29000             0.18456
           0.30000             0.19090
           0.31000             0.19724
           0.32000             0.20358
           0.33000             0.20991
           0.34000             0.21624
           0.35000             0.22257
           0.36000             0.22890
           0.37000             0.23522
           0.38000             0.24154
           0.39000             0.24786
           0.40000             0.25417
           0.41000             0.26049
           0.42000             0.26679
           0.43000             0.27310
           0.44000             0.27940
           0.45000             0.28570
           0.46000             0.29199
           0.47000             0.29828
           0.48000             0.30457
           0.49000             0.31085
           0.50000             0.31713
           0.51000             0.32340
           0.52000             0.32967
           0.53000             0.33594
           0.54000             0.34220
           0.55000             0.34846
           0.56000             0.35471
           0.57000             0.36095
           0.58000             0.36720
           0.59000             0.37344
           0.60000             0.37967
           0.61000             0.38590
           0.62000             0.39212
           0.63000             0.39833
           0.64000             0.40455
           0.65000             0.41075
           0.66000             0.41695
           0.67000             0.42315
           0.68000             0.42934
           0.69000             0.43552
           0.70000             0.44169
           0.71000             0.44786
           0.72000             0.45403
           0.73000             0.46018
           0.74000             0.46634
           0.75000             0.47248
           0.76000             0.47862
           0.77000             0.48475
           0.78000             0.49087
           0.79000             0.49698
           0.80000             0.50309
           0.81000             0.50919
           0.82000             0.51528
           0.83000             0.52137
           0.84000             0.52745
           0.85000             0.53351
           0.86000             0.53957
           0.87000             0.54563
           0.88000             0.55167
           0.89000             0.55770
           0.90000             0.56373
           0.91000             0.56975
           0.92000             0.57575
           0.93000             0.58175
           0.94000             0.58774
           0.95000             0.59372
           0.96000             0.59969
           0.97000             0.60565
           0.98000             0.61159
           0.99000             0.61753
           1.00000             0.62346
           1.01000             0.62937
           1.02000             0.63528
           1.03000             0.64117
           1.04000             0.64706
           1.05000             0.65293
           1.06000             0.65878
           1.07000             0.66463
           1.08000             0.67047
           1.09000             0.67629
           1.10000             0.68210
           1.11000             0.68789
           1.12000             0.69367
           1.13000             0.69944
           1.14000             0.70520
           1.15000             0.71094
           1.16000             0.71667
           1.17000             0.72238
           1.18000             0.72808
           1.19000             0.73376
           1.20000             0.73943
           1.21000             0.74508
           1.22000             0.75072
           1.23000             0.75634
           1.24000             0.76194
           1.25000             0.76752
           1.26000             0.77309
           1.27000             0.77864
           1.28000             0.78418
           1.29000             0.78969
           1.30000             0.79519
           1.31000             0.80067
           1.32000             0.80613
           1.33000             0.81157
           1.34000             0.81699
           1.35000             0.82238
           1.36000             0.82776
           1.37000             0.83312
           1.38000             0.83845
           1.39000             0.84377
           1.40000             0.84906
           1.41000             0.85432
           1.42000             0.85957
           1.43000             0.86479
           1.44000             0.86998
           1.45000             0.87515
           1.46000             0.88030
           1.47000             0.88542
           1.48000             0.89051
           1.49000             0.89558
           1.50000             0.90062
           1.51000             0.90563
           1.52000             0.91061
           1.53000             0.91556
           1.54000             0.92048
           1.55000             0.92537
           1.56000             0.93023
           1.57000             0.93506
           1.58000             0.93986
           1.59000             0.94462
           1.60000             0.94935
           1.61000             0.95404
           1.62000             0.95870
           1.63000             0.96332
           1.64000             0.96790
           1.65000             0.97244
           1.66000             0.97695
           1.67000             0.98141
           1.68000             0.98583
           1.69000             0.99020
           1.70000             0.99453
           1.71000             0.99882
           1.72000             1.00305
           1.73000             1.00724
           1.74000             1.01137
           1.75000             1.01545
           1.76000             1.01948
           1.77000             1.02344
           1.78000             1.02734
           1.79000             1.03118
           1.80000             1.03495
           1.81000             1.03864
           1.82000             1.04226
           1.83000             1.04580
           1.84000             1.04925
           1.85000             1.05261
           1.86000             1.05588
           1.87000             1.05903
           1.88000             1.06208
           1.89000             1.06501
           1.90000             1.06780
           1.91000             1.07046
           1.92000             1.07296
           1.93000             1.07531
           1.94000             1.07747
           1.95000             1.07945
           1.96000             1.08122
           1.97000             1.08276
           1.98000             1.08407
           1.99000             1.08511
           2.00000             1.08586
           2.01000             1.08631
           2.02000             1.08643
           2.03000             1.08618
           2.04000             1.08554
           2.05000             1.08448
           2.06000             1.08297
           2.07000             1.08096
           2.08000             1.07843
           2.09000             1.07532
           2.10000             1.07161
           2.11000             1.06725
           2.12000             1.06219
           2.13000             1.05639
           2.14000             1.04980
           2.15000             1.04237
           2.16000             1.03405
           2.17000             1.02479
           2.18000             1.01454
           2.19000             1.00325
           2.20000             0.99087
           2.21000             0.97735
           2.22000             0.96264
           2.23000             0.94670
           2.24000             0.92948
           2.25000             0.91095
           2.26000             0.89106
           2.27000             0.86979
           2.28000             0.84710
           2.29000             0.82298
           2.30000             0.79740
           2.31000             0.77037
           2.32000             0.74187
           2.33000             0.71191
           2.34000             0.68050
           2.35000             0.64766
           2.36000             0.61343
           2.37000             0.57783
           2.38000             0.54092
           2.39000             0.50275
           2.40000             0.46338
           2.41000             0.42289
           2.42000             0.38134
           2.43000             0.33884
           2.44000             0.29548
           2.45000             0.25135
           2.46000             0.20656
           2.47000             0.16123
           2.48000             0.11548
           2.49000             0.06941
           2.50000             0.02316
           2.51000            -0.02316
           2.52000            -0.06941
           2.53000            -0.11548
           2.54000            -0.16123
           2.55000            -0.20656
           2.56000            -0.25135
           2.57000            -0.29548
           2.58000            -0.33884
           2.59000            -0.38134
           2.60000            -0.42289
           2.61000            -0.46338
           2.62000            -0.50275
           2.63000            -0.54092
           2.64000            -0.57784
           2.65000            -0.61343
           2.66000            -0.64767
           2.67000            -0.68050
           2.68000            -0.71191
           2.69000            -0.74187
           2.70000            -0.77037
           2.71000            -0.79740
           2.72000            -0.82298
           2.73000            -0.84710
           2.74000            -0.86979
           2.75000            -0.89106
           2.76000            -0.91095
           2.77000            -0.92948
           2.78000            -0.94670
           2.79000            -0.96264
           2.80000            -0.97735
           2.81000            -0.99087
           2.82000            -1.00325
           2.83000            -1.01454
           2.84000            -1.02479
           2.85000            -1.03405
           2.86000            -1.04237
           2.87000            -1.04980
           2.88000            -1.05639
           2.89000            -1.06219
           2.90000            -1.06725
           2.91000            -1.07161
           2.92000            -1.07532
           2.93000            -1.07843
           2.94000            -1.08096
           2.95000            -1.08297
           2.96000            -1.08448
           2.97000            -1.08554
           2.98000            -1.08618
           2.99000            -1.08643
           3.00000            -1.08631
           3.01000            -1.08586
           3.02000            -1.08511
           3.03000            -1.08407
           3.04000            -1.08276
           3.05000            -1.08122
           3.06000            -1.07945
           3.07000            -1.07747
           3.08000            -1.07531
           3.09000            -1.07296
           3.10000            -1.07046
           3.11000            -1.06780
           3.12000            -1.06501
           3.13000            -1.06208
           3.14000            -1.05903
           3.15000            -1.05588
           3.16000            -1.05261
           3.17000            -1.04925
           3.18000            -1.04580
           3.19000            -1.04226
           3.20000            -1.03864
           3.21000            -1.03495
           3.22000            -1.03118
           3.23000            -1.02734
           3.24000            -1.02344
           3.25000            -1.01948
           3.26000            -1.01545
           3.27000            -1.01137
           3.28000            -1.00724
           3.29000            -1.00305
           3.30000            -0.99882
           3.31000            -0.99453
           3.32000            -0.99020
           3.33000            -0.98583
           3.34000            -0.98141
           3.35000            -0.97695
           3.36000            -0.97244
           3.37000            -0.96790
           3.38000            -0.96332
           3.39000            -0.95870
           3.40000            -0.95404
           3.41000            -0.94935
           3.42000            -0.94462
           3.43000            -0.93986
           3.44000            -0.93506
           3.45000            -0.93023
           3.46000            -0.92537
           3.47000            -0.92048
           3.48000            -0.91556
           3.49000            -0.91061
           3.50000            -0.90563
           3.51000            -0.90062
           3.52000            -0.89558
           3.53000            -0.89051
           3.54000            -0.88542
           3.55000            -0.88030
           3.56000            -0.87515
           3.57000            -0.86998
           3.58000            -0.86479
           3.59000            -0.85957
           3.60000            -0.85432
           3.61000            -0.84906
           3.62000            -0.84377
           3.63000            -0.83845
           3.64000            -0.83312
           3.65000            -0.82776
           3.66000            -0.82238
           3.67000            -0.81699
           3.68000            -0.81157
           3.69000            -0.80613
           3.70000            -0.80067
           3.71000            -0.79519
           3.72000            -0.78969
           3.73000            -0.78418
           3.74000            -0.77864
           3.75000            -0.77309
           3.76000            -0.76752
           3.77000            -0.76194
           3.78000            -0.75634
           3.79000            -0.75072
           3.80000            -0.74508
           3.81000            -0.73943
           3.82000            -0.73376
           3.83000            -0.72808
           3.84000            -0.72238
           3.85000            -0.71667
           3.86000            -0.71094
           3.87000            -0.70520
           3.88000            -0.69944
           3.89000            -0.69367
           3.90000            -0.68789
           3.91000            -0.68210
           3.92000            -0.67629
           3.93000            -0.67047
           3.94000            -0.66463
           3.95000            -0.65878
           3.96000            -0.65293
           3.97000            -0.64706
           3.98000            -0.64117
           3.99000            -0.63528
           4.00000            -0.62937
           4.01000            -0.62346
           4.02000            -0.61753
           4.03000            -0.61159
           4.04000            -0.60565
           4.05000            -0.59969
           4.06000            -0.59372
           4.07000            -0.58774
           4.08000            -0.58175
           4.09000            -0.57575
           4.10000            -0.56975
           4.11000            -0.56373
           4.12000            -0.55770
           4.13000            -0.55167
           4.14000            -0.54563
           4.15000            -0.53957
           4.16000            -0.53351
           4.17000            -0.52745
           4.18000            -0.52137
           4.19000            -0.51528
           4.20000            -0.50919
           4.21000            -0.50309
           4.22000            -0.49698
           4.23000            -0.49087
           4.24000            -0.48475
           4.25000            -0.47862
           4.26000            -0.47248
           4.27000            -0.46634
           4.28000            -0.46018
           4.29000            -0.45403
           4.30000            -0.44786
           4.31000            -0.44169
           4.32000            -0.43552
           4.33000            -0.42934
           4.34000            -0.42315
           4.35000            -0.41695
           4.36000            -0.41075
           4.37000            -0.40455
           4.38000            -0.39833
           4.39000            -0.39212
           4.40000            -0.38590
           4.41000            -0.37967
           4.42000            -0.37344
           4.43000            -0.36720
           4.44000            -0.36095
           4.45000            -0.35471
           4.46000            -0.34846
           4.47000            -0.34220
           4.48000            -0.33594
           4.49000            -0.32967
           4.50000            -0.32340
           4.51000            -0.31713
           4.52000            -0.31085
           4.53000            -0.30457
           4.54000            -0.29828
           4.55000            -0.29199
           4.56000            -0.28570
           4.57000            -0.27940
           4.58000            -0.27310
           4.59000            -0.26679
           4.60000            -0.26049
           4.61000            -0.25417
           4.62000            -0.24786
           4.63000            -0.24154
           4.64000            -0.23522
           4.65000            -0.22890
           4.66000            -0.22257
           4.67000            -0.21624
           4.68000            -0.20991
           4.69000            -0.20358
           4.70000            -0.19724
           4.71000            -0.19090
           4.72000            -0.18456
           4.73000            -0.17822
           4.74000            -0.17187
           4.75000            -0.16552
           4.76000            -0.15917
           4.77000            -0.15282
           4.78000            -0.14647
           4.79000            -0.14011
           4.80000            -0.13375
           4.81000            -0.12740
           4.82000            -0.12104
           4.83000            -0.11467
           4.84000            -0.10831
           4.85000            -0.10195
           4.86000            -0.09558
           4.87000            -0.08921
           4.88000            -0.08285
           4.89000            -0.07648
           4.90000            -0.07011
           4.91000            -0.06374
           4.92000            -0.05736
           4.93000            -0.05099
           4.94000            -0.04068
           4.95000            -0.21859
           4.96000    -539175687.87944
           4.97000********************
           4.98000********************
           4.99000********************
           5.00000********************
           5.01000             5.00000
  </code></pre>
  
  <p>have a look to the last 6 point </p>