MATLAB Answers

How do I generate a polynomial from roots that are repeated?

1 view (last 30 days)
So I've got the roots of a polynomial from which I want to design the polynomial.
The thing is that I've got 8 roots, 4 of which are repeated. These are the roots I have:
-0.7437 - 1.4178i
-0.7437 - 1.4178i
-1.1031 + 0.1267i
-1.1031 + 0.1267i
-0.4571 + 0.9526i
-0.4571 + 0.9526i
-0.0977 + 1.0976i
-0.0977 + 1.0976i
When I do the polynomial by using the function poly, I get the polynomial that corresponds to the 8 roots but I'd like the polynomial for only the 4, non-repeated roots.
How could I do this? (I know I could probably eliminate the repeated, but I'd like a function that considers repeated roots or something).
Thanks in advance

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 28 Nov 2020
Edited: Star Strider on 28 Nov 2020
Iinteresting. I would expect no repeats, and complex conjugate values instead.
Try this:
rts = [ -0.7437 - 1.4178i
-0.7437 - 1.4178i
-1.1031 + 0.1267i
-1.1031 + 0.1267i
-0.4571 + 0.9526i
-0.4571 + 0.9526i
-0.0977 + 1.0976i
-0.0977 + 1.0976i];
Urts = unique(rts);
p1 = poly(Urts);
Ucrts = [Urts; conj(Urts)];
p2 = poly(Ucrts);
.

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 28 Nov 2020
The uniquetol function works with any real argument you give it.
It does not work with complex values, however there is a work-around for that, as well:
rts = [ -0.7437 - 1.4178i
-0.7437 - 1.4178i
-1.1031 + 0.1267i
-1.1031 + 0.1267i
-0.4571 + 0.9526i
-0.4571 + 0.9526i
-0.0977 + 1.0976i
-0.0977 + 1.0976i];
Urts = uniquetol([real(rts), imag(rts)], 0.01, 'ByRows',1);
Urts = Urts(:,1) + 1i*Urts(:,2)
Use whatever value you want for the tolerance argument. I used 0.01 here simply to demonstrate that it works.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 28 Nov 2020
Did you try just multiplying them all together?
x = linspace(-8, 5, 1000);
r1 = -0.7437 - 1.4178i
r2 = -0.7437 - 1.4178i
r3 = -1.1031 + 0.1267i
r4 = -1.1031 + 0.1267i
r5 = -0.4571 + 0.9526i
r6 = -0.4571 + 0.9526i
r7 = -0.0977 + 1.0976i
r8 = -0.0977 + 1.0976i
y = (x-r1).*(x-r2).*(x-r3).*(x-r4).*(x-r5).*(x-r6).*(x-r7).*(x-r8)
plot(x, real(y), 'r-', 'LineWidth', 2);
hold on;
plot(x, imag(y), 'b-', 'LineWidth', 2);
grid on;
legend('Real', 'Imaginary');

  2 Comments

Guillem Campins
Guillem Campins on 28 Nov 2020
Hmm the problem with that is that I need the value of the polynomial in a straight form (as in x^3+2x^2+1) more than I need the plot, and the polynomial is expressed in a very non-straight form by doing that.
Thanks for the effort, though :)
Image Analyst
Image Analyst on 28 Nov 2020
Maybe might have to use the symbolic toolbox, which I don't have, to do the multiplication.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!