you may like

Tampilkan postingan dengan label newton's method. Tampilkan semua postingan
Tampilkan postingan dengan label newton's method. Tampilkan semua postingan

Jumat, 31 Juli 2009

Simple Newton's Method Fractal code in MATLAB

Due to popular request I've sharing some very simple Newton's Method Fractal code in MATLAB. It produces the following 800x800 image (in about 2.5 seconds on my 2.4Ghz Macbook Pro):


>> [niters,solutions] = matlab_fractal;
>> imagesc(niters)


function [niters,solutions] = matlab_fractal
%Create Newton's Method Fractal Image
%Tomasz Malisiewcz (tomasz@cmu.edu)
%http://quantombone.blogspot.com/
NITER = 40;
threshold = .001;

[xs,ys] = meshgrid(linspace(-1,1,800), linspace(-1,1,800));
solutions = xs(:) + i*ys(:);
select = 1:numel(xs);
niters = NITER*ones(numel(xs), 1);

for iteration = 1:NITER
oldi = solutions(select);

%in newton's method we have z_{i+1} = z_i - f(z_i) / f'(z_i)
solutions(select) = oldi - f(oldi) ./ fprime(oldi);

%check for convergence or NaN (division by zero)
differ = (oldi - solutions(select));
converged = abs(differ) < threshold;
problematic = isnan(differ);

niters(select(converged)) = iteration;
niters(select(problematic)) = NITER+1;
select(converged | problematic) = [];
end

niters = reshape(niters,size(xs));
solutions = reshape(solutions,size(xs));

function res = f(x)
res = (x.^2).*x - 1;

function res = fprime(x)
res = 3*x.^2;


Rabu, 24 Desember 2008

Newton's Method Fractal Yet Again

Yet another Newton's Method Fractal Animation. This one is created from the OpenGL C++ program I wrote some time ago on my Macbook Pro. I dumped the frames as PPMs, used ImageMagick to convert them to pngs (shell script one liner), FrameByFrame (A great free OS X product) to make a movie from frames, and iMovie to add music/titles. The song in the background is a New Deal cover of Journey's Separate Ways from 2003-02-21 (Check it out on archive.org).



In the future I plan on synchronizing the music with the fractals. Here is a cool screenshot from the movie when the background becomes white.

Kamis, 24 Juli 2008

More Newton's Method Fractals on Youtube

newtons method fractal image
I've posted another cool fractal video. I used ffmpeg and imagemagick to get the screenshots from an OpenGL C++ program running on my Macbook Pro.

Rabu, 23 April 2008

newton's method fractal

Back in high school I was 'into' newton's method fractals. Some old images can be seen by clicking on the following image


When people make fractal videos (check them out on youtube), they are usually zooming into a fixed fractal. I have generated a fractal where the axis is fixed and the equation is changing. Check it out!