Hi everyone, I want to find the polynomials from root. I want to get a value without decimal, how is that possible? Please find the example below for more clarification.

2 次查看(过去 30 天)
Hi everyone,
I want to find the polynomials from root. I want to get a value without decimal, how is that possible? Please find the example below for more clarification.
>> poly([ -0.1667 + 1.2802i -0.1667 - 1.2802i])
ans =
1.0000 0.3334 1.6667
Which could be x^2+0.3334x+1.66667=0
But how do I obtain values without decimal? 3x^2+x+5=0 is same as x^2+0.3334x+1.66667=0
my question is how do i convert
ans =
1.0000 0.3334 1.6667
TO ===>
ans =
3 1 5

采纳的回答

Stephen23
Stephen23 2017-9-9
编辑:Stephen23 2017-9-9
>> V = poly([ -0.1667 + 1.2802i -0.1667 - 1.2802i])
V =
1 0.3334 1.6667
>> [N,D] = rat(V,0.001) % get numerator and denominator
N =
1 1 5
D =
1 3 3
>> N = prod(D).*N./D % convert all to same denominator
N =
9 3 15
>> d=N(1); for k=N(2:end), d=gcd(d,k); end % find GCD
>> N = N./d % divide by GCD
N =
3 1 5
  3 个评论
Stephen23
Stephen23 2017-9-11
编辑:Stephen23 2017-9-11
@Supermankid: okay, lets have a look at this line in detail:
N = prod(D).*N./D % convert all to same denominator
As you can see from my comment, the goal of that line is to convert all of the numerators to have the same denominator. The simplest denominator to calculate (although likely not the smallest) is to make the new denominator the product of all of the denominators, thus prod(D). But observe that the three rational fractions returned by rat already have different denominators: how can we account for this? Simply by dividing the new common denominator by the existing denominators, thus
>> prod(D)./D
ans =
9 3 3
is the scaling required to ensure that all numerators have the same denominator. So multiply this by N and you have all of the numerators given with the same denominator:
>> N.*prod(D)./D % and of course this
ans =
9 3 15
>> prod(D).*N./D % is equivalent to what I used
ans =
9 3 15
And you can check it too:
>> N = N.*prod(D)./D; % convert all to same denominator
>> [N2,D2] = rat(N./prod(D))
N2 =
1 1 5
D2 =
1 3 3
which is the same as the original N and D returned by rat. So we have simply adjusted the numerator values to give exactly the same fractions, but using just one common denominator
PS. remember to accept the answer that best resolves your original question. This is the easiest way for you to thank the volunteers to help you.
Supermankid
Supermankid 2017-9-11
Hi Stephen,
Thank you for your effort in explaining it making it very simple and clear. You build clever thought to compute this algorithm. Thanks millions.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by