Elevar un polinomio al cuadrado
조회 수: 13 (최근 30일)
이전 댓글 표시
Tengo este polinomio el cual contiene números racionales:
g = [3/2 -1/4 -1/3];
secondT = poly2sym(g); % g pero como polinomio
Lo necesito elevar al cuadrado, pero no encuetro ningúna forma para hacer esto. O sea, puedo elevar a g al cuadrado sin ningún problema:
disp(g.^2);
Pero necesito multiplicar los exponentes de la variable (x). Cuando trato de elevar secondT me da este resultado:
(x/4 - (3*x^2)/2 + 1/3)^2
댓글 수: 1
John D'Errico
2023년 9월 9일
편집: John D'Errico
2023년 9월 9일
Sorry, that my high school Spanish is far too long out of date. :( Google translate:
I have this polynomial which contains rational numbers:
g = [3/2 -1/4 -1/3];
secondT = poly2sym(g); % g but as a polynomial
I need to square it, but I can't find any way to do this. That is, I can square g without any problem:
disp(g.^2);
But I need to multiply the exponents of the variable (x). When I try to raise secondT it gives me this result:
(x/4 - (3*x^2)/2 + 1/3)^2
채택된 답변
John D'Errico
2023년 9월 9일
편집: John D'Errico
2023년 9월 9일
Easy enough.
g = [3/2 -1/4 -1/3];
gsym = poly2sym(g);
gsym^2
And as you know, it squares the polynomial, but does not expand it. Nothing stops you from using the symbolic toolbox however.
expand(gsym^2)
Could you also have done this without using the symbolic toolbox at all? Well, yes, using conv you can multiply polynomials in double precision rthmetic. But then you will be stuck with doubles, not exact fractional coefficients. If you don't push things too far though, you could have done this...
format rat
conv(g,g)
And format rat comes to save the day. Again, don't push things too far, as it has limits.
댓글 수: 4
Walter Roberson
2023년 9월 9일
sympref('PolynomialDisplayStyle', 'descend');
syms x c2 c1 c0
gsym = c2*x^2 + c1*x + c0
gsym^2
expand(ans)
so the -(3*x^3)/4 is 2 * (3/2) * (-1/4)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

