2
$\begingroup$

I am trying to plot a polynomial via two approaches:

  1. Take CoefficientList of the polynomial and then take Internal`FromCoefficientList, and finally replacing the value of the free parameter with a numerical value.

  2. Take the polynomial, replace the parameter with a numerical value, and then plot the resulting polynomial.

The two approaches should have given me the same plot. However when I try to check the plots, by using the following code:

Show[Plot[
  Internal`FromCoefficientList[
    CoefficientList[(1 - x) x (1 - (0.31875` (-1 + 2 x)^2)/(
        a (1 - x) x) + (0.050800781249999996` (-1 + 2 x)^4)/(
        a^2 (1 - x)^2 x^2) - (0.005397583007812499` (-1 + 2 x)^6)/(
        a^3 (1 - x)^3 x^3) + (0.0004301198959350585` (-1 + 2 x)^8)/(
        a^4 (1 - x)^4 x^4) - (
        0.000027420143365859977` (-1 + 2 x)^10)/(
        a^5 (1 - x)^5 x^5) + (1.4566951163113113`*^-6 (-1 + 2 x)^12)/(
        a^6 (1 - x)^6 x^6) - (6.63316526177472`*^-8 (-1 + 2 x)^14)/(
        a^7 (1 - x)^7 x^7) + (2.642901783988365`*^-9 (-1 + 2 x)^16)/(
        a^8 (1 - x)^8 x^8) - (9.360277151625461`*^-11 (-1 + 2 x)^18)/(
        a^9 (1 - x)^9 x^9) + (
        2.9835883420806145`*^-12 (-1 + 2 x)^20)/(
        a^10 (1 - x)^10 x^10)), {a, 1/a}], {a, 1/a}] /. a -> 0.6, {x, 
   0.1, 0.9}, PlotStyle -> Red], 
 Plot[(1 - x) x (1 - (0.31875` (-1 + 2 x)^2)/(a (1 - x) x) + (
      0.050800781249999996` (-1 + 2 x)^4)/(a^2 (1 - x)^2 x^2) - (
      0.005397583007812499` (-1 + 2 x)^6)/(a^3 (1 - x)^3 x^3) + (
      0.0004301198959350585` (-1 + 2 x)^8)/(a^4 (1 - x)^4 x^4) - (
      0.000027420143365859977` (-1 + 2 x)^10)/(a^5 (1 - x)^5 x^5) + (
      1.4566951163113113`*^-6 (-1 + 2 x)^12)/(a^6 (1 - x)^6 x^6) - (
      6.63316526177472`*^-8 (-1 + 2 x)^14)/(a^7 (1 - x)^7 x^7) + (
      2.642901783988365`*^-9 (-1 + 2 x)^16)/(a^8 (1 - x)^8 x^8) - (
      9.360277151625461`*^-11 (-1 + 2 x)^18)/(a^9 (1 - x)^9 x^9) + (
      2.9835883420806145`*^-12 (-1 + 2 x)^20)/(
      a^10 (1 - x)^10 x^10)) /. a -> 0.6, {x, 0.1, 0.9}]]

the plots don't match.

The plot is as follows: enter image description here

If anyone can clarify the issue, I would be thankful.

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Feb 1, 2022 at 14:40

1 Answer 1

6
$\begingroup$

You cannot use both $a$ and $1/a$ in CoefficientList. Let's take a more simple example, which throws an error message together with a nonsensical result:

CoefficientList[1/a + a, {a, 1/a}]
(* CoefficientList::poly: 1/a+a is not a polynomial. *)
(* {{1/a}, {1}} *)

However, weirdly, the error will not be raised if only $1/a$ is present:

CoefficientList[a, {a, 1/a}]
(* CoefficientList::poly: a is not a polynomial. *)
(* {{1/a}} *)

CoefficientList[1/a, {a, 1/a}]
(* {{0}, {1}} *)

I cannot really explain this behaviour, but the overall solution to your problem is to use only $1/a$ as a variable, because you don't really have any $a$ terms in your polynomial.

p = (1 - x) x (1 - (0.31875` (-1 + 2 x)^2)/(a (1 - x) x) + 
    (0.050800781249999996` (-1 + 2 x)^4)/(a^2 (1 - x)^2 x^2) - 
    (0.005397583007812499` (-1 + 2 x)^6)/(a^3 (1 - x)^3 x^3) + 
    (0.0004301198959350585` (-1 + 2 x)^8)/(a^4 (1 - x)^4 x^4) - 
    (0.000027420143365859977` (-1 +  2 x)^10)/(a^5 (1 - x)^5 x^5) + 
    (1.4566951163113113`*^-6 (-1 + 2 x)^12)/(a^6 (1 - x)^6 x^6) - 
    (6.63316526177472`*^-8 (-1 + 2 x)^14)/(a^7 (1 - x)^7 x^7) + 
    (2.642901783988365`*^-9 (-1 + 2 x)^16)/(a^8 (1 - x)^8 x^8) - 
    (9.360277151625461`*^-11 (-1 + 2 x)^18)/(a^9 (1 - x)^9 x^9) + 
    (2.9835883420806145`*^-12 (-1 + 2 x)^20)/(a^10 (1 - x)^10 x^10));

Internal`FromCoefficientList[CoefficientList[p, 1/a], 1/a] == p // Reduce
(* True *)

Plot[{Internal`FromCoefficientList[CoefficientList[p, 1/a], 1/a] /. a -> 0.6,
      p /. a -> 0.6}, {x, 0.1, 0.9}]

Plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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