Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mathematica, how can I cut off the high-order terms in a polynomial?

For example, I have a polynomial y=a_0+a_1 x + ..... + a_50 x^50. Since I know that the high-order terms are imposing negligible effects on the evaluation of y, I want to cut off them and have something like y=a_0+a_1 x + ..... + a_10 x^10, the first eleven terms. How can I realize this?

I thank you all in advance.

like image 312
jengmge Avatar asked Feb 02 '14 22:02

jengmge


3 Answers

In[1]:= y = a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4;
y /. x^b_ /; b >= 3 -> 0

Out[2]= a0 + a1 x + a2 x^2
like image 137
Bill Avatar answered Sep 28 '22 15:09

Bill


The mathematically proper approach..

  Series[ a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4, {x, 0, 2}] // Normal

  -> a0 + a1 x + a2 x^2
like image 40
agentp Avatar answered Sep 28 '22 17:09

agentp


If your polynomial is actually as simple as shown, with a term for every power of x and none others, you can simply use Take or Part to extract only those terms that you want because of the automatic ordering (in Plus) that Mathematica uses. For example:

exp1 = Expand[(1 + x)^9]

Take[exp1, 5]
1 + 9 x + 36 x^2 + 84 x^3 + 126 x^4 + 126 x^5 + 84 x^6 + 36 x^7 + 9 x^8 + x^9

1 + 9 x + 36 x^2 + 84 x^3 + 126 x^4

If it is not you will need something else. Bill's replacement rule is one concise and efficient method. For more complex manipulations you may wish to decompose the polynomial using CoefficientArrays, CoefficientRules, or CoefficientList.

like image 45
Mr.Wizard Avatar answered Sep 28 '22 16:09

Mr.Wizard