Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

jetxee

By: a guest on Jan 20th, 2009  |  syntax: Haskell  |  size: 0.77 KB  |  hits: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- one step of integration
  2. stepEuler :: (Floating a) => a -> [a] -> [a]
  3. stepEuler mu u@(x:xs) = (applyBC . (diffused mu)) $! u -- strict evaluation of u
  4.     where
  5.           diffused mu (left:x:[]) = []    -- ignore outer points
  6.           diffused mu (left:x:right:xs) = -- integrate inner points
  7.                    (x+mu*(left+right-2*x)) : diffused mu (x:right:xs)
  8.           applyBC inner = inner `seq` u' `seq` l  `seq` r `seq` -- strict evaluation
  9.                           (l ++ inner ++ r) -- boundary conditions
  10.                where u' = [head u] ++ inner ++ [last u]
  11.                      l = lbc u'
  12.                      r = rbc u'
  13.                      lbc = zeroflux mu             -- left boundary
  14.                      rbc = (zeroflux mu) . reverse -- right boundary