title: FTCS Algorithm for the heat equation
body: <p>I am attempting to implement the FTCS algorithm for the 1 dimensional heat equation in Python. </p>
  
  <pre><code>import numpy as np
  
  L = 1 #Length of rod in x direction
  k = 0.3 #Thermal conductivity of rod
  tmax = 5 #how many seconds
  nx = 100 #number of spacial steps
  nt = 100; #number of time steps
  xi = np.linspace(0,L,nx) 
  ti = np.linspace(0,tmax,nt)
  dx = L/(nx-1)
  dt = tmax/(nt-1)
  r = k*dt/(dx)**2
  r2 = 1-2*r
  
  u=np.zeros((nt,nx))
  #IC
  phi = 100;
  for x in range(0,nx):    
      u[0][x] = phi
  
  #BC
  for t in range(0,nt):    
      u[t][0] = 0;
      u[t][nx-1] = 0
  #FTCS Algorithm
  
  for t in range(0,nt-1): #timestep
      for x in range(1,nx-2):
          u[t+1][x] = r*(u[t][x-1]+ u[t][x+1]) + r2*(u[t][x])
  </code></pre>
  
  <p>However I am not getting plausible values for u[t][x] = u(x,t) considering my initial conditions of 100. i.e. they blow up and give me stupid values like '4.11052068e+221' is there some bad programming practise I am partaking in which is destroying the algorithm? Or have I just implemented the algorithm incorrectly?</p>
  
  <p>EDIT: I think I have worked out that it is because the algorithm is stable if and only if r &lt; 1/2. The numbers just blow up because my r is about 2.5 or whatever, however if anyone can see any other errors let me know!!</p>