Dropping higher powers of a variable in an expression
Many a times in symbolic manipulations, I end up with lots of terms of higher powers of a variable. Is there a command to drop all the terms above a given power from a symbolic expression?
Eg: from an expression f(x)= x+ x^2 + x^3 + x^4
I want to get only upto 2nd order. i.e. g(x)= x + x^2
I also want to do this on a symbolic matrix.
This will be very useful for simplifying expressions upto lower order terms for further calculations.
@kcrisman 's solution works.. How do I apply them on a symbolic matrix? when I try them on a symbolic matrix I am getting "Attribute Error"
For the matrix. The solution provided by @DSM worked (by changing the ring of matrix elements).. Apart from that the following command also worked. R=matrix([[1,0,0],[0,1-x^2/2 +x^3,-x],[0,x,1- x^2/2]]) show(R.apply_map(lambda e: taylor(e,x,0,2))) Thanks to everyone for all the answers..