Fractal Software > Programming

 Mandelbrot Set - negative and complex powers in Python

(1/3) > >>

Does anyone know Python? If yes, then when I run my program asking for a complex or negative power for z, I get an error saying "Can't put 0 to a negative or complex power", and z = starting value, and starting value = 0. But negative and complex powers still exists obviously. How can I make this work and how do other fractal softwares such as Ultra Fractal achieve this?


Have no idea about python. In UF there is some built in thing allowing executing iterations with division by zero. Don't know more. z-1 = 1/z.
Maybe trie useing some very small number say 1E-15 instead of 0. Sometimes I use conditionals if x= 0 then x = x+ 1E-15 . Even in fractal software (allowing x/0 ) it sligtly improves the result.

this might help ? from the FragM Include/ComplexBase.frag... (thanks @claude)

--- Code: ---// same as cPow
VEC2 cPower(VEC2 z, REAL n) {
  REAL r2 = dot(z,z);
  return pow(r2,n/2.0)*VEC2(cos(n*atan(z.y,z.x)),sin(n*atan(z.y,z.x)));
--- End code ---
   n shouldn't be 0 but z can be 0 ?

--- Code: ---VEC2 cPow( VEC2 z, REAL n ) {
  REAL r = length( z );
  REAL a = atan( z.y, z.x );
  return pow( r, n )*VEC2( cos(a*n), sin(a*n) );

--- End code ---

   n could be 0 and z can be 0 ?

nvGLSL handles div by 0 so I've not had this problem (I could be wrong maybe just haven't seen it yet)

Not sure on the details, but it might be that python is more a imperative language and UF is perhaps more declarative.

Imperative programming (fortran, c, java, python, etc)
The code can be seen as commands, which are executed based on some math like rules. Almost each step can be seen as a actual step in the computation.

Declarative programming (lisp, haskell, etc)
The code describes the structures, types, etc. Not really instructions, but definitions instead.

The distinction is a bit artificial and most modern programming languages use a bit of both. In a way, we could also view this as low-level VS high-level (in the context of abstraction). Compare:

--- Code: ---F = food
P = plate
H = human
    take F from P
    if P is empty
        exit loop
    if H is full
        exit loop

--- End code ---

--- Code: ---F = food
P = plate
H = human
Let H consume F from P until done

--- End code ---

The first low-level example give much insight into the details of the calculation. But if we go too deep, it becomes harder to understand as a human. Compare assembly to what actually happens in the CPU of a computer.

The second example is more high-level (or you could say deeper into abstraction, whatever direction you like). Simpler for us to understand the code, but we need to trust the compiler and computer even more. This needs strict rules on how to declare things in a sensible way, either by the users or inside the pre-coded libraries.

In a mathematical sense, z/0 does not exist. Though the limit is perfectly defined. You can always get nearer, but never reach z/0. From the UF help pages:

--- Quote ---Invalid operations
Formulas can easily perform invalid operations, such as dividing by zero. Rather than showing an error message when an invalid operation occurs, Ultra Fractal just ignores the error and calculates further. This means that the resulting image can be unpredictable if you do not pay proper attention to these special cases. See also the isInf and isNaN functions, and Compatibility.
--- End quote ---

To answer your question, yes I know (some) python. You should apply a method to catch the division by zero and deal with it.

What does Ultra Fractal do instead of dividing by 0? If you skip it, wouldn't the image be blank?


[0] Message Index

[#] Next page

Go to full version
Powered by SMFPacks Rates (Facepunch) Mod
Powered by SMFPacks SEO Pro Mod | Sitemap
Powered by Advanced Topic Prefix Pro
Powered by SMFPacks Advanced Attachments Uploader Mod