Newton's Fractal Matlab
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I change (with minimum changes) the function I post below to built an image of a square of a complex plane formed by (2m+1) * (2m+1) points centered in the complex number z0 and semilate l.
I have to modify the color assignment to pixels using a single matrix (2m + 1) * (2m + 1) with the default color table consisting of 64 colors ( colormap(’default’) ) and I have to assign color number k to the pixel (i,j) if at the step k it results | Z(i,j) - W(i,j) | <= 10-4 | Z(i,j)| where is it W(i,j) = g(Z(i,j)). Finally i'll test the function with the rational function z+(1/z)(100-1/z)^2
Thanks in advance
function a = newton_vec(m, p)
%NEWTON
if ~exist('p', 'var')
p = [1 0 0 -1];
end
% maximum number of iterations
maxit = 20;
% roots of the polynomial p
x = roots(p);
% order them for the imaginary part
[~, i] = sort(imag(x)); x = x(i);
% grid of points in the complex plane
Z = (-m:m)./m - 1i * (-m:m).'./m;
% iteration g(z)
p1 = polyder(p);
g = @(z) z - polyval(p,z) ./ polyval(p1, z);
dist = zeros(2*m+1, 2*m+1, length(x));
for k = 1 : maxit
Z = g(Z);
end
% check which roots have come to convergence
for n = 1 : length(x)
dist(:,:,n) = abs(Z - x(n));
end
[fs, s] = min(dist, [], 3);
% matrix fs contains minimum distance -- We set corresponding
% entry in a only if fs < 1e-4 -- in the case there isn't
% convergence we use value length(x) + 1 for black.
a = (fs < 1e-4) .* s + (fs >= 1e-4) * (length(x) + 1);
end
0 Kommentare
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!