# Integral of x cos x: Formula, Steps and Examples

> The integral of x cos x is x sin x + cos x + C. See the integration by parts steps, a check, a graph, definite integrals and examples like x² cos x.

Source: https://practicecalculus.com/integrals/x-cos-x
Updated: 2026-11-06

$$ \int x\cos x\,dx = x\sin x + \cos x + C $$

## At a glance

- **Antiderivative:** $x\sin x + \cos x + C$
- **Method:** Integration by parts with $u = x$, $dv = \cos x\,dx$
- **From 0 to π/2:** $\frac{\pi}{2} - 1 \approx 0.571$
- **From 0 to π:** $-2$
- **With cos(kx):** $\int x\cos kx\,dx = \frac{x}{k}\sin kx + \frac{1}{k^2}\cos kx + C$

## Key takeaways

- The integral of $x\cos x$ is $x\sin x + \cos x + C$.
- Use integration by parts with $u = x$ and $dv = \cos x\,dx$, so $v = \sin x$.
- The leftover integral is $-\int\sin x\,dx = +\cos x$, so both terms are positive.
- Repeat the parts step once more for $x^2\cos x$, or use the tabular method.

The **integral of $x\cos x$ is $x\sin x + \cos x + C$**. Like $x\sin x$, it is a power of $x$ times a trig function, so integration by parts with $u = x$ does it in one step.

$$\int x\cos x\,dx = x\sin x + \cos x + C$$

## Graph of x cos x and its antiderivative

```graph
title: 'y = x cos x and its antiderivative x sin x + cos x'
caption: 'The shaded area from $0$ to $\frac{\pi}{2}$ is $\frac{\pi}{2} - 1 \approx 0.571$. The dashed antiderivative has peaks and valleys exactly where $x\cos x$ crosses zero.'
x: [-1, 7]
y: [-5.5, 7]
functions:
  - expr: x*cos(x)
    label: y = x cos x
  - expr: x*sin(x) + cos(x)
    label: y = x sin x + cos x (antiderivative)
    dashed: true
shade:
  expr: x*cos(x)
  from: 0
  to: 1.5708
points:
  - [1.5708, 0, '(π/2, 0)']
```

## How to integrate x cos x step by step

Use [integration by parts](/rules/integration-by-parts-rule), $\int u\,dv = uv - \int v\,du$.

1. **Choose the parts.** $u = x$ and $dv = \cos x\,dx$.
2. **Find $du$ and $v$.** $du = dx$ and $v = \sin x$, from the [integral of cos x](/integrals/cos-x).
3. **Apply the formula.**
$$\int x\cos x\,dx = x\sin x - \int\sin x\,dx$$
4. **Finish.** $\int\sin x\,dx = -\cos x$, and subtracting it gives $+\cos x$:
$$\int x\cos x\,dx = x\sin x + \cos x + C$$

$u = x$ is the right choice because its derivative is $1$, which wipes out the $x$. Choosing $u = \cos x$ would raise the power to $x^2$.

## Check by differentiating

$$\frac{d}{dx}\left(x\sin x + \cos x\right) = \sin x + x\cos x - \sin x = x\cos x$$

The $\sin x$ from the [product rule](/rules/product-rule) cancels the $-\sin x$ from $\cos x$.

## Definite integrals

Let $F(x) = x\sin x + \cos x$.

| Integral | Work | Value |
| --- | --- | --- |
| $\int_0^{\pi/2} x\cos x\,dx$ | $\left(\frac{\pi}{2} + 0\right) - (0 + 1)$ | $\frac{\pi}{2} - 1$ |
| $\int_0^{\pi} x\cos x\,dx$ | $(0 - 1) - (0 + 1)$ | $-2$ |
| $\int_{\pi/2}^{3\pi/2} x\cos x\,dx$ | $\left(-\frac{3\pi}{2}\right) - \frac{\pi}{2}$ | $-2\pi$ |
| $\int_{-a}^{a} x\cos x\,dx$ | odd integrand | $0$ |

The last row uses symmetry: $x\cos x$ is odd (an odd function times an even one), so the areas on the two sides cancel.

## Worked examples

**Example 1: a scaled angle.** $\int x\cos 3x\,dx$. With $u = x$ and $v = \frac{1}{3}\sin 3x$:

$$\frac{x}{3}\sin 3x - \frac{1}{3}\int\sin 3x\,dx = \frac{x}{3}\sin 3x + \frac{1}{9}\cos 3x + C$$

**Example 2: x squared.** $\int x^2\cos x\,dx$. First pass with $u = x^2$, $v = \sin x$:

$$\int x^2\cos x\,dx = x^2\sin x - 2\int x\sin x\,dx$$

The [integral of x sin x](/integrals/x-sin-x) is $\sin x - x\cos x$, so

$$\int x^2\cos x\,dx = x^2\sin x + 2x\cos x - 2\sin x + C$$

**Example 3: a linear factor.** $\int(2x - 1)\cos x\,dx$. With $u = 2x - 1$, $du = 2\,dx$:

$$(2x-1)\sin x - 2\int\sin x\,dx = (2x - 1)\sin x + 2\cos x + C$$

**Example 4: a Fourier coefficient.** In Fourier series you meet integrals like $\int_{-\pi}^{\pi}x\cos(nx)\,dx$. The integrand is odd, so the answer is $0$ for every whole number $n$, with no parts needed.

**Example 5: a hidden product.** $\int x\cos^2 x\,dx$. Write $\cos^2 x = \frac{1 + \cos 2x}{2}$ (see the [integral of cos²x](/integrals/cos-squared-x)), then

$$\int\frac{x}{2}\,dx + \frac{1}{2}\int x\cos 2x\,dx = \frac{x^2}{4} + \frac{x}{4}\sin 2x + \frac{1}{8}\cos 2x + C$$

## Common mistakes

1. **Writing $x\sin x - \cos x$.** The leftover is $-\int\sin x\,dx = -(-\cos x) = +\cos x$.
2. **Mixing it up with $x\sin x$.** Here $v = \sin x$ with no sign change; for $x\sin x$, $v = -\cos x$.
3. **Integrating factor by factor.** $\frac{x^2}{2}\sin x$ is not the answer; differentiate it to see why.
4. **Dropping the $\frac{1}{k^2}$** on the second term when the angle is $kx$.

For more practice, try the [integration by parts practice problems](/practice-problems/integration-by-parts).

## Frequently asked questions

### What is the integral of x cos x?

It is $x\sin x + \cos x + C$.

### What is the integral of x cos x from 0 to π?

It is $-2$. The antiderivative is $\pi\cdot 0 + \cos\pi = -1$ at $\pi$ and $0 + \cos 0 = 1$ at $0$, so the answer is $-1 - 1 = -2$.

### What is the integral of x² cos x?

It is $x^2\sin x + 2x\cos x - 2\sin x + C$. Use parts twice, starting with $u = x^2$.

### What is the integral of x cos(3x)?

It is $\frac{x}{3}\sin 3x + \frac{1}{9}\cos 3x + C$.
