# Fractalforums

## Fractal Software => Programming => Topic started by: Adam Majewski on April 12, 2020, 01:22:23 PM

Title: DEM
Post by: Adam Majewski on April 12, 2020, 01:22:23 PM
HI

I have made image of rational map:

$$f(z) = \frac{z^2}{z^2-1}$$

full code : https://commons.wikimedia.org/wiki/File:Reversed_Basilica_Julia_set_LCM.png

It works for escape time but not for distance stimation  ( DEM/J)

My derivative is :

$$\frac{2 z}{z^2-1} - \frac{2 z^3}{(z^2-1)^2}$$

I compute it using c function :

Code: [Select]

unsigned char ComputeColorOfDEMJ(complex double z){
// https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Julia_set#DEM.2FJ

int nMax = iterMax;
complex double dz = 1.0; //  is first derivative with respect to z.
double distance;
double cabsz;
complex double z2;
complex double z2m1;
complex double t;

int n;

for (n=0; n < nMax; n++){ //forward iteration
cabsz = cabs(z);
if (cabsz > 1e60 || cabs(dz)> 1e60) break; // big values
if (cabsz< PixelWidth) return iColorOfInterior; // falls into finite attractor = interior

z2 = z*z;
z2m1 = z2 - 1.0;
t = (2*z)/z2m1 - (2*z2*z)/(z2m1 * z2m1);
dz = t * dz; //  (2*z)/(z^2-1)-(2*z^3)/(z^2-1)^2 = (2*z)/z2m1 - (2*z2*z)/(z2m1 * z2m1)
z = z2/(z2 +c ); /* forward iteration : complex quadratic polynomial */
}

distance = 2.0 * cabsz* log(cabsz)/ cabs(dz);
if (distance <distanceMax) return iColorOfBoundary; // distanceMax = BoundaryWidth*PixelWidth;
// else

return iColorOfExterior;

}

I see exterior and interior but not the boundary
Below level curves of escape time ( 7.png) and dem ( 1.png)

Title: Re: DEM
Post by: xenodreambuie on April 12, 2020, 11:34:16 PM
I think what is happening is that interior detection is taking precedence over boundary detection. Instead, just flag the point as interior, then outside the loop, check the boundary first, then if interior return interior color, else return exterior color.

While your derivative is correct, it can be simplified to -2z/(z2-1)2 by multiplying out the numerator instead.
Title: Re: DEM
Post by: Adam Majewski on April 13, 2020, 10:37:53 AM
Thx for the answer. Both tips are very important.

First I would like to make code work .

Code: [Select]
unsigned char ComputeColorOfDEMJ(complex double z){
// https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Julia_set#DEM.2FJ

int nMax = iterMax;
complex double dz = 1.0; //  is first derivative with respect to z.
double distance;
double cabsz;
complex double z2;
complex double z2m1;
complex double t;

int n;

for (n=0; n < nMax; n++){ //forward iteration
cabsz = cabs(z);
if (cabsz > 1e60 || cabs(dz)> 1e60) break; // big values
//if (cabsz< PixelWidth) { break;} // falls into finite attractor = interior

z2 = z*z;
z2m1 = z2 - 1.0;
t = (2*z)/z2m1 - (2*z2*z)/(z2m1 * z2m1);
dz = t * dz; //  (2*z)/(z^2-1)-(2*z^3)/(z^2-1)^2 = (2*z)/z2m1 - (2*z2*z)/(z2m1 * z2m1)
z = z2/(z2 +c ); /* forward iteration : complex quadratic polynomial */
}

distance = 2.0 * cabsz* log(cabsz)/ cabs(dz);
if (distance <distanceMax) return iColorOfBoundary; // distanceMax = BoundaryWidth*PixelWidth;
// else

return iColorOfInterior;

}

I have modified it. Still not work

(:-((
Title: Re: DEM
Post by: xenodreambuie on April 13, 2020, 11:37:36 AM
I missed that you are iterating z = z2/(z2 +c ). Shouldn't it be z2/z2m1 + c?

What should work is something like this (I don't use c or c++ so may not be correct):
Code: [Select]

boolean IsInterior;
...
if (cabsz< PixelWidth) IsInterior = true;

...

if (distance <distanceMax) return iColorOfBoundary;
if (IsInterior) return iColorOfInterior;
return iColorOfExterior;

As I generally combine DE and other methods into one procedure for iteration, the general hierarchy I use for checking after iteration is orbit traps, boundary, other. The other is classified by the iteration as interior/exterior/in set.
Title: Re: DEM
Post by: gerrit on April 15, 2020, 10:07:47 PM
M-set ($$z^2/(z^2-1) +c(pixel))$$ is nice too.
Zoom rendered normally and with exponential map, both using cellular orbit trap.