[album]750[/album]
見るからにヤバそうな広義積分の式ですね。
そして、最近講義で台形公式による数値積分を習いました。
よし、数値積分でフーリエ変換を計算してみよう!
といっても、数値積分で無限の範囲の積分はできないので、
ある有限の区間以外は0と定義する関数しかフーリエ変換できません。
がんばって実装したコード
sekibun_i a b h k n f
| k>=n = (f a)*0.5+(f b)*0.5
| otherwise = (f (a+h*k))+sekibun_i a b h (k+1) n f
-- 関数fの[a,b]でn分割した台形公式による数値積分を求める
sekibun a b n f = h*sekibun_i a b h 1 n f
where h = (b-a)/n
-- [s,e]を積分し、fのフーリエ変換F(omega)を求める
-- reが実部、imが虚部を返す
fuuriehenkan_re s e f omega = sekibun s e 10000 (\t -> (f t)*(cos (-omega*t)))
fuuriehenkan_im s e f omega = sekibun s e 10000 (\t -> (f t)*(sin (-omega*t)))
makeplot_i s h k n f
| k>=n = []
| otherwise = (s+h*k,f (s+h*k)):makeplot_i s h (k+1) n f
-- [s,e]の範囲をn分割し、fのグラフを描くためのデータを作る
makeplot s e n f = makeplot_i s ((e-s)/n) 0 n f
-- [(a,b)] -> String 主にmakeplotの出力をgnuplotに入れやすい形式にする
mp2text x = foldr (\a b -> a++b) "" $ map (\a -> (show $ fst a)++" "++(show $ snd a)++"\n")x
makeplot2_i s h k n fs fe f
| k>=n = []
| otherwise = concat [show (s+h*k)," ",show $ fuuriehenkan_re fs fe f (s+h*k)," ",
show $ fuuriehenkan_im fs fe f (s+h*k),"\n",makeplot2_i s h (k+1) n fs fe f]
-- [s,e]の範囲をn分割し、fのフーリエ変換F(omega)のグラフを描くためのデータを作り、直接gnuplot形式にする
-- 実際は、fではなく(\x -> if fsghci
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l fuurie_henkan.hs
[1 of 1] Compiling Main ( fuurie_henkan.hs, interpreted )
Ok, modules loaded: Main.
*Main> do writeFile "1.txt" $ makeplot2 (-10) 10 100 (-1) 1 (\t -> 1)
誰かおすすめの入力関数があれば、教えていただけると嬉しいです。