How do I derive polynomial using given roots?

조회 수: 16 (최근 30일)
Victor
Victor 2012년 3월 1일
댓글: Steven Lord 2023년 8월 10일
Given the known roots -2 -0.5 2 4.5
I am asked to define a symbolic variable 'x'
and derive the symbolic polynomial for the given roots
I have searched google several times to no avail, can anyone help me with this?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 3월 1일
v = [-2 -0.5 2 4.5]
x= sym('x')
yourpoly = expand(prod(x-v))
  댓글 수: 2
Gollapapani
Gollapapani 2023년 8월 10일
Can it also deal with complex roots?
Steven Lord
Steven Lord 2023년 8월 10일
Try it!
r = [-1 1+3i 1-3i];
x = sym('x');
yourpoly = expand(prod(x-r))
yourpoly = 
check = solve(yourpoly)
check = 
Looks good to me. [Yes, the elements in check are in a different order than they appear in r. This is not a bug.]
Another approach, if you want to do this numerically, is to use the poly function in MATLAB. This returns the vector of coefficients, but we can write it as an expression in the symbolic variable using poly2sym.
p2 = poly(r)
p2 = 1×4
1 -1 8 10
yourpoly2 = poly2sym(p2, x)
yourpoly2 = 
Let's make sure the two results are the same.
check = isAlways(yourpoly == yourpoly2)
check = logical
1

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polynomial Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by