MATLAB - Image Processing - Douday's rabbit fractal

In summary: Here's my attempt at a solution. I really hope someone can point me in the right direction. My book did a very bad explaining the matter.
  • #36
interestingly enough, just a while ago, i was running through my file in which i saved my home work problems on and ran into this cell and ran it and got a monochrome image. I was like O.O weird. I ran it another time and the same thing occurred. After being in shock I did a clear, clc and ran the cell again an produced the image that I had been producing before, a multicolored image, the same exact one.

I just think it's all very weird.

Also, how would you recommend handing in a assignment in which you are learning how to use MATLAB? I would imagine the best thing to do would to be handing in a .m file were each problem is a different cell. I'm noticing that there is no really great publishing option sense they all result in errors if you have user input functions in your file that you are trying to publish.

The immediate difference that I'm running into between the different versions of MATLAB is how MATLAB's symbolic tool box used to be based off of Mapple and now it runs through MuPad. It would see that the older versions of MATLAB that used the Mapple interface were stronger at solving large polynomials and could return exact answers for really complicated expressions, some that wolfram alpha can't even solve while the newer versions of MATLAB seem not to be able to do such. My book was written back when MATLAB could solve such equations. The examples however that include making the Mandelbrot sets seem to work exactly as they should on the newest version of MATLAB and apparently were suppose to produce the same results in older versions.

I just didn't realize how drastically different the versions were. I actually understand it now lol ^_^ and agree with you that it shouldn't be producing a multicolored image, but for some unknown reason it does @_@
 
Physics news on Phys.org
  • #37
function [x, fval, exitflag, output] = pso3(objfunc, nvars)
% e=xlsread('WellData1.1.xls','n score');
x=[1 2 3;4 5 6;1 2 6];
obj =x.^3-2*x.^2+5;
% msg = (NARGCHK(1, 3, nargin));
% if ~isempty(msg)
% error('mrr:myoptim:pso:pso:narginerr', 'Inadequate number of input arguments.');
% end
%
% msg = (NARGCHK(0, 4, nargout));
% if ~isempty(msg)
% error('mrr:myoptim:pso:pso:nargouterr', 'Inadequate number of output arguments.');
% end
if nargin==1 && ischar(objfunc) && strcmp(objfunc, 'options')
if nargout<=1
x = getDefaultOptions();
else
error('mrr:myoptim:pso:pso:nargouterr', ...
'Cannot expext more than one output when only OPTIONS are required.');
end
else
if nargin<3, options=getDefaultOptions(); end

if nargout == 4
if strcmp(options.output_level, 'none')
if options.plot == 0
output_level = 0;
else
output_level = 1;
end
elseif strcmp(options.output_level, 'low')
output_level = 1;
elseif strcmp(options.output_level, 'medium')
output_level = 2;
elseif strcmp(options.output_level, 'high')
output_level = 3;
else
error('mrr:myoptim:pso:pso:eek:ptionserr:eek:utput_level', ...
'Invalid value of the OUTPUT_LEVEL options specified.');
end
else
if options.plot == 1
output_level = 1;
else
output_level = 0;
end
end
if ~all(isnan(options.vmax))
if any(isnan(options.vmax))
error('mrr:myoptim:pso:pso:eek:ptionserr:vmax', ...
'VMAX option cannot have some Inf and some numerical (or Inf) values.');
end
if ~isnan(options.vmaxscale)
warning('mrr:myoptim:pso:pso:eek:ptionserr:vmaxconflict', ...
'Both relative and absolute velocity limit are specified. The relative limit is ignored.');
end
if length(options.vmax) == 1
vmax = options.vmax*ones(nvars, 1);
elseif length(options.vmax) == nvars

if size(options.vmax, 1) ~= length(options.vmax)
error('mrr:myopim:pso:pso:eek:ptionserr:vmax', ...
'VMAX option should be specified as column-vector, or as a scalar value.');
end
vmax = options.vmax;
else
error('mrr:myoptim:pso:pso:eek:ptionserr:vmax', ...
'Inadequate dimension of VMAX option. Should be a scalar, or a column vector with NVARS elements.');
end
else

if isnan(options.vmaxscale)
error('mrr:myoptim:pso:pso:eek:ptionserr:vmaxscale', ...
'Either VMAX or VMAXSCALE options should be different than NaN.');
end

if length(options.vmaxscale) == 1
if length(options.initspan) == 1
vmax = options.vmaxscale*options.initspan*ones(nvars, 1);
else

vmax = options.vmaxscale*options.initspan;
end
else
error('mrr:myoptim:pso:pso:eek:ptionserr:vmax', ...
'Inadequate dimension of VMAXSCALE option. Must be a scalar.');
end
end
vmax = repmat(vmax', Ns, 1);


if ~isnan(options.initpopulation)

[pno, pdim] = size(options.initpopulation);
if (pno ~= Ns) || (pdim ~= nvars)
error('mrr:myoptim:pso:pso:eek:ptionserr:initpopulation', ...
['The format of initial population is inconsistent with desired population', ...
'size or dimension of search space - INITPOPULATION options is invalid']);
end
X = options.initpopulation;
elseif (length(options.initoffset) == 1) && (length(options.initspan) == 1)

X = (rand(Ns, nvars)-0.5)*2*options.initspan + options.initoffset;
elseif (length(options.initoffset) ~= size(options.initoffset, 1)) || ...
(length(options.initspan) ~= size(options.initspan, 1))
error('mrr:myoptim:pso:pso:eek:ptionserr:initoffset_initspan', ...
'Both INITOFFSET and INITSPAN options must be either scalars or column-vectors.');
elseif (length(options.initoffset) ~= nvars) || (length(options.initspan) ~= nvars)
error('mrr:myoptim:pso:pso:eek:ptionserr:init', ...
'Both INITOFFSET and INITSPAN options must be scalars or column-vectors of length NVARS.');
else
initoffset = repmat(options.initoffset', Ns, 1);
initspan = repmat(options.initspan', Ns, 1);
X = (rand(Ns, nvars)-0.5)*2.*initspan + initoffset;

if (options.trustoffset)
X(1, :) = options.initoffset';
end
end


if any(isnan(options.vspaninit))
error('mrr:myoptim:pso:pso:eek:ptionserr:vspaninit', ...
'VSPANINIT option must not contain NaN entries.');
elseif isscalar(options.vspaninit)
V = (rand(Ns, nvars)-0.5)*2*options.vspaninit;
else
if (length(options.vspaninit) ~= size(options.vspaninit, 1)) || ...
(length(options.vspaninit) ~= nvars)
error('mrr:myoptim:pso:pso:eek:ptionserr:vspaninit', ...
'VSPANINIT option must be either scalar or column-vector of length NVARS');
end
V = (rand(Ns, nvars)-0.5)*2.*repmat(options.vspaninit', Ns, 1);
end

Y = calcobjfunc(objfunc, X);
Ybest = Y;
Xbest = X;

[GYbest, gbest] = min(Ybest);

gbest = gbest(1);




tolbreak = ~isnan(options.globalmin);
foundglobal = 0;
if tolbreak && ~isscalar(options.globalmin)
error('mrr:myoptim:pso:pso:eek:ptionserr:globalmin', ...
'globalmin option, if specified, option must be a scalar value equal to the global minimum of the objective function');
end


if output_level >= 0

output.itersno = K;
if output_level >= 1

output.gbest_array = NaN*ones(K+1, 1);
output.gmean_array = NaN*ones(K+1, 1);
output.gworst_array = NaN*ones(K+1, 1);
output.gbest_array(1) = GYbest;
output.gmean_array(1) = mean(Ybest);
output.gworst_array(1) = max(Ybest);
if output_level >= 2

output.gbestndx_array = NaN*ones(K+1, 1);
output.Xbest = NaN*ones(K+1, nvars);
output.gbestndx_array(1) = gbest;
output.Xbest(1, :) = X(gbest, :);
if output_level == 3
output.X = NaN*zeros(Ns, nvars, K+1);
output.X(:,:,1) = X;
end
end
end
end

if options.verbose_period ~= 0
disp 'PSO algorithm: Initiating the optimization process.'
end


exitflag = 0;


for iter = 1:K


if options.verbose_period ~= 0
if rem(iter, options.verbose_period) == 0
disp(['iteration ', int2str(iter), '. best criteria = ', num2str(GYbest)]);
end
end


w = linrate(options.wf, options.wi, K, 0, iter);
cp = linrate(options.cbf, options.cbi, K, 0, iter);
cg = linrate(options.cgf, options.cgi, K, 0, iter);


GXbest = repmat(Xbest(gbest, :), Ns, 1);


V = w*V + cp*rand(size(V)).*(Xbest-X) + cg*rand(size(V)).*(GXbest-X);
V = min(vmax, abs(V)).*sign(V);


X = X + V;
Y = calcobjfunc(objfunc, X);

mask = Y<Ybest;
mask = repmat(mask, 1, nvars);
Xbest = mask.*X +(~mask).*Xbest;
Ybest = min(Y,Ybest);


[GYbest, gbest] = min(Ybest);
gbest = gbest(1);


if output_level >= 0

if output_level >= 1

output.gbest_array(iter+1) = GYbest;
output.gmean_array(iter+1) = mean(Ybest);
output.gworst_array(iter+1) = max(Ybest);
if output_level >= 2

output.gbestndx_array(iter+1) = gbest;
output.Xbest(iter+1, :) = X(gbest, :);
if output_level == 3

output.X(:,:,iter+1) = X;
end
end
end
end


if tolbreak && abs(GYbest - options.globalmin)<options.tol
output.itersno = iter;
foundglobal = 1;
break
end

end

if options.verbose_period ~= 0
disp 'Optimization process finished.'
end


x = Xbest(gbest, :); x = x(:);
fval = GYbest;


if foundglobal, exitflag = 1; end;


if options.plot
r = 0:K;
figure
plot(r, output.gbest_array, 'k.', r, output.gmean_array, 'r.', r, output.gworst_array, 'b.');
str = sprintf('Best objective value : %g', fval);
title(str);
legend({'best objective', 'mean objective', 'worst objective'})
end

end
function [func]= calcobjfunc(func, X)
np = size(X,1);
Y = zeros(np,1);
for i = 1:np
Y(i) = func(X(i,:));
end
function opts = getDefaultOptions
%This function, in fact, defines default values of the options within the options structure.
opts.npart = 40; % The number of particles.
opts.niter = 20; % The number of iterations.
opts.cbi = 2.5; % Initial value of the individual-best acceleration factor.
opts.cbf = 0.5; % Final value of the individual-best acceleration factor.
opts.cgi = 0.5; % Initial value of the global-best acceleration factor.
opts.cgf = 2.5; % Final value of the global-best acceleration factor.
opts.wi = 0.9; % Initial value of the inertia factor.
opts.wf = 0.4; % Final value of the inertia factor.
opts.vmax = Inf; % Absolute speed limit. It is the primary speed limit.
opts.vmaxscale = NaN; % Relative speed limit. Used only if absolute limit is unspecified.
opts.vspaninit = 1; % The initial velocity span. Initial velocities are initialized
% uniformly in [-VSPANINIT, VSPANINIT].
opts.initoffset = 0; % Offset of the initial population.
opts.initspan = 1; % Span of the initial population.
opts.trustoffset = 0; % If set to 1 (true) and offset is vector, than the offset is
% believed to be a good solution candidate, so it is included in
% the initial swarm.
opts.initpopulation = NaN; % The user-suplied initial population. If this is set to something
% meaningfull, then INITSPAN, INITOFFSET and TRUSTOFFSET are
% ignored.
opts.verbose_period = 10; % The verbose period, i.e. the number of iterations after which the
% results are prompted to the user. If set to 0, then verbosing is
% skipped.
opts.plot = 1; % If set to 1, evolution of the gbest is ploted to the user after
% the optimization process. The objective value of the best, mean
% and worse particle troughout the optimization process are plotted
% in the single graph.
opts.output_level = 'low'; % The output log level. Possible values are: 'none', 'low',
% 'medium', 'high'.
opts.globalmin = NaN; % Global minimum, used for testing only
opts.tol = 1e-6; % Precision tolerance, used for testing only
 
  • #38
this is PSO code ,
it has error in line 298
is there anyone to help me
 
  • #39
i mean here ,
function [func]= calcobjfunc(func, X)
np = size(X,1);
Y = zeros(np,1);
for i = 1:np
Y(i) = func(X(i,:));
end
 
  • #40
function Y= calcobjfunc(func, X)
np = size(X,1);
Y = zeros(np,1);
for i = 1:np
Y(i) = func(X(i,:));
end
 
  • #41
no clue dude
 
  • #42
we can't let the mathematically impossible results go
 
  • #43
can someone with MATLAB please run my code
 
  • #44
GreenPrint said:
we can't let the mathematically impossible results go

Hi Greenprint. I'm glad you have the tenacity to stick with trying to get to the bottom of this one. :)

What about single stepping through it, that's usually a really good way to expose a problem.

Firstly let's make an m-file containing a macro with the following code (I'll call mine wabbit.m)
Code:
k=k+1
z=z.^2+c;
a=(abs(z)>sqrt(5));
map(a)=k;

Now start a new interactive session (or clear your existing one) and enter the following commands.
Code:
clear
gs = 24
[x,y] = meshgrid(linspace(-1.5,1.5,gs),linspace(-1.5,1.5,gs));
z = x+y*i;
c = -.123+.745*i;
map=zeros(gs,gs);
k = 0

Here we've initialized everything that we need. Notice that I've only made the grid 24x24, so we'll have very coarse resolution, but we'll be able to easily display the matrix contents on the screen at each iteration. So if anything plays up, we'll catch it.

Now run the maco, type "wabbit". It should just display k=1, showing that you've done one iteration. We can now view the contents of "a" and "map" to see if anything unexpected is happening.

Type "a" (without quotes) at the prompt and you'll see the contents of the "a" matrix. Do the same for "map" and it should look exactly the same at this point.

Now run the macro a second time, "wabbit". Now look at "a" and "map" once more the same way as before. This timr "a" should be similar to before, but have slightly more ones and less zeros. However "map" now should contain only zeros and twos, with the twos in exactly the same place as where the ones are in "a". Check that this is what you get.

Now you can repeat this as many times as you wish. Each time you type "wabbit" the macro will do one more iteration, k will increase by one, "a" will have a few more ones (but always contain only zeros and ones) and "map" will have a few more non zero terms, (but always only contain zeros and whatever numerical value "k" currently is).

For example after five iterations map should look something like this :
Code:
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   0   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   0   0   0   0   5   0   0   0   0   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   0   5   5
 5   5   5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   0   5   5   5
 5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5
 5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5
 5   5   5   5   5   0   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5
 5   5   5   0   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5   5   5
 5   5   0   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   0   0   0   0   0   0   0   0   0   0   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   0   0   0   0   5   0   0   0   0   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   0   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5
 5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5   5

Give it a try and let me know what you get.
 
Last edited:
  • #45
Code:
>> clear
gs = 24
[x,y] = meshgrid(linspace(-1.5,1.5,gs),linspace(-1.5,1.5,gs));
z = x+y*i;
c = -.123+.745*i;
map=zeros(gs,gs);
k = 0

gs =

    24


k =

     0

>> wabbit

k =

     1

>> a

a =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> map

map =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> wabbit

k =

     2

>> a

a =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> map

map =

     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     0     0     0     0     0     0     0     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2
     2     2     2     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2
     2     2     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2
     2     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2
     2     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2
     2     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2
     2     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2
     2     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2
     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2
     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2
     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2
     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2     2
     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2     2
     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2     2     2
     2     2     0     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2     2     2     2
     2     2     2     0     0     0     0     0     0     0     0     0     0     0     0     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     0     0     0     0     0     0     0     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
 
  • #46
Code:
>> wabbit

k =

     3

>> a

a =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     1     1     0     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     0     1     1     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> map

map =

     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     0     0     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     0     0     0     0     0     3     3     0     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     3     3     3
     3     3     3     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3
     3     3     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3
     3     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3
     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3
     3     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3
     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3
     3     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3
     3     3     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3
     3     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3
     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3     3
     3     3     0     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3     3     3
     3     3     0     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3     3     3     3
     3     3     3     0     0     0     0     0     0     0     0     0     0     0     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     0     3     3     0     0     0     0     0     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     0     0     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3
     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3     3

>> wabbit

k =

     4

>> a

a =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> map

map =

     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     0     0     0     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4
     4     4     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     0     0     4     4
     4     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     0     0     0     4     4
     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4
     4     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4
     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4
     4     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4
     4     4     4     4     4     0     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4
     4     4     0     0     0     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4     4
     4     4     0     0     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4     4     4
     4     4     4     0     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     0     0     0     0     0     0     0     0     0     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     0     0     0     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4     4
 
  • #47
Code:
>> wabbit

k =

     5

>> a

a =

     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     1     0     0     0     0     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1
     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1
     1     1     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     0     0     0     0     1     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     0     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

>> map

map =

     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     0     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     0     0     0     0     5     0     0     0     0     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5
     5     5     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5     5
     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5
     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5
     5     5     5     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5
     5     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5     5     5
     5     5     0     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     0     0     0     0     0     0     0     0     0     0     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     0     0     0     0     5     0     0     0     0     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     0     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5
     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5     5

>>

It would appear as if we get the same exact results for the 5th iteration, yet we don't get the same plots when we run that one code. I posted the first 5.
 
Last edited:
  • #48
Yep everything is getting calculated exactly as I expected (and exactly the same as gnu-octave is producing here for me). You can plot those maps if you like with the command "image(map)" and of course they will be monochrome (two tone) as the maps have only two levels.

So everything works as expected when you run it step by step and look at the results before you run "image(map)". Sorry but I can't figure this out, it just has to be something that you're doing wrong/different but I don't know what.

The other really confounding thing is that the Mandlebrot example in your book apparently does the same thing and yet the image given for that one also shows a multilevel map. I would normally have put this down to a typo in the book (having a ">" where it should have been "<") except that when you copied their code you also got multilevel maps.
 
Last edited:
  • #49
BTW. One other test that you should try is to edit that little test macro (wabbit.m) so as to change the sign of the inequality as I previously suggested (from ">" to "<"). That is use the following code for the macro :
Code:
k=k+1
z=z.^2+c;
a=(abs(z) < sqrt(5));
map(a)=k;

Clear and re-initialize everything and go through the same steps as above, looking at map after each step. This time you'll see different numbers appearing in the map matrix and when you type "image(map)" you really will get a multi-tone image. Naturally the image will be very low resolution, given the small gridsize, but you'll definitely recognize a vague image of the rabbit-face developing there.

I recommend you doing this test so that you at least understand how it should work, and why I originally suggested making that change.
 
  • #50
With the following code for the marco:

Code:
k=k+1
z=z.^2+c;
a=(abs(z)>sqrt(5));
map(a)=k;
I do produce the following monochrome image after 5 iterations in attachment #1

Running the following code for the marco:

Code:
k=k+1
z=z.^2+c;
a=(abs(z) < sqrt(5));
map(a)=k;
does produce the following multi-tone image in attachment #2

running the following code still however produce the multi-tone image in attachment #3
Code:
>> iterations=80;
grid_size=500;
[x,y]=meshgrid(linspace(-1.5,1.5,grid_size),linspace(-1.5,1.5,grid_size));
c=-.123+.745*i;
z=x+y*i;
map=zeros(size(x));
for k=1:iterations
    z=z.^2+c;
    a=find(abs(z)>sqrt(5));
    map(a)=k;
end
figure(1)
image(map)
colormap(jet)

Wired my book also does an example of how to create a "movie" in which you can zoom in on a Mandelbrot set in which it uses

a= find(abs(z)>sqrt(5));

>_>
 

Attachments

  • capture2.JPG
    capture2.JPG
    20.3 KB · Views: 445
  • Capture.JPG
    Capture.JPG
    20.4 KB · Views: 464
  • Capture3.JPG
    Capture3.JPG
    36.1 KB · Views: 406
  • #51
For anyone interested, here's the same code in Python using the third party Numpy and Matplotlib modules. Linux or windows or Mac of course. I read that Numpy runs some orders of magnitude faster than Matlab and of course Python/Numpy requires no license fee.

Code:
import numpy as np
import pylab
import math

iterations = 80
N=500

x,y = np.meshgrid(np.linspace(-1.5, 1.5, N), np.linspace(-1.5, 1.5, N))

c = -0.123 + 0.745j
z = x+y*1j
map = np.zeros( (N,N))
sqrt5 = math.sqrt(5)

for k in range(iterations):
    print "iteration:",k
    z = z**2 + c
    a = np.where(np.abs(z)<sqrt5)
    map[a] = k

pylab.imshow(map)
pylab.show()

In addition to interactive sessions, the code above can be run with the debugging module pdb for line by line execution and inspection:

Code:
import pdb
...
#run when debugging desired
pdb.set_trace()
 
Last edited:
  • #52
mheslep said:
For anyone interested, here's the same code in Python

Thanks for the info mheslep. Very interesting, I'll have to take a look at those python modules. In the past I know it's been common to translate MATLAB to fortran for faster execution. I have actually translated the above code in Fortran and it is indeed several times faster than the MATLAB code (though i did it more as a sanity check in this case) BTW. Also take a look at gnu-octave for an excellent freeware MATLAB clone.Back to the question of why greenprint is getting unexpected results. Would you be able to make a quick test for us with that python code to test the conjecture that the direction of the inequality in a = np.where(np.abs(z)<sqrt5) should cause either a multi-level or a
two-level map to be produced.

In particular could you please test if replacing the above line with, a = np.where(np.abs(z)>sqrt5), causes your program to produce only a two level map (and a corresponding monochrome image).
 
  • #53
uart said:
...
Back to the question of why greenprint is getting unexpected results. Would you be able to make a quick test for us with that python code to test the conjecture that the direction of the inequality in a = np.where(np.abs(z)<sqrt5) should cause either a multi-level or a
two-level map to be produced.

In particular could you please test if replacing the above line with, a = np.where(np.abs(z)>sqrt5), causes your program to produce only a two level map (and a corresponding monochrome image).

Sure. The orginal, abs(z)<sqrt(5):
156efk4.png

and the almost(?) monochrome image obtained from
abs(z)>sqrt(5):
30lj5n9.png
 
  • #54
mheslep said:
abs(z)>sqrt(5):
30lj5n9.png
Arrh. That's exactly the image that Greenprint is getting and that we're having difficulty explaining. You see that's actually far from a two level map, there are lots of different shades and colors in that image, which implies that the map "matrix" must contain may different numbers, but I can only explain two of them!

Anyway I'm currently installing those python packages and am just about to try and reproduce you code. Hopefully I'll be able to get to the bottom of it once I see the results for myself. :)
 
  • #55
Mystery solved !

Ok once I got the python code running it didn't take long to figure out what was happening. In the end it turned out to be fairly simple, the gnu-Octave I'm using thinks infinity > sqrt(5), as do I, but Matlab and Python think otherwise.

Well actually it's the way the respective programs handle numerical overflow. There are regions on the map that begin with |z|>2, so not surprisingly when you keep repetitively squaring this you soon get a numerical overflow, (((2^2)^2)^2)^…, it only takes about 10 iterations to exceed even a double precision floating point capability. When this happens Octave returns "+inf" for the absolute value, while MATLAB and python return "nan" (not a number).

So that's it. All the lovely shading that Greenprint (and his MATLAB textbook) have been getting in their images have been purely the result of bad programming and a glitch in the way the MATLAB handles numerical overflow. :biggrin:
 
  • #56
Ah, thanks.

Numpy has a hack around for the overflow that (efficiently) forces NaN's to zeros:
http://www.scipy.org/Numpy_Example_List_With_Doc?highlight=%28NaN%29#head-c98ac710ae88aadee85e953af821e560ab316ef3

So that

Code:
   ...
    z = z**2 + c
    z = np.nan_to_num(z)
    a = np.where(np.abs(z)>sqrt5)
    map[a] = k
    ...
produces the attached image as you would expect
 

Attachments

  • nantozero.png
    nantozero.png
    6.9 KB · Views: 497
  • #57
Python-Numpy comparison with Matlab:
http://www.scipy.org/NumPy_for_Matlab_Users
 

Similar threads

Replies
2
Views
3K
Replies
2
Views
4K
Replies
1
Views
1K
Replies
2
Views
3K
Replies
1
Views
3K
Replies
11
Views
11K
Replies
5
Views
20K
Replies
2
Views
20K
Back
Top