필터 지우기
필터 지우기

How to extract powers of a symbolic polynomial?

조회 수: 24 (최근 30일)
Alina Rossi-Conaway
Alina Rossi-Conaway 2021년 3월 18일
댓글: Walter Roberson 2023년 9월 25일
I'm working with a symbolic polynomial
y = 0.96*z^3500 + 0.04*z^0
I can extract the coefficients easily with
coeffs(y)
but I cannot figure out a way to pull off the corresponding powers of z into a vector. I've tried doing some wonky stuff with logs, but nothing so far. Am I SOL?
Thank you!!

답변 (3개)

Steven Lord
Steven Lord 2021년 3월 22일
syms z
y = 0.96*z^3500 + 0.04*z^0
y = 
[coefficients, powers] = coeffs(y)
coefficients = 
powers = 
syms y positive
exponents = simplify(subs(log(powers)./log(z), z, y))
exponents = 
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 7월 19일
Different formulation for finding the exponents.
syms z
y = 0.96*z^randi(9999) + 0.04*z^randi(9999)
y = 
[coefficients, powers] = coeffs(y)
coefficients = 
powers = 
exponents = mapSymType(powers, 'power', @(Z) children(Z,2));
if powers(end) == 1; exponents(end) = 0; end
exponents
exponents = 
This particular code relies on an enhancement to children() that was made a small number of releases ago. A workaround is possible for older releases.

댓글을 달려면 로그인하십시오.


Shubham Rawat
Shubham Rawat 2021년 3월 22일
Hi Alina,
You may first find coefficients of all variables like this:
coef = sym2poly(y);
Then you can find all the index of all the non zero elements and -1 as indexing start from 1 in MATLAB:
polyPowers = find(coef) - 1;
Hope this Helps!
  댓글 수: 1
Davy Figaro
Davy Figaro 2021년 7월 19일
This is good, but because symbolic polynomial powers are presented in descending order, you need to double flip to get the polyPowers to line up to the original polynomial:
polyPowers = flip(find(flip(coef))) - 1;

댓글을 달려면 로그인하십시오.


sil das
sil das 2023년 9월 25일
(x+1)^2
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 9월 25일
Could you explain how that line of code solves the problem mentioend by @Alina Rossi-Conaway ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by