How can i use the roots function to show that all the roots of a complex number lie on a square

2 visualizaciones (últimos 30 días)
Basically i have the polynomial x^4 -16=0, and I want to plot a square showing that the roots of the polynomial represent a square. Thanks!
  3 comentarios
Pablo Doval
Pablo Doval el 16 de Nov. de 2018
i got this so far:
>> p = [1 0 0 0 -16];
>> r = roots(p)
r =
-2.0000 + 0.0000i
0.0000 + 2.0000i
0.0000 - 2.0000i
2.0000 + 0.0000i
>> abs(r)
ans =
2.0000
2.0000
2.0000
2.0000
>> plot(real(r),imag(r),'bo')
Pablo Doval
Pablo Doval el 16 de Nov. de 2018
when plotting the points on the graph it shows the four points but i want to make a square with the axis in the four points

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 16 de Nov. de 2018
Editada: James Tursa el 16 de Nov. de 2018
You are really only missing one piece to get the lines plotted. To plot the lines between the points, you first need to order the points so that the connections are along the square edges like you want. A simple way to do this is to sort by phase angle first, then add an extra point to connect the last line. E.g.,
p = [1 0 0 0 -16];
r = roots(p);
[~,a] = sort(angle(r)); % Sort by phase angle
x = real(r); x = x(a); x(end+1) = x(1); % reorder according to sort indexing, add an extra point
y = imag(r); y = y(a); y(end+1) = y(1); % reorder according to sort indexing, add an extra point
plot(x,y,'*-');
axis square
xlim([-3 3]);
ylim([-3 3]);

Más respuestas (1)

Mark Sherstan
Mark Sherstan el 16 de Nov. de 2018
Try this out:
corners = roots([1 0 0 0 -16]);
x = real(corners);
y = imag(corners);
figure(1)
plot(x,y,'*r')
xlim([-4 4])
ylim([-4 4])
untitled.png

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by