5
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

marked as duplicate by Artes, m_goldberg, bbgodfrey, Mr.Wizard Feb 12 '15 at 8:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Related: (71542) $\endgroup$ – Mr.Wizard Feb 11 '15 at 21:55
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) 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. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Dr. belisarius Feb 11 '15 at 22:07
6
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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})$

$\endgroup$

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