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.
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Stephen23
on 9 Sep 2017
Edited: Stephen23
on 9 Sep 2017
>> 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 Comments
Stephen23
on 11 Sep 2017
Edited: Stephen23
on 11 Sep 2017
@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.
More Answers (0)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!