---
title: "Lecture 6: Całka nieoznaczona"
lecture_number: 6
has_solutions: true
has_exercises: true
file_format: mystnb
kernelspec:
  name: sagemath
  display_name: SageMath
---

```{include} ../_includes/sagecell-loader.md
```

# Całka nieoznaczona

## Funkcja pierwotna

:::{narration}

Niech będzie dana funkcja $f:X \to \rr$ na przedziale $X\subseteq \rr$.
:::

:::{prf:definition}

**Funkcją pierwotną** {index}`funkcja; pierwotna`
funkcji $f$ nazywamy
funkcję $F:X \to \rr$,
jeśli

```{math}
\forall x\in X \quad F'(x) = f(x).
```

:::

:::{prf:remark}

W powyższej definicji, jeśli przedział $X$ jest
jednostronnie lub obustronnie domknięty,
to odpowiednią pochodną $F'$ traktujemy jako jednostronną.
:::

:::{prf:example}
:class: [example]

1. Funkcje $\ln x, \pi + \ln x $ są pierwotne dla funkcji $f(x) = \frac 1 x$ na $(0,+\infty)$.

2. Funkcje $\sin x, -23 + \sin x$ są pierwotne dla funkcji $f(x) = \cos x$ na $\rr$.
:::

::::{exercise}
:label: lec-07-ex-01
:class: [exercise]

Pokażmy, że funkcje
$\tfrac 1 2 \sin^2 x,\ -\tfrac 1 2 \cos^2 x,\ -\tfrac 1 4 \cos 2x$
są pierwotne
dla funkcji $f(x) = \sin x \cos x$ na $\rr$.

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-01`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

Wystarczy policzyć pochodne tych funkcji:

$$
\Diff{}\Paren{\tfrac 1 2 \sin^2 x}
    & = \tfrac 1 2 (2 \sin x \cos x)
   =  \sin x \cos x ,
   \\
   \Diff{}\Paren{-\tfrac 1 2 \cos^2 x}
    & = -\tfrac 1 2 (-2 \cos x \sin x)
   =  \sin x \cos x ,
   \\
   \Diff{}\Paren{-\tfrac 1 4 \cos 2x}
    & = -\tfrac 1 4 (-\sin 2x \cdot 2)
   = \tfrac 1 2 (2\sin x \cos x)
   =  \sin x \cos x .
$$

:::

:::{prf:theorem}

Jeśli $f:X\to \rr$ jest ciągła na przedziele $X\subseteq \rr$,
to istnieje jej funkcja pierwotna.
:::

:::{prf:example}
:class: [example]

Twierdzenie nie jest prawdziwe w przeciwną stronę.

Istnieją nieciągłę funkcje $f$, dla których istnieją funkcje pierwotne.

Dla przykładu niech:

$$
f(x) & =
   \begin{cases}
      2x \cos \frac 1 x + \sin \frac 1 x, & \text{dla } x\neq 0 \\
      0,                   & \text{dla } x=0
   \end{cases},
        &
   F(x) & =
   \begin{cases}
      x^2 \cos \frac 1 x, & \text{dla } x\neq 0 \\
      0,         & \text{dla } x=0
   \end{cases}.
$$

1. Pokażmy, że $f$ nie jest ciągła w $x=0$.

   Weźmy ciąg

   $$
   a_n = \frac 1 {\tfrac \pi 2 + 2 \pi n} \LimToInfty 0,
   $$

   dla którego

   $$
   f(a_n)
   = \frac {2 \cos \Paren{\tfrac \pi 2 + 2 \pi n}} {\tfrac \pi 2 + 2 \pi n}
   + \sin \Paren{\tfrac \pi 2 + 2 \pi n}
   = \frac {2 \cos {\tfrac \pi 2 }} {\tfrac \pi 2 + 2 \pi n}
   + \sin {\tfrac \pi 2}
   = 1 \LimToInfty 1.
   $$

   Zatem $\LimIn{0} f(x) \neq 0 = f(0)$
   (bez względu na to czy granica istnieje).

2. Pokażmy, że $F'(x) = f(x)$.

   - Dla $x \neq 0$ funkcja $F$ jest różniczkowalna jako iloczyn funkcji różniczkowalnych
     i jej pochodna jest równa

     $$
     F'(x) = 2x \cos \tfrac 1 x - x^2 \sin \tfrac 1 x \cdot \Paren{- \tfrac 1 {x^2}}
     = 2x \cos \tfrac 1 x + \sin \tfrac 1 x .
     $$

   - Dla $x = 0$ skorzystamy z definicji pochodnej:

     $$
     F'(0) = \LimIn[\DeltaX] 0 \frac {F(0 + \DeltaX) - F(0)} { \DeltaX}
     = \LimIn[\DeltaX] 0 \frac {\DeltaX^2 \cos \tfrac 1 {\DeltaX} } { \DeltaX}
     = \LimIn[\DeltaX] 0 {\DeltaX \cdot \cos \tfrac 1 {\DeltaX} } = 0,
     $$

     ponieważ $\DeltaX \LimTo[\DeltaX]{0} 0$ oraz $\Absolute{\cos \tfrac 1 {\DeltaX}} \leq 1$.
:::

## Definicja całki nieoznczonej

:::{prf:theorem} podstawowe o funkcjach pierwotnych

Niech $X\subseteq \rr$ będzie przedziałem.

Jeśli $F:X\to\rr$ jest funkcją pierwotną funkcji $f:X\to\rr$, to:

- dla każdej stałej $C\in\rr$, funkcja $ F_C(x) = F(x) + C$
  jest funkcją pierwotną $f$

- jeśli $F_1$ i $F_2$ są funkcjami pierwotnymi $f$, to
  istnieje stała $C\in\rr$ taka, że $F_2(x) = F_1(x) + C$.
:::

:::{prf:remark}

[GEOGEBRA](https://www.geogebra.org/calculator/rqfmmc9m)
W powyższym twierdzeniu bardzo istotne jest założenie, że $X$ jest przedziałem.

Na przykład

$$
F_1(x) & = \ln |x|,
       &
   F_2(x) & =
   \begin{cases}
      \ln x +\pi, & \text{dla } x > 0 \\
      \ln (-x),   & \text{dla } x < 0
   \end{cases}
$$

są funkcjami pierwotnymi $f(x) = \dfrac 1 x,$
ale $\forall C \in \rr \quad F_2(x) \neq F_1(x) + C .$
:::

:::{prf:corollary}

Jeśli $X\subseteq \rr$ jest przedziałem
i istnieje $F:X \to \rr$ funkcja pierwotna $f:X \to \rr$,
to

$$
\Int{ f(x)} = \Set{F(x) + C : C \in \rr}
$$

jest zbiorem wszystkich funkcji pierwotnych $f$.
:::

:::{prf:definition}

**Całką nieoznaczoną** {index}`całka; nieoznaczona`
funkcji $f:X\to \rr$ na przedziale $X$ nazywamy zbiór
$\Int{ f(x)}$
z powyższego wniosku.
:::

:::{narration}

Zwyczajowo, jeśli $F$
jest pewną funkcją pierwotną $f$ na przedziale $X$, to piszemy:

$$
\begin{aligned}
\Int{ f(x)} & = F(x) + C,
&
\Int{ F'(x)} = F(x) + C.
\end{aligned}
$$

:::

::::{tip}

Podstawowe całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle \Int{ x^{\alpha} } = \dfrac {x^{\alpha +1}} {\alpha +1} + C \quad$
   dla $\alpha \in \rr\setminus\Set{-1} $
2. $\displaystyle \Int{ \frac 1 x } = \ln |x| + C $
3. $\displaystyle \Int{ a^x  } =  \dfrac{a^x}{\ln a} + C \quad$
   dla $a \in \rr_+ \setminus \Set{1} $
4. $\displaystyle \Int{ \sin x } = -\cos x + C $
5. $\displaystyle \Int{ \cos x } = \sin x + C $
6. $\displaystyle \Int{  \frac 1 {\cos^2 x}} = \tg x + C $
7. $\displaystyle \Int{  \frac 1 {\sin^2 x}} = \ctg x + C $
8. $\displaystyle \Int{  \frac 1 {\sqrt{1- x^2}}} = \arcsin x + C $
9. $\displaystyle \Int{ \frac 1 {1 + x^2}} = \arctg x + C .$
:::

::::

## Działania na całkach

::::{prf:theorem} o działaniach arytmetycznych na całkach
:oasis-title: Twierdzenie o działaniach arytmetycznych na całkach

Niech $X$ będzie przedziałem i niech $f,g:X \to \rr$ będą funkcjami,
dla których istnieją funkcje pierwotne.

Wówczas:

1. $\displaystyle \Int{c\cdot f(x)} = c\cdot \Int{f(x)},$
2. $\displaystyle \Int{f(x) \pm g(x)} = \Int{f(x)} \pm \Int{g(x)},$
3. jeśli
   $\forall x \in X \ f(x)\neq 0$
   i
   $f$ jest różniczkowalna,
   to
   $\quad \displaystyle \Int{ \frac {f'(x)}{f(x)}} = \ln\left| f(x) \right| + C.$

::::

::::{exercise}
:label: lec-07-ex-02
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle \Int{(x^2 - 2x) \sqrt[3]{x}}$
2. $\displaystyle \Int{ \tg x } $
3. $\displaystyle \Int{ \frac 1 {3x -2} } $
4. $\displaystyle \Int{ \frac x {x^2 - 1} +5\,\ctg x }.$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-03`, {numref}`prob-07-ex-05`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

body_01 = latex((x ^ 7 / 3 - 2 * x ^ 4 / 3).integrate(x))
content = rf"""
\displaystyle
\Int{{(x^2 - 2x) \sqrt[3]{{x}}}}
= \Int{{x^{{\frac 7 3}} - 2x^{{\frac 4 3}}}}
= \dfrac {{ x^{{\frac 7 3 + 1}}}} {{\frac 7 3 + 1}}
- 2\dfrac {{ x^{{\frac 4 3 + 1}}}} {{\frac 4 3 + 1}} + C
= {body_01} + C
\;
"""
glue('sageglue_6_0', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. {glue:}`sageglue_6_0`

2. $
   \displaystyle
   \Int{ \tg x }
   = \Int{ \frac {\sin x} {\cos x} }
   = \Int{ - \frac {(\cos x)'} {\cos x} }
   = - \ln |\cos x| + C
   $

3. $
   \displaystyle
   \Int{ \frac 1 {3x -2} }
   = \Int{ \frac 1 3 \cdot\frac 3 {3x -2} }
   =  \frac 1 3 \cdot \Int{ \frac {(3x -2)'} {3x -2} }
   = \frac 1 3 \ln |3x -2| + C
   $

4. Korzystając ze wszystkich własności zapisanych w twierdzeniu,

   $$
   \begin{aligned}
   \Int{ \frac x {x^2 - 1} +5\,\ctg x }
   & = \Int{ \frac 1 2 \cdot \frac {2x} {x^2 - 1}}
   +5\cdot \Int { \frac {\cos x} {\sin x} }
   \\ &
   = \frac 1 2 \cdot \Int{ \frac {(x^2 - 1)'} {x^2 - 1}}
   +5\cdot \Int { \frac {(\sin x)'} {\sin x} }
   \\ &
   = \frac 1 2 \ln \Absolute{x^2 - 1} + 5 \ln\Absolute{\sin x} + C
   .
   \end{aligned}
   $$

:::

:::{prf:theorem} o całkowaniu przez części
:oasis-title: Twierdzenie o całkowaniu przez części

Niech $X$ będzie przedziałem i niech $f,g:X \to \rr$ będą funkcjami
różniczkowalnymi oraz $f',g':X \to \rr$ będą ciągłe.

Wówczas

$$
\Int{f(x)\cdot g'(x)} = f(x)\cdot g(x) - \Int{f'(x)\cdot g(x)}.
$$
:::

::::{exercise}
:label: lec-07-ex-03
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle \Int{ \ln x } $
2. $\displaystyle \Int{x\,\sin x} $
3. $\displaystyle \Int{ \frac {\ln x} {x^3} } $
4. $\displaystyle \Int{ x\, \arctg x } .$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-02`, {numref}`prob-07-ex-04`, {numref}`prob-08-ex-08`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \ln x } ="
   r"\Int{ \ln x \cdot 1 } & ="
)
content = IntegrationByPartsNewline(x, ln(x), 1 + 0*x, '')
part_3 = (
   r"\\ & = x \ln x - \Int 1 "
   r"\\ & = x \ln x - x + C "
   r"\\ & = x \Paren{\ln x - 1} + C "
)
glue("sageglue_integration_6_0", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{x\,\sin x} & ="
)
content = IntegrationByPartsNewline(x, x, sin(x), '.(.)')
part_3 = (
   r"\\ & = -x \cos x + \Int{\cos x} "
   r"\\ & = -x \cos x + \sin x + C "
)
glue("sageglue_integration_6_1", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \frac {\ln x} {x^3} } ="
   r"\Int{ \ln x \cdot \frac {1} {x^3} } & ="
)
content = IntegrationByPartsNewline(x, ln(x), x^(-3), '.(.)')
part_3 = (
   r"\\ & = - \frac {\ln x} { 2x^2} + \frac 1 2 \cdot \Int {\frac 1 {x^{3}}} "
   r"\\ & = - \frac {\ln x} { 2x^2} - \frac 1 4 \cdot{\frac 1 {x^{2}}} + C "
)
glue("sageglue_integration_6_2", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```


```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\renewcommand{\arctan}{\arctg}"
   r"\displaystyle \Int{ x\, \arctg x } & ="
)
content = IntegrationByPartsNewline(x, atan(x), x, '')
part_3 = (
   r"\\ & = \frac 1 2 x^2 \arctg x - \frac 1 2 \Int{ \frac {\Paren{1 + x^2} - 1}{ 1 + x^2}} "
   r"\\ & = \frac 1 2 x^2 \arctg x - \frac 1 2\Brack{\Int{1} - \Int{ \frac {1}{ 1 + x^2}}} "
   r"\\ & = \frac 1 2 x^2 \arctg x - \frac 1 2\Paren{x - \arctg x} + C ."
)
glue("sageglue_integration_6_3", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Na początek podchwytliwy przykład, gdzie wydaje się, że brakuje drugiego czynnika:

   ```{glue:math} sageglue_integration_6_0
   ```

2. Najprostszy przykład całkowania iloczynu wielomianu i funkcji sinus:

   ```{glue:math} sageglue_integration_6_1
   ```

3. Kolejny przykład z funkcją logarytmiczną:

   ```{glue:math} sageglue_integration_6_2
   ```

4. Wykorzystujemy fakt, że pochodna $\arctg$ jest funkcją wymierną:

   ```{glue:math} sageglue_integration_6_3
   ```

:::

::::{exercise}
:label: lec-07-ex-04
:class: [exercise]

Policzmy całkę nieoznaczoną
$I = \displaystyle\Int{\sin^2 x}. $

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-02`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"I = \Int{\sin^2 x} & ="
)
content = IntegrationByPartsNewline(x, sin(x), sin(x), '.(.)')
part_3 = (
   r"\\ & = -\sin x \cos x + \Int{ 1 - \sin^2 x }"
   r"\\ & = -\sin x \cos x + x - \Int{ \sin^2 x }"
   r"\\ & = -\sin x \cos x + x - I + 2C"
   r"."
)
glue("sageglue_integration_6_4", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Zaczynamy o całkowania przez części:

```{glue:math} sageglue_integration_6_4
```

W konsekwencji otrzymujemy:

$$
2I & = x -\sin x \cos x + 2C
   \\
   \Int{\sin^2 x} = I & = \tfrac 1 2 \Paren{x -\sin x \cos x} + C
   .
$$

:::

:::{prf:remark}

Całkowanie przez części można zastosować kilka razy.

Ta metoda pozwala
obliczyć całki:

$$
\begin{aligned}
\Int{w(x)\ a^{\alpha x}},   &  &
\Int{w(x) \log_a \alpha x},
\\
\Int{w(x) \sin \alpha x},   &  &
\Int{w(x) \cos \alpha x},
\end{aligned}
$$

gdzie $\alpha\in\rr,\ a \in \rr_+ \setminus \Set 1$,
zaś $w\in\rr[x]$ jest dowolnym wielomianem.
:::

::::{exercise}
:label: lec-07-ex-05
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle\Int{ x^2 e^x } $
2. $\displaystyle\Int{ e^{-x} \cos x } .$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-02`, {numref}`prob-07-ex-04`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ x^2 e^x }"
   r"& ="
)
part_2 = IntegrationByPartsNewline(x, x^2, e^x, '')
part_3 = (
   r"\\ & = x^2 e^x - 2 \Int{x e^x } ="
)
part_4 = IntegrationByPartsPrepare(x, x, e^x)
part_5 = (
   r"\\ & = x^2 e^x - 2\cdot\Brack{"
)
part_6 = IntegrationByPartsSummed(x, x, e^x, '')
fourth = (
   r"=}"
   r"\\ & = x^2 e^x - 2 \cdot \Paren{x e^x - e^x} + C"
   r"= \Paren{x^2 - 2 x + 2} e^x + C"
   r""
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}{part_6}{fourth}
"""
glue('sageglue_integration_6_5', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"I = \Int{ e^{-x} \cos x }"
   r"& ="
)
part_2 = IntegrationByPartsNewline(x, e^(-x), cos(x), '')
part_3 = (
   r"\\ & ="
)
part_4 = IntegrationByPartsPrepare(x, e^(-x), sin(x))
part_5 = (
   r"\\ &"
   r"= e^{-x} \sin x +"
   r"\Paren{"
)
part_6 = IntegrationByPartsSummed(x, e^(-x), sin(x), '.(.)')
fourth = (
   r"}"
   r"\\ &"
   r"= e^{-x}\Paren{\sin x - \cos x} - \Int{ e^{-x} \cos x }"
   r"= e^{-x}\Paren{\sin x - \cos x} - I + 2C ."
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}{part_6}{fourth}
"""
glue('sageglue_integration_6_8', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Ponieważ wielomian $x^2$ jest stopnia 2, to dwukrotnie zastosujemy całkowanie przez części:

   ```{glue:math} sageglue_integration_6_5
   ```

2. Zaczynamy o dwukrotnego całkowania przez części:

   ```{glue:math} sageglue_integration_6_8
   ```

   W konsekwencji otrzymujemy:

   $$
   2I & = e^{-x}\Paren{\sin x - \cos x} + 2C
   \\
   \Int{ e^{-x} \cos x } = I & = \tfrac 1 2 {e^{-x}} \Paren{\sin x - \cos x} + C .
   $$

:::

:::{prf:theorem} o całkowaniu przez podstawienie $t=h(x)$
:oasis-title: Twierdzenie o całkowaniu przez podstawienie $t=h(x)$

Niech $X, T$ będą przedziałami oraz załóżmy, że:

- funkcja $h:X \to \rr$ jest
   różniczkowalna i $h(X) = T$
- funkcja $g:T \to \rr$ ma funkcję pierwotną $G:T \to \rr$
- funkcja $f:X \to \rr$ jest postaci $f(x) = g\circ h(x) \cdot h'(x)$.

Wówczas, na $X$,

$$
\Int{f(x)} & =
   \Int{g(h(x)) \cdot h'(x)} =
   \WaveBrack{
   t       & = h(x)   \\
   dt      & = h'(x)\ dx
   }
   =
   \Int[t]{g(t)} =
   \\ &=
   \left(G(t) + C\right)_{t = h(x)} =
   G(h(x)) + C.
$$

:::

::::{exercise}
:label: lec-07-ex-06
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle\Int{ \frac {x}{(x^2 + 1)^2}  } $
2. $\displaystyle\Int{\frac {\sin x}{1 + 2\cos x}}  $
3. $\displaystyle\Int{\frac {\sqrt{1+\ln x}} {x}}  $
4. $\displaystyle \Int{\frac {\sin 2x} { 1 + \sin^4 x}} .$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-03`, {numref}`prob-07-ex-05`, {numref}`prob-08-ex-08`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \frac {x}{(x^2 + 1)^2}  }"
   r"& ="
   r"\Int{ \frac {1}{(x^2 + 1)^2} \cdot x  }"
   r"\\ & ="
)
content = IntegrationBySubstitutionIPrepare(x, 't', x^2 + 1, 'x dx = \\tfrac 1 2 \\ dt')
part_3 = (
   r"\\ &"
   r"= \Int[t]{ \frac {1}{t^2} \cdot \tfrac 1 2 }"
   r"= \tfrac 1 2 \cdot \Int[t]{ t^{-2} }"
   r"\\ & = \tfrac 1 2 \cdot \Paren{-t^{-1}} + C"
   r"= - \frac {1}{2(x^2 + 1)} + C"
   r""
)
glue("sageglue_integration_6_11", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\frac {\sin x}{1 + 2\cos x}}"
   r"& = \Int{\frac {1}{1 + 2\cos x}\cdot \sin x }"
   r"\\ & ="
)
content = IntegrationBySubstitutionIPrepare(x, 't', 1+ 2*cos(x), '\\sin x \\ dx = - \\tfrac 1 2 \\ dt')
part_3 = (
   r"\\ &"
   r"= \Int[t]{ \frac 1 t \cdot(- \tfrac 1 2) }"
   r"= -\tfrac 1 2 \ln |t| + C"
   r"= -\tfrac 1 2 \ln |1+2 \cos x| + C"
   r""
)
glue("sageglue_integration_6_12", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\frac {\sqrt{1+\ln x}} {x}}"
   r"& ="
   r"\Int{ \sqrt{1+\ln x}\cdot \frac 1 {x}}"
   r"="
)
content = IntegrationBySubstitutionIPrepare(x, 't', 1+ ln(x), '')
part_3 = (
   r"\\ &"
   r"= \Int[t]{\sqrt{t}}"
   r"= \Int[t]{t^{\frac 1 2} }"
   r"= \tfrac 2 3 t^{\frac 3 2} + C"
   r"= \tfrac 2 3 (1 + \ln x)^{\frac 3 2} + C"
   r""
)
glue("sageglue_integration_6_13", Math(r"\begin{aligned}" + part_1 + content + part_3 + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Policzmy całki nieoznaczone:

1. Podstawiamy podstawę mianownika, widząc, że licznik jest proporcjonalny do jej pochodnej:

   ```{glue:math} sageglue_integration_6_11
   ```

2. Podobnie tutaj:

   ```{glue:math} sageglue_integration_6_12
   ```

3. Pochodna funkcji logarytmicznej jest proporcjonalna do jednego z czynników, więc:

   ```{glue:math} sageglue_integration_6_13
   ```

4. Na koniec coś trudniejszego:

   $$
   \Int{\frac {\sin 2x} { 1 + \sin^4 x}}
   & =
   \Int{\frac {1} { 1 + \sin^4 x}\cdot 2\sin x \cos x}
   = \WaveBrack{
   t  & = \sin^2 x      \\
   dt & = 2\sin x \cos x \ dx
   }
   \\ &
   \Int[t]{\frac 1 {1+t^2} }
   = \arctg t + C
   = \arctg \Paren{\sin^2 x} + C
   .
   $$

:::

:::{prf:theorem} o całkowaniu przez podstawienie $x=\varphi(t)$
:oasis-title: Twierdzenie o całkowaniu przez podstawienie $x=\varphi(t)$

Niech $X, T$ będą przedziałami oraz załóżmy, że:

- funkcja $\varphi:T \to \rr$ jest
  różniczkowalna, różnowartościowa i $\varphi(T) = X$
- funkcja $f:X \to \rr$ ma funkcję pierwotną $F:X \to \rr$.

Wówczas, na $X$,

$$
\Int{f(x)} & =
   \WaveBrack{
   x       & = \varphi(t)   & \varphi^{-1}(x) = t \\
   dx      & = \varphi'(t)\ dt & t \in T
   }
   =
   \Int[t]{f(\varphi(t))\cdot \varphi'(t) }
$$

:::

::::{exercise}
:label: lec-07-ex-07
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle \Int{ \arccos x } $
2. $\displaystyle \Int{ \sqrt{9 - x^2} } .$

:::

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-07-ex-03`, {numref}`prob-07-ex-04`, {numref}`prob-07-ex-05`, {numref}`prob-08-ex-08`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \arccos x } & ="
)
part_2 = IntegrationBySubstitutionIIPrepare(t, 'x', cos(t), '\\arccos x = t', 't\\in[0,\\pi]')
part_3 = (
   r"= \Int[t]{ t\cdot (-\sin t} ) \\ & ="
)
part_4 = IntegrationByParts(t, t, - sin(t), '')
part_5 = (
   r"\\ &"
   r"= t \cos t - \sin t + C"
   r"= \arccos x \cdot x - \sin \Paren{\arccos x} + C "
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}
"""
glue('sageglue_integration_6_14', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)

```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \sqrt{9 - x^2} } & ="
)
part_2 = IntegrationBySubstitutionIIPrepare(t, 'x', 3*sin(t), '\\arcsin \\tfrac x 3 = t', 't\\in\\Brack{-\\tfrac \\pi 2, \\tfrac \\pi 2]}')
part_3 = (
   r"= \Int[t]{\sqrt{9 - 9\sin^2 t}\cdot 3\cos t  }"
   r"\\ &"
   r"= 9\cdot \Int[t]{|\cos t|\cdot \cos t  }"
   r"= 9\cdot \Int[t]{\cos^2 t }"
   r"= 9\cdot \Int[t]{\tfrac 1 2 \Paren{1 + \cos 2t} }"
   r"\\ &"
   r"= \WaveBrack{"
   r"u  & = 2t    \\"
   r"du & = 2\ dt"
   r"}"
   r"= \frac 9 4 \cdot \Int[u]{1 + \cos u }"
   r"= \frac 9 4 \Paren{u +  \sin u} + C"
   r"\\ &"
   r"= \frac 9 4 \Paren{2t + \sin 2t} + C"
   r"= \frac 9 4 \Paren{2t + 2\sin t \cos t} + C"
   r"\\ &"
   r"= \frac 9 4 \Paren{2t + 2\sin t \sqrt{1- \sin^2 t}} + C"
   r"\\ & = \frac 9 2 \Paren{\arcsin \frac x 3 + \frac x 3 \sqrt{1 - \Paren{\frac x 3}^2}} + C"
   r"."
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_16', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Na początek pozbądźmy się funkcji cyklometrycznej:

   ```{glue:math} sageglue_integration_6_14
   ```

2. Standardowy trik z wykorzystaniem *jedynki trygonometrycznej*:

   ```{glue:math} sageglue_integration_6_16
   ```

:::

::::{prf:remark}

Nie każdą całkę "można obliczyć".

Mówiąc precyzyjniej, wyróżniamy
**funkcje elementarne** {index}`funkcje; elementarne`:
potęgowe, wykładnicze, trygonometryczne, odwrotne do nich,
oraz ich sumy, różnice, iloczyny, ilorazy i złożenia.

Okazuje się, że nie każda całka z funkcji elementarnej
wyraża się w postaci funkcji elementarnej.

Przykłady takich całek:

:::{container} columns-3-auto

1. $\displaystyle\Int{ \frac {\sin x} {x} }\ $
2. $\displaystyle\Int{ \frac {\cos x} {x} }\ $
3. $\displaystyle\Int{ \frac {e^{\pm x}} {x} }\ $
4. $\displaystyle\Int{ {e^{\pm \frac 1 x}}  }\ $
5. $\displaystyle\Int{  {e^{\pm x^2}}  }\ $
6. $\displaystyle\Int{ \frac {1} { \ln x }}\ $
7. $\displaystyle\Int{ \frac {1} { \sqrt{x^3 + 1}} }\ $
8. $\displaystyle\Int{ \sin x^2 }\ $
9. $\displaystyle\Int{ \cos x^2 }\ $

:::

oraz, dla $\alpha\notin \nn\cup\Set{0}$,

:::{container} columns-3-auto

10. $\displaystyle\Int{x^\alpha e^{\pm x}} \ $
11. $\displaystyle\Int{x^\alpha\sin x} \ $
12. $\displaystyle\Int{x^\alpha\cos x} \ $

:::

a także całki eliptyczne 1. i 2. rodzaju (dla $-1 < k < 1$):

:::{container} columns-2-auto

13. $\displaystyle\Int{ \frac {1} { \sqrt{1 - k^2\sin^2 x}} }\ $
14. $\displaystyle\Int{ { \sqrt{1 - k^2\sin^2 x}} }\ $.

:::

::::

## Całkowanie funkcji wymiernych

### Funkcje wymierne właściwe

:::{narration}

Przypomnijmy, że **funkcją wymierną** {index}`funkcja; wymierna`
nazywamy funkcję zadaną przez
$x \mapsto\dfrac{f(x)}{g(x)},$ gdzie $f,g$ są wielomianami i $\deg g \geq 0$,
określoną dla wszystkich $x\in\rr$, takich że
$g(x)\neq 0$.

**Właściwą** {index}`funkcja; wymierna właściwa`
nazywamy funkcję wymierną, jeśli stopień
wielomianu w liczniku jest mniejszy niż stopień wielomianu w
mianowniku.
:::

:::{prf:proposition}

Każda funkcja wymierna jest sumą wielomianu oraz funkcji
wymiernej właściwej.

Co więcej dla każdej funkcji wymiernej $f /  g$ istnieją
wielomiany $r, q$ takie, że

```{math}
\frac {f(x)} {g(x)} = \frac {r(x)} {g(x)} + q(x) \qquad \text{oraz} \qquad \deg r < \deg g.
```

:::

::::{exercise}
:label: lec-07-ex-08
:class: [exercise]

Znajdźmy rozkład funkcji $\displaystyle\frac{4x^3 + 5x^2 + 2x - 2}{x^2 + 1}$.


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

Wykonujemy dzielenie wielomianów:

$$
\begin{aligned}
4x^3 + 5x^2 + 2x - 2 & = \left(x^2 + 1\right)\left(4x + 5\right) - 2x - 7 \\
\underline{-4x^3 \phantom{{}+5x^2} - 4x \phantom{{}-2}} & \\
5x^2 - 2x - 2 & \\
\underline{-5x^2 \phantom{{}+2x} - 5} & \\
-2x - 7 &
\end{aligned}
$$

Stąd wniosek, że
$\quad \displaystyle\frac{4x^3 + 5x^2 + 2x - 2}{x^2 + 1} = \frac{-2x-7}{x^2+1} + 4x + 5.$
:::

### Rzeczywiste ułamki proste

:::{prf:theorem}

Każdy wielomian rzeczywisty dodatniego stopnia można
rozłożyć na iloczyn wielomianów pierwszego stopnia, $(x- a)$,
gdzie $a\in\rr$,
oraz nierozkładalnych wielomianów drugiego stopnia,
$(x^2+px+q)$,
gdzie $p,q\in\rr$, przy czym $\Delta=p^2-4q<0$.
:::

:::{narration}

**Rzeczywistym ułamkiem prostym pierwszego rodzaju** {index}`ułamek prosty; rzeczywsity`
nazywamy
rzeczywistą funkcję wymierną postaci

```{math}
\displaystyle \frac{A}{(x+a)^n},
```

gdzie $A,a\in\rr$ oraz $n\in\nn$.

**Rzeczywistym ułamkiem prostym drugiego rodzaju** {index}`ułamek prosty; rzeczywsity`
nazywamy
rzeczywistą funkcję wymierną postaci

```{math}
\displaystyle \frac{Ax+B}{(x^2+px+q)^n},
```

gdzie $A,B,p,q\in\rr$ oraz $n\in\nn$, przy czym $\Delta=p^2-4q<0$.
:::

### Całkowanie ułamków prostych pierwszego rodzaju

:::{narration}

Funkcję wymierną $\displaystyle\frac{A}{(x+a)^n}$ całkujemy
przez podstawienie $t = x+a$ (czyli $dt = dx$):

$$
\Int{ \frac{A}{(x+a)^n} }
=
   A\cdot \Int[t]{ \frac{1}{t^n} } =
   \begin{cases}
      A\cdot \ln|x+a| + C,                 & \text{dla } n = 1 \\
      \displaystyle\frac A {1-n}\cdot (x+a)^{1-n} + C, & \text{w p.p. }
   \end{cases}.
$$

:::

::::{exercise}
:label: lec-07-ex-09
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle\Int{ \frac {- 3} {2x-6} } $
2. $\displaystyle\Int{ \frac {e^\pi} {(3x-6)^5} } .$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \frac {- 3} {2x-6} }"
   r"& ="
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', 2*x-6, '\\tfrac 1 2 dt = dx')
part_3 = (
   r"= -3\cdot \Int[t]{\frac 1 t \cdot \frac 1 2 }"
   r"\\ &"
   r"= -\tfrac 3 2 \cdot \Int[t]{t^{-1} }"
   r"= -\tfrac 3 2  \ln|t| + C"
   r"= -\tfrac 3 2  \ln|2x-6| + C"
   r""
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_17', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{ \frac {e^\pi} {(3x-6)^5} }"
   r"& ="
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', 3*x-6, '\\tfrac 1 3 dt = dx')
part_3 = (
   r"= e^\pi\cdot \Int[t]{t^{-5} \cdot \frac 1 3 }"
   r"\\ &"
   r"= \frac {e^\pi} 3 \cdot \Int[t]{t^{-5} }"
   r"= \frac {e^\pi} 3 \cdot \frac {t^{-4}} {-4} + C"
   r"= - \frac {e^\pi} {12} \cdot \frac 1 {\Paren{3x-6}^4} + C"
   r"."
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_18', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Przy pomocy podstawienia doprowadzamy ułamek prosty do postaci kanonicznej:

   ```{glue:math} sageglue_integration_6_17
   ```

2. Podobnie:

   ```{glue:math} sageglue_integration_6_18
   ```

:::

### Całkowanie ułamków prostych drugiego rodzaju

:::{narration}

Całkowanie ułamków prostych drugiego rodzaju jest dość
skomplikowane, więc zaczynając od najprostszych przypadków,
dojdziemy do metody ogólnej.

Zacznijmy od funkcji wymiernej $\displaystyle\frac{1}{(x^2+1)^n}$.

Aby ją scałkować stosujemy wzór rekurencyjny.
:::

::::{exercise}
:label: lec-07-ex-10
:class: [exercise]

Pokażmy, że dla $n\in \nn_2$ zachodzi

$$
\Int{ \frac{1}{(x^2+1)^n} }
   = \frac 1 {2n - 2} \cdot \frac x {(x^2+1)^{n-1}}
   + \frac {2n - 3}{2n - 2} \cdot\Int{ \frac{1}{(x^2+1)^{n-1}} }.
$$


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

Przypomnijmy, że całka nieoznaczona jest rozdziną funkcji
różniących się o stałą addytywną, więc musimy pokazać prawa i lewa strona
różnią się o stałą.

W tym celu zróżniczkujmy różnicę lewej i prawej strony tej tożsamości:

$$
F(x)     & =
   \Int{ \frac{1}{(x^2+1)^n} }
   \\ & \quad - \Paren{
      \frac 1 {2n - 2} \cdot \frac x {(x^2+1)^{n-1}}
      + \frac {2n - 3}{2n - 2}\cdot \Int{ \frac{1}{(x^2+1)^{n-1}} }
   },
   \\
   \Diff{F}(x) & =
   \frac{1}{(x^2+1)^n}
   - \frac 1 {2n - 2} \cdot \Diff{}\Paren{\frac x {(x^2+1)^{n-1}}}
   \\ & \quad
   - \frac {2n - 3}{2n - 2}\cdot \frac{1}{(x^2+1)^{n-1}}
   \\ &
   =
   \frac {(2n - 2) - (2n-3)\Paren{x^2+1}}{(2n - 2)\cdot(x^2+1)^{n}}
   \\ & \quad
   - \frac 1 {2n - 2} \cdot \frac {(x^2+1)^{n-1} - (n-1)\cdot(x^2+1)^{n-2}\cdot 2x \cdot x}{(x^2+1)^{2n-2}}
   \\ &
   =
   \frac {(2n - 2) - (2n-3)\Paren{x^2+1}}{(2n - 2)\cdot(x^2+1)^{n}}
   \\ & \quad
   - \frac 1 {2n - 2} \cdot \frac {(x^2+1) - 2(n-1) x^2 }{(x^2+1)^{n}}
   \\ &
   =
   \frac {(2n - 2) - (2n-3+1)\Paren{x^2+1} +  (2n-2) x^2 }{(2n - 2)\cdot(x^2+1)^{n}}
   \\ &
   =
   \frac {(2n - 2)\Paren{ 1 - x^2 - 1 + x^2}}{(2n - 2)\cdot(x^2+1)^{n}}
   = 0
   .
$$

Ponieważ $F$ jest różniczkowalna dla $x\in \rr$,
to wnioskujemy, że $\Exists{C\in \rr}{F(x) = C}$ dla $x\in \rr$.

To oznacza, że prawa i lewa strona różnią się o stałą addytywną.
:::

::::{exercise}
:label: lec-07-ex-11
:class: [exercise]

Policzmy całkę nieoznaczoną
$\displaystyle\Int{\frac {4}{(x^2 + 1)^3} }  .$


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\frac {4}{(x^2 + 1)^3} }"
   r"    & ="
   r"   4\cdot \Paren{"
)
part_2 = IntegralIterationI(x, 3)
part_3 = (
   r"}"
   r"   \\ & = \frac {x}{\Paren{x^2+1}^2} + 3 \Int{\frac {1}{(x^2 + 1)^2} }"
   r"   \\ & = \frac {x}{\Paren{x^2+1}^2} + 3 \Paren{"
)
part_4 = IntegralIterationI(x, 2)
part_5 = (
   r"}"
   r"   \\ &"
   r"   = \frac {x}{\Paren{x^2+1}^2} + \frac 3 2 \cdot \Paren{ \frac {x}{x^2+1} + \arctg x } + C"
   r"   ."
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}
"""
glue('sageglue_integration_6_31', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Korzystając z powyższego wzoru otrzymujemy:

```{glue:math} sageglue_integration_6_31
```

:::

:::{narration}

W dalszej kolejności weźmy
funkcję wymierną $\displaystyle\frac{1}{(x^2+ px + q)^n}$,
dla której $\Delta=p^2-4q<0$.

Zapiszmy dwumian kwadratowy z mianownika w postaci kanonicznej:

$$
x^2+ px + q
   = \alpha \Paren{ \Paren{\beta x + \gamma}^2 + 1},
$$

dla pewnych stałych $\alpha, \beta, \gamma \in \rr.$

Stąd
skuteczne będzie podstawienie
$\displaystyle t = \beta x + \gamma,$
dla
$\displaystyle dt = \beta\ dx$
i~otrzymamy

$$
\Int{ \frac{1}{(x^2+ px + q)^n} }
   = \frac 1 {\alpha^n}
   \cdot \Int[t]{ \frac {1} {(t^2 + 1)^n}\cdot \frac 1 \beta }
   = \frac 1 {\alpha^n \cdot \beta}
   \cdot \Int[t]{ \frac {1} {(t^2 + 1)^n} }.
$$

Ostatnią całkę umiemy już policzyć!
:::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = r"\displaystyle\Int{\frac {4}{("
part_2 = latex(expand((2*x-4)^2 + 2))
part_3 = r")^2} } . "
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_6_1', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

::::{exercise}
:label: lec-07-ex-12
:class: [exercise]

Policzmy całkę nieoznaczoną {glue:}`sageglue_6_1`

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\frac {4}{("
   + latex(expand((2*x-4)^2 + 2))
   + r")^2} }"
   r"& ="
   r"\Int{\frac {4}{ 4\Paren{ \Paren{{\sqrt 2 x- 2\sqrt 2}}^2 + 1}^2} }"
   r"\\ & = "
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', sqrt(2)* x - 2*sqrt(2), r'dx = \frac 1 {\sqrt 2} \, dt')
part_3 = (
   r"\\ &"
   r"= \Int[t]{\frac {1}{\Paren{t^2 + 1}^2} \cdot \frac 1 {\sqrt 2} }"
   r"\\ & = \frac 1 {\sqrt 2} \cdot \Paren{"
)
part_4 = IntegralIterationI(t, 2)
part_5 = (
   r"}"
   r"\\ &"
   r"= \frac 1 {2\sqrt 2} \cdot \Paren{\frac t { t^2 + 1} + \arctg t } + C"
   r"\\ &"
   r"= \frac 1 {2\sqrt 2} \cdot \Paren{\frac {\sqrt 2 x- 2\sqrt 2} { \Paren{\sqrt 2 x- 2\sqrt 2}^2 + 1} + \arctg \Paren{\sqrt 2 x- 2\sqrt 2} } + C"
   r"\\ &"
   r"= \frac 1 {2\sqrt 2} \cdot \Paren{\frac {\sqrt 2 x- 2\sqrt 2} { 2x^2 - 8x + 9} + \arctg \Paren{\sqrt 2 x- 2\sqrt 2} } + C"
   r"."
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}
"""
glue('sageglue_6_23', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Na początku przekształćmy podstawę z mianownika:

$$
4x^2 - 16x + 18
    & = \Paren{4x^2 - 16x + 16} + 2
   = (2x-4)^2 + 2
   \\ &
   = 2\Paren{ \frac {(2x-4)^2} 2 + 1}
   = 2\Paren{ \Paren{\frac {2x-4} {\sqrt 2}}^2 + 1}
   = 2\Paren{ \Paren{{\sqrt 2 x- 2\sqrt 2}}^2 + 1}
   .
$$

To oznacza, że należy zastosować podstawienie $t = \sqrt 2 x- 2\sqrt 2$:

```{glue:math} sageglue_6_23
```

:::

:::{narration}

Z funkcją wymierną $\displaystyle\frac{2x + p}{(x^2+ px + q)^n}$
(dla której $\Delta=p^2-4q$ może być dowolna!),
poradzimy sobie bez problemu,
całkując przez podstawienie $t = x^2+ px + q$.

Istotnie, wynika z niego, że $dt = (2x + p) \ dx$, więc

$$
\Int{ \frac{2x + p}{(x^2+ px + q)^n} } =
   \Int[t]{ \frac{1}{t^n} },
$$

którą to całkę znów umiemy już policzyć.
:::

::::{exercise}
:label: lec-07-ex-13
:class: [exercise]

Policzmy całkę nieoznaczoną
$\displaystyle\Int{\frac {4x}{(x^2 + 3)^2} + \frac{2x+1} {x^2 + x +7} } . $


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math


part_1_a = (
    r"I_1 & = \Int{\frac {4x} {(x^2 + 3)^2}}"
    r"= 2 \cdot \Int{\frac {2x} {(x^2 + 3)^2}}"
    r"\\ &"
    r"="
)
part_1_b = IntegrationBySubstitutionIPrepare(x, 't', x^2+3, r'dx = \frac{1}{2x} \, dt')
part_1_c = (
    r"\\ &"
    r"= 2 \cdot \Int[t]{\frac {1} {t^2}}"
    r"= - \frac 2 t + C"
    r"= - \frac 2 {x^2+3} + C"
)
content = rf"""
{part_1_a}{part_1_b}{part_1_c}
"""
glue('sageglue_integration_6_20', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)

part_2_a = (
    r"I_2 & = \Int{\frac {2x+1} {x^2 + x +7}}"
    r"\\ &"
    r"="
)
part_2_b = IntegrationBySubstitutionIPrepare(x, 't', x^2+x + 7, r'dx = \frac{1}{2x+1} \, dt')
part_2_c = (
    r"\\ &"
    r"= \Int[t]{\frac 1 {t}}"
    r"= \ln \Absolute{t} + C"
    r"= \ln \Absolute{x^2+x + 7} + C"
)
content = rf"""
{part_2_a}{part_2_b}{part_2_c}
"""
glue('sageglue_integration_6_21', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Policzmy oddzielnie całki każdego ze składników:

```{glue:math} sageglue_integration_6_20
```

```{glue:math} sageglue_integration_6_21
```

Stąd

$$
\Int{\frac {4x}{(x^2 + 3)^2} + \frac{2x+1} {x^2 + x +7} }
   = I_1 + I_2
   =  - \frac 2 {x^2+3} + \ln \Absolute{x^2+x + 7} + C .
$$

:::

:::{narration}

Jesteśmy gotowi by scałkować dowolny ułamek prosty drugiego rodzaju
$\displaystyle \frac{Ax+B}{(x^2+px+q)^n},$
dla którego $\Delta=p^2-4q<0$.

W tym celu wykorzystamy tożsamość

$$
\Int{\frac{Ax+B}{(x^2+px+q)^n}}
   = \alpha\cdot \Int{\frac{2x+p}{(x^2+px+q)^n}}
   + \beta\cdot \Int{\frac{1}{(x^2+px+q)^n}}
$$

dla pewnych stałych $\alpha, \beta \in \rr$.

Jak widać, z obiema całkami poradzimy sobie bez problemu.
:::

::::{exercise}
:label: lec-07-ex-14
:class: [exercise]

Policzmy całkę nieoznaczoną
$\displaystyle\Int{\frac {3x+2}{(x^2 + x +1)^2}} .$

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"I_1 = \Int{\frac {2x+1}{(x^2 + x +1)^2}}"
   r"& = "
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', x^2 + x + 1, '')
part_3 = (
   r"\\ & = \Int[t]{\frac 1 {t^2}}"
   r"= - \frac 1 t + C"
   r"= - \frac 1 {x^2 + x + 1} + C ,"
   r"\\"
   r"I_2 = \Int{\frac {1}{(x^2 + x +1)^2}}"
   r"& ="
   r"\WaveBrack{"
   r"x^2 + x + 1 & = \Paren{x+\frac 1 2 }^2 + \tfrac 3 4"
   r"\\ &"
   r"= \tfrac 3 4 \Paren{\tfrac 4 3 \Paren{x + \tfrac 1 2 }^2 + 1}"
   r"\\ &"
   r"= \tfrac 3 4 \Paren{\Paren{\tfrac 2 {\sqrt 3} x + \tfrac 1 {\sqrt 3} }^2 + 1}"
   r"}"
   r"\\ & "
   r"= \Int{\frac {1}{\Paren{\tfrac 3 4}^2 \Paren{\Paren{\tfrac {2} 3 \sqrt 3 x + \tfrac {1} 3 \sqrt 3 }^2 + 1}^2}}"
   r"\\ &"
   r"= "
)
part_4 = IntegrationBySubstitutionIPrepare(x, 't', 2/sqrt(3)*x + 1/sqrt(3), r'dx = \frac{\sqrt{3}} 2 \, dt')
part_5 = (
   r"\\ &"
   r"= \frac {16} 9 \Int[t]{\frac 1 {\Paren{t^2 + 1}^2} \cdot  \frac{\sqrt{3}} 2 }"
   r"\\ &"
   r"= \frac{8\sqrt 3 } 9 \Paren{\frac 1 2 \cdot \frac t {t^2 + 1} + \frac 1 2 \arctg t} + C"
   r"\\ &"
   r"= \frac{4\sqrt 3 } 9 \Paren{\frac {\tfrac {2} 3 \sqrt 3 x + \tfrac {1} 3 \sqrt 3}"
   r"{\Paren{\tfrac {2} 3 \sqrt 3 x + \tfrac {1} 3 \sqrt 3}^2 + 1} + \arctg \Paren{\tfrac {2} 3 \sqrt 3 x + \tfrac {1} 3 \sqrt 3}} + C"
   r"\\ &"
   r"= " + latex( (1/((x^2 + x +1)^2)).integrate(x) ) + r" + C."
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}
"""
glue('sageglue_integration_6_32', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\frac {3x+2}{(x^2 + x +1)^2}}"
   r"& = \tfrac 3 2 I_1 + \tfrac 1 2 I_2"
   r"\\ & = -\frac 3 2 \cdot \frac 1 {x^2 + x + 1}"
   r"+  "
)
part_2 = latex( (1/(2*(x^2 + x +1)^2)).integrate(x) )
part_3 = (
   r" + C."
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_33', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

Zaczynamy od rozkładu całki na dwa składniki:

$$
\Int{\frac {3x+2}{(x^2 + x +1)^2}}
   & =
   \Int{\frac {\frac 3 2 (2x+1) + \frac 1 2}{(x^2 + x +1)^2}}
   \\ & =
   \frac 3 2 \Int{\frac {2x+1}{(x^2 + x +1)^2}}
   + \frac 1 2 \Int{\frac {1}{(x^2 + x +1)^2}}
   .
$$

Liczymy dwie całki:

```{glue:math} sageglue_integration_6_32
```

Ostatecznie,

```{glue:math} sageglue_integration_6_33
```

:::

### Rozkład funkcji wymiernych na ułamki proste

:::{prf:theorem}

Rzeczywista funkcja wymierna właściwa

$$
\frac{P(x)}{a_n(x-x_1)^{k_1}\ldots  (x-x_m)^{k_m}
      (x^2+p_1x+q_1)^{l_1}\ldots  (x^2+p_s+q_s)^{l_s}}
$$

jest sumą $k_1+\ldots +k_m$ rzeczywistych ułamków prostych I rodzaju oraz $l_1+\ldots +l_s$
rzeczywistych ułamków prostych II rodzaju, przy czym czynnikowi $(x-x_i)^{k_i}$
odpowiada suma $k_i$ ułamków prostych I rodzaju postaci

```{math}
\frac{A_{i1}}{x-x_i}+\frac{A_{i2}}{(x-x_i)^2}+\ldots +\frac{A_{ik_i}}{(x-x_i)^{k_i}},
```

a czynnikowi $(x^2+p_jx+q_j)^{l_j}$ odpowiada suma $l_j$ ułamków prostych II rodzaju postaci

$$
\frac{B_{j1}x+C_{j1}}{x^2+p_jx+q_j}
   +\frac{B_{j2}x+C_{j2}}{(x^2+p_jx+q_j)^2}
   +\ldots
   \\ \quad
   +\frac{B_{jl_j}x+C_{jl_j}}{(x^2+p_jx+q_j)^{l_j}},
$$

gdzie stałe $A_\Box, B_\Box, C_\Box$ są liczbami rzeczywistymi.
:::

::::{exercise}
:label: lec-07-ex-15
:class: [exercise]

Znajdźmy rozkład na ułamki proste funkcji:

:::{container} columns-2-auto

1. $\displaystyle\frac{ x^2 + 2}{x^4 + x^2} $
2. $\displaystyle\frac {1+ x}{(x-1)^2(x^2 +1)} .$

:::


:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

1. Przedstawiamy funkcję wymierną jako sumę ułamków prostych:

   $$
   \frac{ x^2 + 2}{x^4 + x^2}
   & = \frac A x + \frac B {x^2} + \frac{Cx + D}{x^2 + 1} & & \Big|  \cdot x^2\Paren{x^2 + 1}
   \\
   x^2 + 2 & = Ax \Paren{x^2 + 1} + B \Paren{x^2 +1} + \Paren{Cx + D} x^2.
   $$

   Przyrównując czynnikimi przy jednomianach z obu stron otrzymujemy:

   $$
   \Uklad{
   A + C = 0 \\
   B + D = 1 \\
   A = 0     \\
   B = 2
   }
   \Leftrightarrow \quad
   \begin{cases}
   A = 0 \\
   B = 2 \\
   C = 0 \\
   D = -1
   \end{cases}
   \Quad{\imply}
   \frac{ x^2 + 2}{x^4 + x^2}
   = \frac 2 {x^2} + \frac{-1}{x^2 + 1} .
   $$

2. Pozostawiam jako ćwiczenie rozkład funkcji, którą będziemy chcieli całkować:

   $$
   \frac {1+ x}{(x-1)^2(x^2 +1)}
   & = \frac A {x-1} + \frac B {\Paren{x-1}^2} + \frac {Cx + D}{x^2 + 1}
   \\ & = -\frac 1 {2(x-1)} + \frac 1 {\Paren{x-1}^2} + \frac {x - 1}{2\Paren{x^2 + 1}}
   .
   $$

:::

### Całkowanie funkcji wymiernych

::::{narration}

Całkowanie funkcji wymiernej $\frac f g$ można podzielić na trzy części:

1. Rozkładamy $\frac f g$
   na sumę wielomianu $q$ i właściwej funkcji wymiernej $\frac r g$.
2. Rozkładamy właściwą funkcję wymierną $\frac r g$ na ułamki proste.
3. Całkujemy wielomian $q$ i każdy z ułamków prostych.

   Suma scałkowanych składników daje końcowy wynik.

::::

::::{exercise}
:label: lec-07-ex-16
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle\Int{\frac{ x^4 + 2x^2 + 2}{x^4 + x^2}}  $
2. $\displaystyle\Int{\frac {1+ x}{(x-1)^2(x^2 +1)}} . $

:::

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-02`, {numref}`prob-08-ex-06`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"I_1 = \Int{-\frac 1 {2(x-1)} + \frac 1 {\Paren{x-1}^2}}"
   r"& = "
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', x-1, '')
part_3 = (
   r"=  \Int[t]{-\frac 1 {2t} + \frac 1 {t^2}}"
   r"= -\tfrac 1 2 \ln|t| - \frac 1 t + C"
   r"\\ &"
   r"= -\tfrac 1 2 \ln|x-1| - \frac 1 {x-1} + C ,"
   r"\\"
   r"I_2 = \Int{\frac {x - 1}{2\Paren{x^2 + 1}}}"
   r"& = \frac 1 4 \cdot \Int{\frac {2x - 2}{x^2 + 1}}"
   r"= \frac 1 4 \cdot \Int{\frac {2x}{x^2 + 1}}"
   r"- \frac 1 2 \cdot \Int{\frac {1}{x^2 + 1}}"
   r"\\ &"
   r"= \frac 1 4 \cdot \Int{\frac {2x}{x^2 + 1}}"
   r"- \frac 1 2 \arctg x"
   r"= "
)
part_4 = IntegrationBySubstitutionIPrepare(x, 't', x^2+1, '')
part_5 = (
   r"\\ &"
   r"= \frac 1 4 \cdot \Int[t]{\frac {1}{t}}"
   r"- \tfrac 1 2 \arctg x"
   r"= \tfrac 1 4 \ln |t|"
   r"- \tfrac 1 2 \arctg x + C"
   r"\\ &"
   r"= \tfrac 1 4 \ln \Paren{x^2+1}"
   r"- \tfrac 1 2 \arctg x + C ."
)
content = rf"""
{part_1}{part_2}{part_3}{part_4}{part_5}
"""
glue('sageglue_integration_6_24', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Przedstawiamy funkcję jako sumę wielomianu i funkcji wymiernej właściwej, którą rozkładamy na ułamki proste:

   $$
   \Int{\frac{ x^4 + 2x^2 + 2}{x^4 + x^2}}
   & =
   \Int{\frac{ \Paren{x^4 + x^2} + x^2 + 2}{x^4 + x^2}}
   =
   \Int{1 + \frac{x^2 + 2}{x^4 + x^2}}
   \\ &
   =
   \Int{1}
   + \Int{\frac 2 {x^2}}
   - \Int{\frac{1}{x^2 + 1}}
   = x - \frac 2 x  - \arctg x + C .
   $$

2. Rozkładamy całkę na trzy składniki odpowiadające ułamkom prostym:

   $$
   \Int{\frac {1+ x}{(x-1)^2(x^2 +1)}}
   =
   \Int{- \frac 1 {2(x-1)}
   + \frac 1 {\Paren{x-1}^2}}
   + \Int{\frac {x - 1}{2\Paren{x^2 + 1}}}
   .
   $$

   Liczymy:

   ```{glue:math} sageglue_integration_6_24
   ```

   Po zsumowaniu otrzymamy

   $$
   \Int{\frac {1+ x}{(x-1)^2(x^2 +1)}}
   = I_1 + I_2
   = -\tfrac 1 2 \ln|x-1| - \frac 1 {x-1} + \tfrac 1 4 \ln \Paren{x^2+1}
   - \tfrac 1 2 \arctg x + C
   .
   $$

:::

## Całkowanie funkcji trygonometrycznych

:::{narration}

Jeśli funkcja podcałkowa jest iloczynem dowolnej liczby funkcji
$\sin a x$, $\cos b x$, to stosujemy wzory trygonometryczne:

$$
\sin \alpha  \cdot \sin \beta
    & = \frac 1 2 \left( \cos (\alpha - \beta)  - \cos (\alpha + \beta)   \right) ,
    & \sin^2 \alpha
    & = \frac{1- \cos 2\alpha} 2 ,
   \\
   \sin \alpha  \cdot \cos \beta
    & = \frac 1 2 \left( \sin (\alpha - \beta)  + \sin (\alpha + \beta)    \right) ,
    & \cos^2 \alpha
    & = \frac{1+ \cos 2\alpha} 2 ,
   \\
   \cos \alpha  \cdot \cos \beta
    & = \frac 1 2 \left( \cos (\alpha - \beta)  + \cos (\alpha + \beta)    \right) ,
    &\quad \sin \alpha \cos \alpha
    & = \frac{\sin 2\alpha} 2 .
$$

:::

::::{exercise}
:label: lec-07-ex-17
:class: [exercise]

Policzmy całki nieoznaczone:

:::{container} columns-2-auto

1. $\displaystyle \Int{\sin a x} $ dla $a\neq 0$
2. $\displaystyle \Int{\cos a x}$ dla $a\neq 0$
3. $\displaystyle \Int{\sin 3x \cdot \cos 5x } $
4. $\displaystyle \Int{\cos^4 x } .$
<!-- 5. $\displaystyle\Int{\sin^4 x \cdot \cos^2 x} .$ -->

:::

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-01`, {numref}`prob-08-ex-05`.
:::

::::

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\sin a x}"
   r"& = "
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', a*x, '')
part_3 = (
   r"= \Int[t]{\sin t \cdot \frac 1 a}"
   r"= -\frac 1 a \cos t + C"
   r"= -\frac 1 a \cos a x + C "
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_26', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

```{code-cell} sage
:tags: [remove-cell]
from myst_nb import glue
from IPython.display import Math

part_1 = (
   r"\Int{\cos a x}"
   r"& = "
)
part_2 = IntegrationBySubstitutionIPrepare(x, 't', a*x, '')
part_3 = (
   r"= \Int[t]{\cos t \cdot \frac 1 a}"
   r"= \frac 1 a \sin t + C"
   r"= \frac 1 a \sin a x + C "
)
content = rf"""
{part_1}{part_2}{part_3}
"""
glue('sageglue_integration_6_27', Math(r"\begin{aligned}" + content + r"\end{aligned}"), display=False)
```

:::{solution-without-reference}
:class: [solution] dropdown

1. Całka, którą warto zapamiętać:

   ```{glue:math} sageglue_integration_6_26
   ```

2. Analogicznie:

   ```{glue:math} sageglue_integration_6_27
   ```

3. Prosty przykład:

   $$
   \Int{\sin 3x \cdot \cos 5x }
   & =
   \Int{\frac 1 2 \Paren{\sin \Paren{-2x} + \sin 8x }}
   \\ &
   = \frac 1 2 \Paren{\frac 1 2 \cos 2x - \frac 1 8 \cos 8x } + C
   \\ &
   = {\tfrac 1 4 \cos 2x - \tfrac 1 {16} \cos 8x } + C

   $$

4. Niekiedy trzeba metodę zastosować kilkukrotnie:

   $$
   \Int{\cos^4 x }
   & = \Int{\Paren{\frac{1+\cos 2x} 2}^2}
   = \frac 1 4 \cdot \Int{1+2\cos 2x + \cos^2 2x}
   \\ &
   = \frac 1 4 x + \frac 1 4\sin 2x + \frac 1 4 \cdot \Int{\frac 1 2 \Paren{1 + \cos 4x} }
   \\ &
   = \frac 1 4 x + \frac 1 4\sin 2x + \frac 1 8 \Paren{x + \frac 1 4 \sin 4x} + C
   \\ &
   = \tfrac 3 8 x + \tfrac 1 4\sin 2x + \tfrac 1 {32} \sin 4x + C
   .
   $$

<!-- 5. Metodę można iterować do skutku:

   $$
   \Int{\sin^4 x \cdot \cos^2 x}
   & =
   \Int{\frac 1 4 \Paren{1- \cos 2x}^2 \cdot \frac 1 2 \Paren{1+ \cos 2x}}
   = \frac 1 8 \cdot \Int{ \Paren{1- \cos^2 2x} \cdot \Paren{1- \cos 2x}}
   \\ &
   = \frac 1 8 \cdot \Int{ 1- \cos 2x -  \cos^2 2x \Paren{1-\cos 2x}}
   \\ &
   = \frac 1 8 \Paren{x - \frac 1 {2} \sin 2x
   - \Int{\frac 1 2\Paren{1 - \cos 4x}\Paren{1- \cos 2x} } }
   \\ &
   = \frac 1 8 \Paren{x - \frac 1 {2} \sin 2x
   - \frac 1 2 \cdot\Int{1- \cos 2x - \cos 4x + \cos 4x \cos 2x} }
   \\ &
   = \frac 1 8 \Paren{x - \frac 1 {2} \sin 2x
   - \frac 1 2 \Paren{x - \frac 1 2 \sin 2x - \frac 1 4 \sin 4x
   + \Int{ \frac 1 2 \Paren{\cos 2x + \cos 6x } } } }
   \\ &
   = \frac 1 8 \Paren{x - \frac 1 {2} \sin 2x
   - \frac 1 2 \Paren{x - \frac 1 2 \sin 2x - \frac 1 4 \sin 4x
   + { \frac 1 2 \Paren{\frac 1 2 \sin 2x + \frac 1 6 \sin 6x } } } } + C .
   $$ -->

:::

:::{narration}

Jeśli funkcja podcałkowa jest postaci $R(\sin x, \cos x)$,
gdzie $R$ jest funkcją wymierną, to można zastosować podstawienie uniwersalne
$t = \tg \frac x 2$, by otrzymać całkę z funkcji wymiernej:

$$
\Int{R(\sin x, \cos x)}  =
   \WaveBrack{
   \displaystyle t   & = \tg \tfrac x 2
               & \displaystyle x   & = 2 \arctg t
      \\
               &             & \displaystyle dx    & = \frac {2} {1 + t^2} \ dt
      \\
   \displaystyle \sin x & = \frac {2t}{1+t^2}
               & \displaystyle \cos x & = \frac {1-t^2}{1+t^2}
   }
   = \Int[t]{R\left(\frac {2t}{1+t^2},\frac {1-t^2}{1+t^2}\right) \frac {2} {1 + t^2} } .
$$

:::

::::{exercise}
:label: lec-07-ex-18
:class: [exercise]

Policzmy całkę nieoznaczoną
$\displaystyle\Int{\frac {1} {\cos x}} .$

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-03`, {numref}`prob-08-ex-07`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

Stosujemy podstawienie uniwersalne:

$$
\Int{\frac {1} {\cos x}}
               & =
   \WaveBrack{
   \displaystyle t   & = \tg \tfrac x 2
               & \displaystyle x   & = 2 \arctg t
      \\
               &             & \displaystyle dx    & = \frac {2} {1 + t^2} \ dt
      \\
   \displaystyle \sin x & = \frac {2t}{1+t^2}
               & \displaystyle \cos x & = \frac {1-t^2}{1+t^2}
   }
   = \Int[t]{\frac {\cancel{1 + t^2}} { 1-t^2} \cdot \frac 2 {\cancel{1+t^2}}}
   \\ &
   = \Int[t]{\frac 2 {(1 + t)(1 - t)}}
   = \Int[t]{\frac 1 {t + 1} - \frac 1 {t - 1}}
   = \ln\Absolute{t+1} - \ln\Absolute{t-1} + C
   \\ &
   = \ln\Absolute{\frac {t+1} {t-1}}  + C
   = \ln\Absolute{\frac {\tg \frac x 2+1} {\tg \frac x 2-1}}  + C
   = \ln\Absolute{\frac {\sin \frac x 2+\cos \frac x 2} {\sin \frac x 2-\cos \frac x 2}}  + C .
$$

:::

:::{narration}

Jeśli funkcja podcałkowa jest postaci $R(\tg x)$,
gdzie $R$ jest funkcją wymierną, to można również zastosować podstawienie
$t = \tg x$, by otrzymać całkę z funkcji wymiernej:

$$
\Int{R(\tg x)}  =
   \WaveBrack{
   \displaystyle t  & = \tg x          \\
   \displaystyle x  & = \arctg t         \\
   \displaystyle dx & = \frac {1} {1 + t^2}\ dt
   }
   =\Int[t]{\frac{R(t)} {1 + t^2} } .
$$

:::

::::{exercise}
:label: lec-07-ex-19
:class: [exercise]

Policzmy całkę nieoznaczoną
$\displaystyle\Int{\tg^4 x} . $

:::{note}
:class: [see-problem]

Pomoże rozwiązać {numref}`prob-08-ex-04`.
:::

::::

:::{solution-without-reference}
:class: [solution] dropdown

$$
\Int{\tg^4 x}
              & =
   \WaveBrack{
   \displaystyle t  & = \tg x          \\
   \displaystyle x  & = \arctg t         \\
   \displaystyle dx & = \frac {1} {1 + t^2}\ dt
   }
   =\Int[t]{\frac {t^4} {1 + t^2} }
   =\Int[t]{\frac {t^4 + t^2} {t^2 + 1} + \frac {-t^2 - 1} {t^2 + 1} + \frac {1} {1 + t^2} }
   \\ &
   =\Int[t]{t^2 - 1 + \frac {1} {t^2 + 1} }
=\tfrac 1 3 t^3 - t + \arctg t  + C
   =\tfrac 1 3 \tg ^3 x - \tg x  + x  + C .
$$

:::
