A test case:
I'm trying to replace an expression inside a series expansion:
Series[f[x],{x,x0,4}] ./ (x-x0)->h
but it still returns
f[x0]+f'[x0](x-x0)+.....
What am I screwing up here?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityA test case:
I'm trying to replace an expression inside a series expansion:
Series[f[x],{x,x0,4}] ./ (x-x0)->h
but it still returns
f[x0]+f'[x0](x-x0)+.....
What am I screwing up here?
Here is something which works:
Normal@Series[f[x], {x, x0, 4}] /. (x - x0) -> h
The reason your attempt doesn't work can be determined by examining the FullForm
:
FullForm@Series[f[x], {x, x0, 4}]
(*SeriesData[x, x0,
List[f[x0], Derivative[1][f][x0],
Times[Rational[1, 2], Derivative[2][f][x0]],
Times[Rational[1, 6], Derivative[3][f][x0]],
Times[Rational[1, 24], Derivative[4][f][x0]]], 0, 5, 1]*)
Series
returns a SeriesData
object which doesn't look anything like what the display output looks like (as can be seen from above), and applying (x - x0) -> h
doesn't change anything because there is no (x - x0)
expression inside of the above expression.
Applying Normal
converts the SeriesData
object into a normal-looking expression, which then gets substituted using the rule (x - x0) -> h
, giving what you want.
Not the safest way:
s = Series[f[x], {x, x0, 4}];
s[[2]] = x - h;
s // Normal
$\frac{1}{24} h^4 f^{(4)}(\text{x0})+\frac{1}{6} h^3 f^{(3)}(\text{x0})+\frac{1}{2} h^2 f''(\text{x0})+h f'(\text{x0})+f(\text{x0})$