Logo by Fractal Ken - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit us on facebook
 
*
Welcome, Guest. Please login or register. March 28, 2024, 09:18:52 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: de Moivre's theorem in VBA  (Read 471 times)
0 Members and 1 Guest are viewing this topic.
Iariak
Alien
***
Posts: 26



« on: January 30, 2016, 09:49:11 PM »

So basically, I wrote a little 'program' that can draw 2D fractals in Excel using VBA. Recently I tried working the de Moivre's theorem into it so that I can get different powers of Z easier. It worked, not entirely though. Here is the code.
Code:
Sub Grid()
With Range(Cells(1, 1), Cells(600, 1000))
    .ColumnWidth = 0.08
    .RowHeight = 0.75
    .Interior.ColorIndex = 1
End With
End Sub

Sub Draw()
Dim iterCount, i, j As Double
Dim counterI, counterJ As Integer

For i = -2 To 2 Step 0.01
    counterI = counterI + 1
    counterJ = 0
    For j = -2 To 2 Step 0.01
        counterJ = counterJ + 1
        iterCount = Iterate(i, j)
        If iterCount > 2 Then Cells(counterI, counterJ).Interior.Color = RGB(0, 1200 / iterCount, 255)
        DoEvents
    Next j
Next i
End Sub
Function Iterate(ByVal j As Double, ByVal i As Double)
Dim Mag, Angle, Pi, iNew, jNew, Power As Double
If i = 0 Then Exit Function

Pi = 4 * Atn(1)
Mag = Sqr(i * i + j * j)
Angle = Atn(j / i)
Power = 4   ' <- This is the exponent

For k = 1 To 500

    iNew = (Mag ^ Power) * Cos(Angle * Power) + i
    jNew = (Mag ^ Power) * Sin(Angle * Power) + j
    
    Iterate = k
    
    If iNew = 0 Then Exit Function
    Mag = Sqr(iNew * iNew + jNew * jNew)
    If Mag > 2 Then Exit Function
    Angle = Atn(jNew / iNew)
        
Next k

End Function


In case you wanted to try it out, run Grid first, then run Draw. The exponent is set to 4, you can change it to whatever.
Now the problem is that for some reason this doesn't work at all with odd exponents cry When I try to render something with odd exponent, the image has weird cut-outs at top and bottom. Even exponents work just fine. If anybody could tell me why it doesn't work, that would be awesome.

I also wanted to try rendering Glynn Fractals which require fractional exponents, from what I understand though, the Formula doesn't really work with fractional exponents? What options would I have if I wanted to get that to work if any? I know VBA and Excel is not suitable for this kind of stuff at all  cheesy
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: January 30, 2016, 11:22:24 PM »

a picture says always more than a thousand words wink

glynn fractals indeed need fractional exponents, fractional exponents are very easy to calculate once you get the idea: multiply the distances, add the angles wink which means take the atan2 of x/y and the lengthes of your vectors, multiply the angle by your exponent, and exponentiate your length to get the desired fractional complex multiplication outcome, basically this i have tried to present in my complex multiplication tutorial wink

<a href="https://www.youtube.com/v/9n5kve9HzRo&rel=1&fs=1&hd=1" target="_blank">https://www.youtube.com/v/9n5kve9HzRo&rel=1&fs=1&hd=1</a>

Logged

---

divide and conquer - iterate and rule - chaos is No random!
Iariak
Alien
***
Posts: 26



« Reply #2 on: January 31, 2016, 10:55:59 AM »

Thanks! I made some pictures...as you can see, the sets with odd exponents don't look how they're supposed to.
Multibrot Sets
The
fractional exponents are very easy to calculate once you get the idea: multiply the distances, add the angles wink which means take the atan2 of x/y and the lengthes of your vectors, multiply the angle by your exponent, and exponentiate your length to get the desired fractional complex multiplication outcome, basically this i have tried to present in my complex multiplication tutorial wink
I believe you are refering to this?
if i is the real component and j is the imaginary component of a complex number then to get any power of that number you do.

Angle = Atn(j / i)
Mag = Sqr(i * i + j * j)        (This would be the distance from origin, absolute value, magnitude or whatever you wanna call it)
iNew = (Mag ^ Power) * Cos(Angle * Power)
jNew = (Mag ^ Power) * Sin(Angle * Power)

I already knew that, I cannot get Glynn fractals to appear using this method though and it also doesn't appear to work with odd exponents.
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #3 on: January 31, 2016, 11:18:07 AM »

thats right, this is exactly the way how complex exponents are calculated

for the odd ones, are you sure you implemented it correctly ? if you are using some kind of recursion this might be a problem, basically integer exponentiation is a repeated multiplication with the source, so odd exponents should not lead to the cut out parts of your image although it looks like a "nice error " wink
Logged

---

divide and conquer - iterate and rule - chaos is No random!
Iariak
Alien
***
Posts: 26



« Reply #4 on: January 31, 2016, 12:02:43 PM »

Well, I am absolutely NOT sure I am implementing it correctly. I can't think of a reason why it wouldn't work with odd exponents. Thanks for the help though, I will look into it  smiley
Logged
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #5 on: February 04, 2016, 06:54:16 AM »

Well, I am absolutely NOT sure I am implementing it correctly. I can't think of a reason why it wouldn't work with odd exponents. Thanks for the help though, I will look into it  smiley

  Hmm.  I don't think atn returns the same values as atan2, which might be the problem.

  https://en.wikipedia.org/wiki/Atan2#Definition_and_computation


  I don't want to lead you on a goose chase... so try an implementation in which you take the absolute value of the angle parts of inew and jnew and see if it's continuous for odd n:

    iNew = (Mag ^ Power) * abs(Cos(Angle * Power)) + i
    jNew = (Mag ^ Power) * abs(Sin(Angle * Power)) + j


  If that solves the continuity problem, you might want to code in atan2. 
Logged

Iariak
Alien
***
Posts: 26



« Reply #6 on: February 05, 2016, 10:18:02 AM »

  Hmm.  I don't think atn returns the same values as atan2, which might be the problem.
That was totally it! I used Atan2 and everything works now, even Glynn fractals cheesy thanks a lot!
Logged
M Benesi
Fractal Schemer
****
Posts: 1075



WWW
« Reply #7 on: February 06, 2016, 07:37:06 AM »

Awesome.  Glad I could help. 

  Now, I need you to code a universe in Excel.   afro   cheesy
Logged

Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
de Fermat's last theorem Complex Numbers jehovajah 3 2150 Last post March 01, 2014, 10:36:54 AM
by jehovajah
The Enigmatic Lost Theorem of Pierre Fermat Mandelbulb3D Gallery KRAFTWERK 0 434 Last post January 22, 2012, 03:36:07 PM
by KRAFTWERK
A "forgotten" theorem about complex numbers (new) Theories & Research hgjf2 3 534 Last post July 22, 2013, 04:24:32 PM
by kram1032

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.232 seconds with 24 queries. (Pretty URLs adds 0.009s, 2q)