• R/O
  • SSH

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

修訂. 52e1869670532bdd059a4c0cf6b8868af6a948c2
大小 1,423 bytes
時間 2010-09-10 02:21:41
作者 lorenzo
Log Message

I modified this program which now can read a table of integers as if they
were real numbers and can also load them as a matrix using the hmatrix module.

Content

-- 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