syms x a1 a2 a3 a4

n = 3;

P = a1*x^3 + a2*x^2 + a3*x + a4;

expand((-1)^n*subs(P,x,sqrt(x))*subs(P,x,-sqrt(x)))

ans =

a1^2*x^3 + 2*a1*a3*x^2 – a2^2*x^2 – 2*a2*a4*x + a3^2*x – a4^2

I suppose after each iteration, you could scale the coefficients so the leading coefficient is 1, but one would naturally do that before iteration 1, so the leading coefficient would never change from 1.

The interesting questions are how to resolve the problem when the root of largest magnitude is a complex conjugate pair, or what happens with multiple roots, etc.

]]>— Cleve ]]>

Thanks for a really interesting article on how roots() came to be. I’ve learned a lot from your posts! Regarding Fortran, have you checked out the GNU Fortran compiler? It’s Fortran 95 compliant with some newer features too, and you can download it alongside the Code::Blocks IDE to configure everything to run right out of the gate!

Peter

]]>function gif_frame(n) % gif_frame(filename) initiates making an animated gif file. % gif_frame with no arguments appends one copy of the current frame. % gif_frame(n) appends n copies of the current frame. % gif_frame('reset') "It's a wrap" persistent gif_file first if nargin == 0 n = 1; elseif isequal(n,'reset') first = false; return elseif ischar(n) gif_file = n; first = true; return end frame = getframe(1); im = frame2im(frame); [imind,cm] = rgb2ind(im,256); if first imwrite(imind,cm,gif_file,'gif','Loopcount',Inf) n = n-1; first = false; end for k = 1:n imwrite(imind,cm,gif_file,'gif','WriteMode','append') end end]]>