module Main where
import Text.Printf

ns = [860, 847, 743, 672, 623, 521, 461, 427, 376, 343, 315, 288]
angles = take 12 $ [0, 10..]

main :: IO()
main = do
    let xs = (map (\x -> 1 - cos (pi * x / 180)) angles)
    let ys = (map (\x -> 1 / x - 1 / (head ns)) ns)
    print_data xs ys

    let k' = k xs ys
    --let b' = b xs ys

    putStr "k="
    print k'
    
    let n0 = k' * (1 - cos 0) + 1/ (head ns)
    print $ 1 / n0
    let n90 = k' * (1 - cos (pi / 2)) + 1 / (head ns) 
    print $ 1 / n90
    

print_data :: [Double] -> [Double] -> IO ()
print_data (x:xs) (y:ys) = do
    printf "%f %f\n" x y
    print_data xs ys  
print_data _ _ = return ()

mean :: [Double] -> Double
mean lst = sum lst / n where
    n = fromIntegral $ length lst

k :: [Double] -> [Double] -> Double
k xs ys = xy / x' where
    xy = mean $ zipWith (*) xs ys
    x' = mean $ map (^2) xs

b :: [Double] -> [Double] -> Double
b xs ys = (xy - x * y) / (x ^ 2 - x') where
    xy = mean $ zipWith (*) xs ys
    x = mean xs
    y = mean ys
    x' = mean $ map (^2) xs
