473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Mandelbrot trouble

93
Hi,
I wrote this little piece of code for a very simple Mandelbrot explorer some time ago. The main problem I came across was that after zooming in to a certain depth, the double data type I used couldn't go further. Is there a way to solve this problem? Thank you.
Jun 10 '07 #1
15 1973
AdrianH
1,251 Expert 1GB
Hi,
I wrote this little piece of code for a very simple Mandelbrot explorer some time ago. The main problem I came across was that after zooming in to a certain depth, the double data type I used couldn't go further. Is there a way to solve this problem? Thank you.
You can do one of two things. Use a long double, or find the repeating pattern and back off to that position when you get there.

The long double is definitely easier.


Adrian
Jun 10 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You can do one of two things. Use a long double, or find the repeating pattern and back off to that position when you get there.
Be sure to do a sizeof(long double). On Windows, double and long double are the same.
Jun 10 '07 #3
DumRat
93
Be sure to do a sizeof(long double). On Windows, double and long double are the same.
Yep. You are right. Actually I used long double in my code, but later I found out that both double and long double are only 8 bytes long. I said double because it doesn't matter. However, is there a way around this problem in another way?
Jun 10 '07 #4
DumRat
93
Just as an afterthought, I thought the patterns never actually repeat - so what do you mean by "Find the repeating pattern"?
Jun 10 '07 #5
AdrianH
1,251 Expert 1GB
Just as an afterthought, I thought the patterns never actually repeat - so what do you mean by "Find the repeating pattern"?
A mandelbrot is a fractal. Fractals always repeat.

As for double and long double being the same, that is just a MSism. Try a real compiler. ;)


Adrian
Jun 10 '07 #6
Banfa
9,065 Expert Mod 8TB
I would have though you could achieve something by scaling.

That is initially when you start your calculations you (and everyone else) tends to assume a unit scale, that is that 1 == 1.

However once you have zoomed into a certain level a double can no longer hold the difference between your scale minimum and maximum. But if a some point prior to that you instead start assuming something like 1 == 10e-100 and scale all your calculations similarly then you can actually hold much much lower values.

Another alternative if you are using C++ is rather than using a plain old double write yourself a class to hold you numbers, you can then choose the number of bits required in the significand and the exponent to suit you application.


Oh have fractals do not "repeat" they are "self similar" that is when you look at the they appear similar, however use enough decimal places they will be different. A chaotic fractal by it's nature never actually repeats, it just comes close. Not that I am saying the suggested method won't work (because i have really taken the time to understand what has been suggested) I am merely being picky about the terminology.
Jun 10 '07 #7
DumRat
93
Are you suggesting that I write my own data type, which is maybe 32, 64 bytes long?
Jun 11 '07 #8
Banfa
9,065 Expert Mod 8TB
Are you suggesting that I write my own data type, which is maybe 32, 64 bytes long?
Yes or (assuming you meant bits not bytes) even 128 bits.
Jun 11 '07 #9
Banfa
9,065 Expert Mod 8TB
BTW in the clear light of morning (as opposed to the middle of the night like my last post) I have realised that scaling wont work, the problem you are running into is running out of precision and scaling the value will not alter this so writing your own data type is the only option.

While you could do this in C or C++ a C++ class is ideally suited to do the job, in C you would end up with a structure and a bunch of functions (which is essentially what a stand alone i.e. 1 that isn't part of a class hierarchy, class is) but the C++ solution using operator overloading is more elegant.
Jun 11 '07 #10
AdrianH
1,251 Expert 1GB
BTW in the clear light of morning (as opposed to the middle of the night like my last post) I have realised that scaling wont work, the problem you are running into is running out of precision and scaling the value will not alter this so writing your own data type is the only option.

While you could do this in C or C++ a C++ class is ideally suited to do the job, in C you would end up with a structure and a bunch of functions (which is essentially what a stand alone i.e. 1 that isn't part of a class hierarchy, class is) but the C++ solution using operator overloading is more elegant.
I liked the scaling idea. You are right. Floating point numbers are scaled, that is why the point is floating. ;) But thinking about this out loud. If precision is being lost that would mean that either 1) the numbers are spanning too many bits requiring more significant figures (I don't think this is as likely) or 2) the exponent has reached its limit (I think this is more likely). If the latter is the case, scaling still may be what you need.

If I am right, then you can make a class that contains a double and a long for an extended exponential value, giving you an exponential range of +-2 billion, much greater than what a double has. For ease, I would lookup the IEEE definition of a double and use that for you base. I would, for simplicity, keep the the exponent on the double to 0 as much as possible (remember that e is not a signed value but a biased value, so 0 is actually pow(2,11-1)-1 for a double equalling 1023, wikipedia has a fairly good article on this) and move your long exponent around instead. Doing it this way should reduce the amount of coding you would have to do. Be careful and check that the value is normilised or not or your exponent can be off by 1 changing the value of your number by a factor of 2 or 1/2. Alternatively, you can just rewrite the entire floating point yourself.

As for the bot being self-similar, I thought with the right transform, they were identical, but precision was the only reason why that they are not. Granted, it would require more than a scale, it would probably need a scale and rotate at the minimum. Perhaps a skew or stretch as well. But of course, this isn't a course of study for me, so I could just be spewing out crap. ;)


Adrian
Jun 11 '07 #11
Banfa
9,065 Expert Mod 8TB
I liked the scaling idea. You are right. Floating point numbers are scaled, that is why the point is floating. ;) But thinking about this out loud. If precision is being lost that would mean that either 1) the numbers are spanning too many bits requiring more significant figures (I don't think this is as likely) or 2) the exponent has reached its limit (I think this is more likely). If the latter is the case, scaling still may be what you need.
Sorry Adrian but

The Mandlebrot fractal is contained in the area defined by the 2 points

-2 - i
1 + i

Where i is the sqrt(-1).

So when you are specifying the limits of the current bit of the fractal that you wish to examine then you are not pushing the exponent but the presision because it is likely to be a range in the order of

-1 + 0.25i
-.9999999999999999999 + 0.2500000000000000001i

It's the precision that is the problem not the exponent which is very happily in range which is why scaling wont work.

A problem with the exponent is really on likely if you happen to be examining along 1 or more of the axis i.e. where real is very close to 0 or imaginary is very close to 0.
Jun 11 '07 #12
AdrianH
1,251 Expert 1GB
Sorry Adrian but

The Mandlebrot fractal is contained in the area defined by the 2 points

-2 - i
1 + i

Where i is the sqrt(-1).

So when you are specifying the limits of the current bit of the fractal that you wish to examine then you are not pushing the exponent but the presision because it is likely to be a range in the order of

-1 + 0.25i
-.9999999999999999999 + 0.2500000000000000001i

It's the precision that is the problem not the exponent which is very happily in range which is why scaling wont work.

A problem with the exponent is really on likely if you happen to be examining along 1 or more of the axis i.e. where real is very close to 0 or imaginary is very close to 0.
So you are saying that all of the bits are going to be in use for the calculation when zooming in? What i'm saying is, are all of those significant figures? I've not dealt with fractals in a long while, so forgive my ignorance. ;)

If so, then an entirely new class would have to be made. Fun stuff. :D


Adrian
Jun 11 '07 #13
JosAH
11,448 Expert 8TB
Google for "mandelbrot integer". It can be done and has been done before.

kind regards,

Jos
Jun 11 '07 #14
Banfa
9,065 Expert Mod 8TB
Google for "mandelbrot integer". It can be done and has been done before.
But that's so boring when you can re-invent the wheel.
Jun 11 '07 #15
AdrianH
1,251 Expert 1GB
But that's so boring when you can re-invent the wheel.
;) :D


Adrian
Jun 12 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nick J Chackowsky | last post by:
Okay, here's my naive solution to coding a Mandelbrot microscope in Python... but it's so slow! Would anyone care to comment on how to speed this up? Nick. # #This uses the graphics.py...
2
by: Chris | last post by:
Below is my code for the mandelbrot set. This takes a long time to run about a minute and a 1/2. I was wondering if anyone had any ideas on improving the pixval function as this where most of the...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.