查看单个帖子
旧 2019-12-10, 20:30   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 八度/ Matlab:如何绘制多项式的根

我试图绘制多项式的根,但我无法理解。

首先,我创建我的多项式

p5 = [1 0 0 0 0 -1] %x^5 - 1 r5 = roots(p5) stem (p5) 我正在使用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

更多&回答...
poster 当前离线   回复时引用此帖