Tom*_*Tom 5 math matlab octave
我试图绘制多项式的根,我只是不能得到它.
首先,我创建我的多项式
p5 = [1 0 0 0 0 -1] %x^5 - 1
r5 = roots(p5)
stem (p5)
Run Code Online (Sandbox Code Playgroud)
我正在使用这个stem功能,但是我想删除干,然后绕过根.
这是可能的,是干正确的命令吗?
提前致谢,
PS:这不是作业,但非常接近,如果要求将标记它.
如果要绘制复杂的根,要在x轴上绘制实部,在y轴上绘制虚部,可以使用PLOT函数:
plot(r5,'o');
Run Code Online (Sandbox Code Playgroud)
如果你想将函数和根连在一起,你将不得不忽略复杂的根(正如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
Run Code Online (Sandbox Code Playgroud)