代码之家  ›  专栏  ›  技术社区  ›  Tom

八度/matlab:如何绘制多项式的根

  •  5
  • Tom  · 技术社区  · 15 年前

    我试图画出一个多项式的根,但我无法得到它。

    首先我创建我的多项式

    p5 = [1 0 0 0 0 -1] %x^5 - 1
    r5 = roots(p5)
    stem (p5)
    

    即时通讯使用 stem 函数,但我想删除茎,只得到围绕根的圆。

    这可能吗,stem是正确的命令吗?

    事先谢谢,

    附言:这不是家庭作业,但非常接近,如果有要求,会贴上标签。

    1 回复  |  直到 15 年前
        1
  •  5
  •   gnovice    15 年前

    如果你有复杂的根,你想用x轴上的实部和y轴上的虚部来绘制,你只需要使用 PLOT 功能:

    plot(r5,'o');
    

    如果你想绘制函数 把根放在一起,你将不得不忽略复杂的根(正如尤克在下面的评论中提到的那样):

    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