2
$\begingroup$

I'm trying to get mathematicas series function for Sin[x] to output a result that look like this:

$\sin x=\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2 n+1) !} x^{2 n+1}$

I referred to ybeltukov's answer and used his code. https://mathematica.stackexchange.com/a/71593/69835

Clear["Global`*"];
series[expr_, x_, x0_] := 
 Defer[expr = Sum[#, {n, 0, \[Infinity]}]] &[
  FullSimplify@
    SeriesCoefficient[expr, {x, x0, n}, 
     Assumptions -> {n >= 0}] (x - x0)^n]
series[Sin[x], x, 0]

$\operatorname{Sin}[x]=\sum_{n=0}^{\infty} \frac{i i^{n}\left(-1+(-1)^{n}\right) x^{n}}{2 n !}$

However, the result contains some complex numbers.

How to get the result in real number form

$\sin x=\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2 n+1) !} x^{2 n+1}$ ?

$\endgroup$

2 Answers 2

7
$\begingroup$

A slight modification

Clear["Global`*"];
series[expr_, x_, x0_] := Defer[expr = Sum[#, {n, 0, \[Infinity]}]] &[
FullSimplify[ComplexExpand[SeriesCoefficient[expr, {x, x0, 2 n + 1}]], 
Assumptions -> n >= 0 && n \[Element] Integers] (x - x0)^(2 n + 1)]

works for odd functions:

series[Sin[x], x, 0]

$\sin (x)=\sum _{n=0}^{\infty } \frac{(-1)^n x^{2 n+1}}{\Gamma (2 n+2)}$

$\endgroup$
3
  • $\begingroup$ Nice. Minor suggestion, you can add ComplexityFunction -> ((LeafCount@# + 10 Count[#, _Gamma | _Pochhammer, {0, \[Infinity]}]) &) in FullSimplify to take care of the Gamma --- see this $\endgroup$
    – user49048
    Mar 15, 2022 at 17:10
  • $\begingroup$ @user64494 Great answer! Thank you! $\endgroup$
    – lotus2019
    Mar 16, 2022 at 2:34
  • $\begingroup$ @kcr Thank you! The expression is perfect after your slight modification. $\endgroup$
    – lotus2019
    Mar 16, 2022 at 2:37
4
$\begingroup$
Entity["MathematicalFunction", "Sin"]["SeriesRepresentations"][[2]][
  x] // TraditionalForm

enter image description here

% // Activate

(* True *)

EDIT: For a cleaner display

Entity["MathematicalFunction", "Sin"]["SeriesRepresentations"][[2]][x] // 
  Activate[#, Except[Sum]] & // TraditionalForm

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you! This piece of code is great! $\endgroup$
    – lotus2019
    Mar 16, 2022 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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