Integrate over a piecewise function [closed]

I want to calculate the indefinite Integral of

$$f(x)=\begin{cases} 2x\cos(\frac{1}{x})& \text{ if } x\ne 0 \\ 0& \text{ if } x=0 \end{cases}.$$

I use the following code:

F[x_] := Piecewise[{0, x==0}, {2*x*Cos[1/x], x != 0}];
Integrate[Piecewise[{{0, x == 0}, {2*x*Cos[1/x], x != 0}}], x]


It doesn't evaluate. I don't know why it doesn't evaluate the piecewise function.

Maybe this is quite simple question, but it's not easy for me, a greenest amateur.

• You are missing a pair of curly brackets in your Piecewise expression. Try Integrate[Piecewise[{{0, x == 0}, {2*x*Cos[1/x], x != 0}}], x] – m_goldberg Jul 7 '16 at 11:12
• @m_goldberg:Oh,I am sorry,I reedit it again.The question still remains unresolved. – Elliot Jul 7 '16 at 11:18
• Your use of Piecewise is still incorrect. Look closely at my previous comment. – m_goldberg Jul 7 '16 at 11:29

2 Answers

Plugging in

  F[x_] := Piecewise[{ {0, x == 0}, {2*x*Cos[1/x], x != 0}}];
Integrate[F[x], x]


leads to the output

Piecewise[{{2 (1/2 x^2 Cos[1/x] + 1/2 CosIntegral[1/x] -
1/2 x Sin[1/x]), x <= 0}},
I \[Pi] +
2 (1/2 x^2 Cos[1/x] + 1/2 CosIntegral[1/x] - 1/2 x Sin[1/x])]]

f = Piecewise[{{2 x Cos[1/x], x != 0}}]
Integrate[f, x, Assumptions -> x != 0] // Simplify

(* CosIntegral[1/x] + x (x Cos[1/x] - Sin[1/x]) *)