필터 지우기
필터 지우기

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