Skip to content

Instantly share code, notes, and snippets.

@akira093
Created November 27, 2013 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira093/7675420 to your computer and use it in GitHub Desktop.
Save akira093/7675420 to your computer and use it in GitHub Desktop.
import System.IO
--constants
e0 :: Double
e0 = 6.0
v1 :: Double
v1 = 3.0
v2 :: Double
v2 = 3.0
v12 :: Double
v12 = 1.0
s1 :: Double
s1 = 1.0
s2 :: Double
s2 = 1.0
vStart = 100
vEnd = 1000
step = 1
vs = [vStart,vStart+step..vEnd]
ns = [1..5]
main = mapM_ (print . intensity2) vs
factorial :: Int -> Int
factorial 0 = 1
factorial n =
if n < 0
then undefined
else n * factorial (n-1)
intensity :: Double -> Int -> Int -> Double
intensity v n1 n2=
let
a = ((e0 - fromIntegral n1 * v1 - fromIntegral n2 * v2) / e0) ** 4
b = s1 ^ n1 / (fromIntegral . factorial) n1 * s2 ^ n2 / (fromIntegral . factorial) n2
c = exp(-4 * log(2 * ((v - e0 + fromIntegral n1 * v1 + fromIntegral n2 * v2) / v12) ** 2))
in
a * b * c
intensity2 v = sum [intensity v n1 n2 | n1 <- ns, n2 <- ns]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment