Итак, как новичок, я думал, что буду работать над ужасно ужасной версией проекта, установленного в mandelbrot. В этом жалком случае набор рисуется с текстом (Shreik!) В текстовый файл. Поскольку мне нужна была какая-то практика с некоторым числовым кодированием, я разработал самую сложную систему с множеством номеров. Я не могу определить проблему в коде - тот, который рисует группу вместо набора mandelbrot. Вот она (не смотрите на него слишком долго, или вы могли бы умереть от более expossure к нуб-ioactivity):Haskell - Проблемы в ящике Мандельброта
-- complex numbers, test for mandelbrot set
----------------- Complex Numbers
data C = Complex Float Float -- a + bi
deriving Show
data Mandelbrot = Possible -- if thought to be in mandelbrot set
| Not Integer -- this Integer is iterations before |z| > 2 in z=z^2+c
deriving Show
complexReal :: C -> Float
complexReal (Complex n _) = n
complexImaginary :: C -> Float
complexImaginary (Complex _ n) = n
modulus :: C -> Float
modulus (Complex n m) = sqrt ((n^2) + (m^2))
argument :: C -> Float --returns in radians
argument (Complex m n) | n < 0 && m < 0 = pi + (argument (Complex (0-m) (0-n)))
| m < 0 = (pi/2) + (argument (Complex (0-m) n))
| n < 0 = ((3 * pi)/2) + (argument (Complex m (0-n)))
| otherwise = atan (n/m)
multComplex :: C -> C -> C
multComplex (Complex m n) (Complex x y) = Complex ((m*x)-(n*y)) ((m*y)+(n*x))
addComplex :: C -> C -> C
addComplex (Complex m n) (Complex x y) = Complex (m + x) (m + y)
----------------- End Complex numbers
----------------- Mandelbrot
inMandelbrot :: C -> Mandelbrot
inMandelbrot c = inMandelbrotTest (Complex 0 0) c 0
--(z, c, i terations) with z=z^2+c, c is plotted on set map if z is bound
inMandelbrotTest :: C -> C -> Integer -> Mandelbrot
inMandelbrotTest z c i | (modulus z) > 2 = Not i -- too large
| i > 100 = Possible -- upper limit iterations
| otherwise = inMandelbrotTest (addComplex (multComplex z z) c) c (i+1)
possiblyInMandelbrot :: Mandelbrot -> Bool
possiblyInMandelbrot Possible = True
possiblyInMandelbrot _ = False
mandelbrotLine :: [C] -> String
mandelbrotLine [] = "\n"
mandelbrotLine (n:x) | possiblyInMandelbrot (inMandelbrot n) = "#" ++ mandelbrotLine x
mandelbrotLine (_:x) = " " ++ mandelbrotLine x
mandelbrotFeild :: [[C]] -> String
mandelbrotFeild [[]] = ""
mandelbrotFeild (n:x) = (mandelbrotLine n) ++ (mandelbrotFeild x)
-----------------End Mandelbrot
---------------- textual output
feildLine :: Float -> Float -> Float -> Float -> [C] -- start R, end R, i, increment x
feildLine s e i x | s > e = []
| otherwise = [(Complex s i)] ++ feildLine (s+x) e i x
feildGenerate :: Float -> Float -> Float -> Float -> Float -> [[C]] -- start R, end R, start i, end i, increment x
feildGenerate sr er si ei x | si > ei = [[]]
| otherwise = [(feildLine sr er si x)] ++ (feildGenerate sr er (si+x) ei x)
l1 :: String
l1 = mandelbrotFeild (feildGenerate (-3) 3 (-3) 3 0.05)
---------------- End textual output
main = do
writeFile "./mandelbrot.txt" (l1)
Как вы можете видеть (или не может, если не смотреть) есть некоторые неиспользуемые функции для моих комплексных чисел. Есть ли надежда доктора?
Резюме:
Почему это сделать группу вместо множества Мандельброта?
Итак, о чем именно вы спрашиваете? – leftaroundabout
Почему вы так сильно оскорбляете свой код? Обучение - это пробовать. Не зная что-то или учиться, нечего стыдиться. –
Сначала я предлагаю вам использовать некоторую существующую библиотеку для сложных чисел, например [в базе] (http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Complex .html). Это поможет вам сосредоточиться на части Мандельброта и избежать возможных ошибок в реализации «Сложности». И существующая библиотека также реализует стандартные числовые классы, такие как 'Num' или' Fractional', что делает выражения более читабельными. Позже вы можете попробовать реализовать свою версию, если хотите. (Примечание: этот вопрос, вероятно, должен принадлежать http://codereview.stackexchange.com/.) –