gpt4 book ai didi

math - 倍频程/Matlab : How to plot the roots of a polynomial

转载 作者:太空宇宙 更新时间:2023-11-03 19:43:11 26 4
gpt4 key购买 nike

我正在尝试绘制多项式的根,但我就是做不到。

首先我创建多项式

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

关于math - 倍频程/Matlab : How to plot the roots of a polynomial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2441218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com