Rev. | 52e1869670532bdd059a4c0cf6b8868af6a948c2 |
---|---|
サイズ | 1,423 バイト |
日時 | 2010-09-10 02:21:41 |
作者 | lorenzo |
ログメッセージ | I modified this program which now can read a table of integers as if they
|
-- Import the haskell module for array manipulations and linear algebra
import Numeric.LinearAlgebra
import Graphics.Plot
main :: IO ()
main = do
txt <- readFile "mydata.dat"
-- let dat :: [[Integer]]-- i.e. I am specifying explicitly the type of dat
-- -- using a let because I am inside a do action
let dat :: [[Double]]-- I am now specifying that dat needs to be a
-- Double. This is due to the fact that I later on want to
-- convert the list into a matrix, but the hmatrix module
-- requires matrices to be either Double or Complex.
dat = convert txt
print dat -- this prints out my chunk of data
let c = fromLists dat :: Matrix Double
disp c
let d=c+3.8
-- print d
-- The whole procedure of reading data into a list and then translating it into a
-- matrix can be bypassed since there already is an inbuilt hmatrix function to do that
my_mat<-loadMatrix "mydata.dat"
disp my_mat -- and one can see that the 2 matrices are exactly the same
-- return ()
-- convert x = lines x
-- convert x = map (map read . words) $ lines x
-- convert :: Read a => String -> [[a]]
convert x = (map (map read . words) . lines) x
disp = putStr . dispf 2
-- Now try performing some manipulations on the list