1
$\begingroup$

I would like to replace all the coefficients with new conditions in a list that I specify.

For example, suppose I have the polynomial $a_1 x + a_2 x^2$.

p = a1 x + a2 x^2;
CoefficientList[p,x]

Returns the list {0,a1,a2}. I would like to replace this list from the greek alphabet ($\alpha, \beta, \gamma, \dots$) such that in this case it replaces the old coefficients with {0, $\alpha, \beta$}.

Thanks for your help!

EDIT:

In general the polynomial occurs with differences between polynomials and so I end up with (a1 + b1 + c1)x + (a2 + b2 + c2)x^2. I would still like to be able to replace this as $\alpha x + \beta x^2$.

$\endgroup$
  • $\begingroup$ what would be desired result for the input p1 = 3 + a1 x +2 x^2+ a2 x^3? $\endgroup$ – kglr Apr 5 '18 at 16:57
  • $\begingroup$ I would want it to become $p1 = 3 + \alpha x + \beta x^2 + \gamma x^3$ $\endgroup$ – Gregory Apr 5 '18 at 18:14
  • $\begingroup$ No matter what will be the structure of the coeffs, it they are constant ,i.e., independent of other variables, the current answers will be helpful... $\endgroup$ – José Antonio Díaz Navas Apr 5 '18 at 18:51
  • $\begingroup$ @JoséAntonioDíazNavas, which one in particular. I tried working with kglr's answer and greekCoeffList[(a1 - b1) x + a2 x^2] returns {$\beta, \epsilon, \zeta$}, where it should return {0, $\alpha, \beta$} $\endgroup$ – Gregory Apr 5 '18 at 19:06
  • $\begingroup$ Oh, So others except that from @kglr ;)), however, I am sure he/she correct it soon, after your comment.. $\endgroup$ – José Antonio Díaz Navas Apr 5 '18 at 19:08
2
$\begingroup$
ClearAll[greekCoeffList]
greekCoeffList = Module[{cl = CoefficientList[#, x]}, 
  cl[[2 ;;]] = Symbol /@ FromCharacterCode /@ Range[945, 945 + Length[cl] - 2]; cl] &;

Examples:

cl2 = greekCoeffList[a1 x + a2 x^2]

{0, α, β}

Expand @ FromDigits[Reverse @ cl2, x]

x α + x^2 β

cl2 = greekCoeffList[(a1 + a2) x + (b1 - b2) x^2]

{0, α, β}

Expand @ FromDigits[Reverse @ cl2, x]

x α + x^2 β

cl2 = greekCoeffList[3 + a1 x + 5 x^2 + a2 x^3]

{3, α, β, γ}

Expand @ FromDigits[Reverse @ cl2, x]

3 + x α + x^2 β + x^3 γ

$\endgroup$
  • $\begingroup$ This module seems to get confused if for example I have (a1 + a2) x + (b1 - b2) x^2 $\endgroup$ – Gregory Apr 5 '18 at 18:09
  • $\begingroup$ I updated my question to reflect this. $\endgroup$ – Gregory Apr 5 '18 at 18:21
  • $\begingroup$ @Gregory, please see the updated version. $\endgroup$ – kglr Apr 5 '18 at 19:44
1
$\begingroup$

Well, assuming that the number of your coefficients is less than the number of Greek alphabet letters:

p = a1 x + a2 x^2;
oldcoef = CoefficientList[p, x];
newcoef = Join[{First@oldcoef}, Take[EntityValue[Entity["Alphabet", "Greek::33sff"], 
EntityProperty["Alphabet", "CommonAlphabet"]], Length[oldcoef] - 1]]

$$\{0,\alpha ,\beta \}$$

so:

FromDigits[Reverse@newcoef, x]

$$\beta x^2+\alpha x$$

If you need more letters, just add to the list more characters corresponding to other languages, or those in uppercase style of the Greek language:

EntityValue[Entity["Alphabet", "Greek::33sff"], 
EntityProperty["Alphabet", "CommonAlphabetUpper"]]

$$\{A,B,\Gamma ,\Delta ,E,Z,H,\Theta ,I,K,\Lambda ,M,N,\Xi ,O,\Pi ,P,\Sigma ,T,\Upsilon ,\Phi ,X,\Psi ,\Omega \}$$

$\endgroup$
1
$\begingroup$

Treating the constant special makes things a bit messy..

 (MapIndexed[ 
      Boole[# =!= 0] x^(#2[[1]] - 1) FromCharacterCode[943 + #2[[1]]] &,
      CoefficientList[#, x]  ] /. 
          FromCharacterCode[944] -> Coefficient[#, x, 0] // Total) &@
       (3 + 2 x + 3 x^5)

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.