我试图绘制多项式的根,但我无法得到它。
首先我创建我的多项式
p5 = [1 0 0 0 0 -1] %x^5 - 1
r5 = roots(p5)
stem (p5)
我正在使用该stem
功能,但我想删除茎,然后在根周围画一个圆圈。
这可能吗,stem是正确的命令吗?
提前致谢,
PS:这不是作业,但非常接近,如果需要,会标记它。
如果您有复杂的根,您想在 x 轴上绘制实部,在 y 轴上绘制虚部,您可以使用PLOT函数:
plot(r5,'o');
如果您想将函数和根一起绘制,您将不得不忽略复杂的根(正如 yuk 在下面的评论中提到的那样):
p5 = [1 0 0 0 0 -1];
r5 = roots(p5);
realRoots = r5(isreal(r5)); %# Gets just the real roots
x = -2:0.01:2; %# x values for the plot
plot(x,polyval(p5,x)); %# Evaluate the polynomial and plot it
hold on; %# Add to the existing plot
plot(realRoots,zeros(size(realRoots)),'o'); %# Plot circles for the roots