0

I have

f[x_]=Log[1+x]

g[x_]=TraditionalForm[Series[f[x], {x, 0, 4}]]

Is there a way to get the answer to print out as

Ln(1+x) = x-x^2/2+x^3/3-x^4/4+O(x^5)

I've tried to use StringJoin but this doesn't seem to work

Thanks for the help in advance

Kuba
  • 136,707
  • 13
  • 279
  • 740

2 Answers2

1

It seems that

f[x] == Series[f[x], {x, 0, 4}] // TraditionalForm

does the trick.

On a more general note, one could also use:

pretty[f_, x_, n_] := Module[{},
 f[x] == Series[f[x], {x, 0, n}] // TraditionalForm
]

like so:

pretty[f,x,4]

to get the desired output.

Note, that there is no concatenation needed. Furthermore, Mathematica does not need to splice together functions and strings (even though it could have done, easily). See TraditionalForm from Wolfram Language reference guide.

user42582
  • 4,195
  • 1
  • 10
  • 31
  • Thank you very much for this.

    How do you get the mathematica like formatting

    – NumberCruncher Aug 30 '17 at 12:03
  • you're welcome; please give an example of what you mean by "mathematica-like formating"; would https://mathematica.stackexchange.com/editing-help help out? – user42582 Aug 30 '17 at 12:50
  • That definitely helps. What I meant was formatting the text so it looks like mathematica code rather than plain text. Thanks. – NumberCruncher Aug 30 '17 at 13:11
0

Try this

StringJoin[{ToString[f[x]], " = ", ToString[g[x]]}]

$Log[1+x] = x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+O\left(x^5\right)$

Sumit
  • 15,912
  • 2
  • 31
  • 73