产生Lyapunov分形的问题 [英] Problems generating a Lyapunov fractal

查看:70
本文介绍了产生Lyapunov分形的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击此链接(使用Wolfram语言的工作代码):

http://示范。 wolfram.com/LyapunovFractals/ [ ^ ]



生成图像应该非常简单:

选择任何非平凡长度的As和Bs字符串(例如,AABAB)。

构造由字符串中连续项组成的序列S,根据需要重复多次。

选择一个点(a,b)\在[0,4] \times [0,4]

定义函数

r_n = a如果S_n = A,



r_n = b如果S_n = B.



设x_0 = 0.5,并计算迭代次数

x_ {n + 1} = r_n x_n(1 - x_n)。



计算Lyapunov指数:

\ lambda = \lim_ {N \ altarrow \in fty} {1 \over N} \sum_ {n = 1} ^ N \log \ leftft | {dx_ {n + 1} \over dx_n} \ right | = \lim_ {N \ rightarrow \ inffty} {1 \over N} \sum_ {n = 1} ^ N \ log | r_n(1 - 2x_n)|



实际上,\ lambda是通过选择一个合适的大N来近似的。

根据获得的\ lambda的值对点(a,b)进行着色。 />
对图像平面中的每个点重复步骤(3-7)。



Following this link (with a working code in a Wolfram language):
http://demonstrations.wolfram.com/LyapunovFractals/[^]

generating the image should be pretty straight forward:
Choose a string of As and Bs of any nontrivial length (e.g., AABAB).
Construct the sequence S formed by successive terms in the string, repeated as many times as necessary.
Choose a point (a,b) \in [0,4] \times [0,4].
Define the function
r_n = a if S_n = A,
and
r_n = b if S_n = B.

Let x_0 = 0.5, and compute the iterates
x_{n+1} = r_n x_n (1 - x_n).

Compute the Lyapunov exponent:
\lambda = \lim_{N \rightarrow \infty} {1 \over N} \sum_{n = 1}^N \log \left|{dx_{n+1} \over dx_n}\right| = \lim_{N \rightarrow \infty} {1 \over N} \sum_{n = 1}^N \log |r_n (1 - 2x_n)|

In practice, \lambda is approximated by choosing a suitably large N.
Color the point (a,b) according to the value of \lambda obtained.
Repeat steps (3–7) for each point in the image plane.

' https://en.wikipedia.org/wiki/Lyapunov_fractal
  ' http://hypertextbook.com/chaos/44.shtml

  LyapunovCanvas.Background = Nothing

  ' Save the generating string (AB) into a char array
  Dim Sn As Char() = txtLyapunovGeneratingString.Text.ToString.ToCharArray

  ' Set the resolution of the image
  Dim LyapunovImageDimensions As Integer = 400

  'Calculate the scaling factor to get the appropriate a and b values
  Dim LyapunovScaleFactor = 4 / LyapunovImageDimensions

  Dim LyapunovLambdaArray(LyapunovImageDimensions + 1, LyapunovImageDimensions + 1) As Double

  Dim MAxValue, MinValue As Double
  MAxValue = Double.MinValue
  MinValue = Double.MaxValue

  ' The number of iterations to calculate the Lyapunov Exponent Lambda
  Dim N As Integer = 180

  ' The values a and b that should be between 0 and 4 unless you have zoomed in
  Dim a, b As Double

  For x As Integer = 0 To LyapunovImageDimensions
      For y As Integer = 0 To LyapunovImageDimensions

          ' Caluclate the a and b values from the placement
          a = LyapunovScaleFactor * x
          b = LyapunovScaleFactor * y

          ' Initialize the calcualtion parameters
          Dim rn As Double = 0
          Dim X0 As Double = 0.5
          Dim Xn As Double = X0
          Dim LyapunovExponent As Double = 0

          'Loop through the items in the generation string
          For CharItem As Integer = 0 To Sn.Length - 1

              ' Choose the value for rn based on the current item in the generating string
              rn = If(Sn(CharItem).ToString.ToUpper = "A", a, b)

              ' Reset the Xn value
              Xn = 0.5

              ' The iteration loop
              For NCount As Integer = 1 To N

                  ' Calcualte the exponent value and add a small value inside the logarithm
                  ' in case the clculated value is 0
                  LyapunovExponent += Math.Log(0.00001 + Math.Abs(rn * (1 - 2 * Xn))) / N

                  ' Create the next value of Xn
                  Xn = rn * Xn * (1 - Xn)
              Next
          Next

          ' Save the exponent value to the Image array
          LyapunovLambdaArray(x, y) = LyapunovExponent

          'Calculate the max and min values calculated (can be used for drawing the image)
          If MAxValue < LyapunovExponent Then
              MAxValue = LyapunovExponent
          End If

          If MinValue > LyapunovExponent Then
              MinValue = LyapunovExponent
          End If

      Next
  Next

  ' Create a Byte array of the image
  Dim buffer As New List(Of Byte)

  For x As Integer = 0 To LyapunovImageDimensions
      For y As Integer = 0 To LyapunovImageDimensions
          Dim k As Integer = 0

          Dim TempBrush As New SolidColorBrush

          ' Based on the value of the exponent
          If LyapunovLambdaArray(x, y) > 0.1 Then
              TempBrush = Brushes.Blue
          ElseIf LyapunovLambdaArray(x, y) < 0.1 Then
              TempBrush = Brushes.Yellow
          Else
              TempBrush = Brushes.Black
          End If

          buffer.Add(TempBrush.Color.B)
          buffer.Add(TempBrush.Color.G)
          buffer.Add(TempBrush.Color.R)
          buffer.Add(TempBrush.Color.A)

      Next
  Next

  Dim dpiX As Double = 96D
  Dim dpiY As Double = 96D
  Dim pixelFormat = PixelFormats.Pbgra32
  Dim bytesPerPixel = Math.Truncate(((pixelFormat.BitsPerPixel + 7) / 8))
  Dim stride = bytesPerPixel * (LyapunovImageDimensions + 1)


  Dim img As New ImageBrush
  img.ImageSource = BitmapSource.Create(LyapunovImageDimensions, LyapunovImageDimensions, dpiX, dpiY,
                                   pixelFormat, Nothing, buffer.ToArray, stride) '
  LyapunovCanvas.Background = img





但是创建的图像看起来并不像他们应该的那样。任何人都可以在这里发现我的错误吗?



But the images that are created looks nothing like they should. Can anyone spot my mistake here?

推荐答案

我不确定,但这些行:

I'm not sure, but these lines:
Dim MAxValue, MinValue As Double
MAxValue = Double.MinValue
MinValue = Double.MaxValue



对我来说似乎很可疑。

也许:


seems suspicious to me.
Maybe:

Dim MAxValue, MinValue As Double
MAxValue = Double.MaxValue
MinValue = Double.MinValue




?


我弄明白我错过了什么。对于所有迭代,必须重复a和b的文本字符串。它现在按预期工作。



I figured out what I missed. The text string of a's and b's have to be repeted for all iterations. It now works as expected.

' Caluclate the a and b values from the placement
               a = LyapunovScaleFactor * x
               b = LyapunovScaleFactor * y

               ' Initialize the calcualtion parameters
               Dim rn As Double = 0
               Dim X0 As Double = 0.5
               Dim Xn As Double = X0
               Dim LyapunovExponent As Double = 0
               Xn = 0.5
               'Loop throught the items in the generation string
               '    For CharItem As Integer = 0 To Sn.Length - 1
               For NCount As Integer = 1 To N

                   ' Choose the value for rn based on the current item in the generating string
                   ' You need to make the string repeatable for all the iterations hence the mod function 
                   rn = If(Sn(NCount Mod Sn.Length).ToString.ToUpper = "A", a, b)       

                   ' Create the next value of Xn
                   Xn = rn * Xn * (1 - Xn)

                   ' Calcualte the exponent value and add a small value inside the logarithm
                   ' in case the clculated value is 0
                   LyapunovExponent += Math.Log(Math.Abs(rn * (1 - 2 * Xn))) / N / Math.Log(2)
               Next

               ' Sace the exponent value to the Image array
               LyapunovLambdaArray(x, y) = LyapunovExponent


这篇关于产生Lyapunov分形的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆