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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Supermankid
am 9 Sep. 2017
Kommentiert: Supermankid
am 11 Sep. 2017
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 Kommentare
Akzeptierte Antwort
Stephen23
am 9 Sep. 2017
Bearbeitet: Stephen23
am 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 Kommentare
Stephen23
am 11 Sep. 2017
Bearbeitet: Stephen23
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!