0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ why doesn't Ln[1 + x] == Series[f[x], {x, 0, 4}] // TraditionalForm work for you? $\endgroup$ – user42582 Aug 30 '17 at 11:08
  • $\begingroup$ Because when I go change f[x] then it doesn't automatically update the left hand side of the answer $\endgroup$ – NumberCruncher Aug 30 '17 at 11:20
  • $\begingroup$ f[x] == Series[f[x], {x, 0, 4}] // TraditionalForm ? $\endgroup$ – user42582 Aug 30 '17 at 11:21
  • $\begingroup$ How do I get the mathematica formatting on the question. I hope what I've typed in the question isn't misleading, I do want the answer to appear in traditional form, it's just that when I copied and pasted from mathematica it came out this way $\endgroup$ – NumberCruncher Aug 30 '17 at 11:23
  • $\begingroup$ @user42582 Oh man, that works :P Thanks very much $\endgroup$ – NumberCruncher Aug 30 '17 at 11:26
1
$\begingroup$

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.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you very much for this. How do you get the mathematica like formatting $\endgroup$ – NumberCruncher Aug 30 '17 at 12:03
  • $\begingroup$ you're welcome; please give an example of what you mean by "mathematica-like formating"; would mathematica.stackexchange.com/editing-help help out? $\endgroup$ – user42582 Aug 30 '17 at 12:50
  • $\begingroup$ That definitely helps. What I meant was formatting the text so it looks like mathematica code rather than plain text. Thanks. $\endgroup$ – NumberCruncher Aug 30 '17 at 13:11
0
$\begingroup$

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

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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