How can i use the roots function to show that all the roots of a complex number lie on a square
1 次查看(过去 30 天)
显示 更早的评论
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!
采纳的回答
James Tursa
2018-11-16
编辑:James Tursa
2018-11-16
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]);
0 个评论
更多回答(1 个)
Mark Sherstan
2018-11-16
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])

0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!