Octave / Matlab: how to build polynomial roots

Im trying to build the roots of a polynomial and I just can't get it.

First I create my polynomial

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

Im using the stem function, but I would like to remove the stems and just get a circle around the roots.

Is this possible, is there the right team?

Thanks in advance,

PS: This is not homework, but very close, tagging it on request.

+4
source share
1 answer

If you have complex roots that you want to build with the real part on the x axis and the imaginary part on the y axis, you can simply use PLOT :

 plot(r5,'o'); 

If you want to focus the function and the roots together, you will have to ignore the complex roots (as the yuk mentions in the comment below):

 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 
+5
source

Source: https://habr.com/ru/post/1304049/


All Articles