\documentclass{article}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../homework-problems-UMB.tex
\addtolength{\hoffset}{-3.5cm}
\addtolength{\textwidth}{6.8cm}
\addtolength{\voffset}{-3cm}
\addtolength{\textheight}{6cm}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../homework-problems.tex
\usepackage{amsmath, amsfonts, amssymb, verbatim, hyperref, ifthen}
\usepackage{amsthm}
\usepackage{multicol}
\usepackage{longtable}
\usepackage{etoolbox}
\usepackage{comment}
\usepackage{cleveref}
\usepackage{enumitem}
%\usepackage{fourier}

\crefformat{footnote}{#2\footnotemark[#1]#3}

\newtoggle{solutions}
\newtoggle{solutionsExtra}
\newtoggle{answers}

%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../lectures/example-templates.tex
\usepackage{ifthen}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{cancel}
\usepackage{comment}
\usepackage{multirow}
\usepackage{psfrag}
\usepackage{rotating}
\usepackage{fp}
\usepackage{calc}
\usepackage{bm}
\usepackage[all,cmtip]{xy}
\RequirePackage{xstring}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% List of commands in this document
%
%
% \logdiffbaseandexp
% \logdifftwouponedown
% \productrulefofx
% \quotientruley
% \limitradical  (broken)
% \limitsub
% \chainruley
% \chainrulefofx
% \chainruleStyleOne
% \chainruleStyleTwo
% \chainruleStyleThree
% \infinitelimit
% \limitfactor
% \newtonsmethod
% \constantmultiple
% \chainruletwice
% \youWillNotBeTested
% \optionalDisplay  %Dummy command needed for compatibility with Calculus notes.
% \Arcsin
% \Arccos
% \Arctan
% \Arccot
% \diff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\diff}{{\normalfont \text{d}}}
\newtheorem{question}{Question}
\newtheorem{observation}{Observation}
\newtheorem{proposition}{Proposition}
\newtheorem{remark}{Remark}
\newcommand{\youWillNotBeTested}{\begin{frame}You will not be tested on the material in the following slide.\end{frame}}
\DeclareMathOperator{\Vol}{Vol}

\DeclareMathOperator{\Arcsin}{\sin^{-1}}
\DeclareMathOperator{\Arccos}{\cos^{-1}}
\DeclareMathOperator{\Arctan}{\tan^{-1}}
\DeclareMathOperator{\Arccot}{{\cot^{-1}}}
\DeclareMathOperator{\Arcsec}{{\sec^{-1}}}
\DeclareMathOperator{\Arccsc}{{\csc^{-1}}}
\DeclareMathOperator{\maclaurin}{{\normalfont{Mc}}}
\newcommand{\taylor}{{\normalfont{T}}}

\newcommand{\optionalDisplay}[1]{#1}
\renewcommand{\Im}{\mathrm{Im}}
\renewcommand{\Re}{\mathrm{Re}}

%\DeclareMathOperator{\Re}{Re}
%\DeclareMathOperator{\Im}{Im}
\newcommand{\fcv}[1]{{\bf #1}} %this command stands for freecalc Vector
\DeclareMathOperator{\curl}{\fcv{curl}}
\DeclareMathOperator{\divg}{div}
\DeclareMathOperator{\proj}{\fcv{proj}}
\DeclareMathOperator{\orth}{\fcv{orth}}
\DeclareMathOperator{\grad}{\fcv{grad}}
\newcommand{\RR}{{\mathbb{R}}}
\newcommand{\cR}{{\mathcal{R}}}
\newcommand{\cD}{{\mathcal{D}}}
\newcommand{\cP}{{\mathcal{P}}}
\newcommand{\fcUncoverAlert}[2]{\uncover<#1->{\alert<#1>{#2}}}
\newcommand{\fcAnswer}[2]{
\FPeval{\fcResult}{clip(#1-1)}
\uncover<handout:0|\fcResult>{\alert<handout:0|\fcResult>{\textbf{?} }} \uncover<#1->{\alert<handout:0|#1>{\!\!\!#2}}
}
\newcommand{\fcAnswerUncover}[3]{
\FPeval{\fcResult}{clip(#2-1)}
\uncover<handout:0|#1-\fcResult>{\alert<handout:0|\fcResult>{\textbf{?}}} \uncover<#2->{\alert<handout:0|#2>{\!\!\!#3}}
}

\newcommand{\fcQuestion}[2]{%
\FPeval{\fcResult}{clip(#1+1)}%
\uncover<#1->{\alert<handout:0| #1,\fcResult>{#2}}%
}
\newcommand{\fcEvalToInt}[1]{\FPeval{\fcResult}{clip(#1)}\fcResult}
\newcommand{\refBad}[3]{%
\ifthenelse{\equal{#1}{??}}%
{#2}%
{#3}%
}%example usage: \refBad{\ref{eqMacLaurinDef}}{their definition}{their definition (Definition \ref{eqMacLaurinDef})}
\newcommand{\alertNoH}[2]{\alert<handout:0|#1>{#2}}
%code blocks regular expression that replaces all strings of the form \alert<a> where a does not contain the | character by \alertNoH{a}:
%Find:
%\\alert<\([^>^|]*\)>
%Replace:
%\\alertNoH{\1}


\newcommand{\onlyNoH}[2]{\only<handout:0|#1>{#2}}
%
%  An example of logarithmic differentiation of a function with a
%  variable base and exponent.
%  #1 is the base.
%  #2 is the exponent.
%  #3 is the derivative of the natural logarithm of the base.
%  #4 is the derivative of the exponent.
%  #5 is (base)(exponent)' + (exponent)(base)' after simplification.
%
\newcommand{\logdiffbaseandexp}[5]{
\begin{example}[Variable base and exponent]
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad \alert<handout:0| 13>{y} %
 & \alert<handout:0| 13>{=} %
\alert<handout:0| 13>{%
#1^{#2}%
}.%
\uncover<2->{%
\intertext{
Take logarithms of both sides:%
}
}%
\uncover<2->{%
\ln y
}%
 & \uncover<2->{ = } %
\uncover<2->{%
\ln #1^{\alert<handout:0| 3>{#2}}%
}\\%
\uncover<3->{%
\alert<handout:0| 4-5>{\ln y}%
}%
 & \uncover<3->{ = } %
\uncover<3->{%
\alert<handout:0| 6-7>{%
\alert<handout:0| 3>{#2} \ln #1%
}.}%
\uncover<4->{%
\intertext{
Differentiate implicitly with respect to $x$:%
}%
}%
\uncover<5->{%
\alert<handout:0| 5>{\frac{1}{y} y'}%
}%
 & \uncover<4->{ = } %
\uncover<7->{%
\alert<handout:0| 7>{%
\left( #2 \right) \alert<handout:0| 8-9>{\frac{\diff}{\diff x} \left( \ln #1 \right)} + \left( \ln #1 \right)\alert<handout:0| 10-11>{\frac{\diff}{\diff x}\left( #2 \right)} %
}%
}\\%
\uncover<8->{%
\frac{1}{\alert<handout:0| 12>{y}} y'%
}%
 & \uncover<8->{ = } %
\uncover<8->{%
( #2 ) \alert<handout:0| 8-9>{\left( \uncover<9->{ #3 }\right)} + \left( \ln #1 \right) \alert<handout:0| 10-11>{ \left( \uncover<11->{ #4 } \right) }
}\\%
\uncover<12->{%
y'%
}%
 & \uncover<12->{ = } %
\uncover<12->{%
\alert<handout:0| 12-13>{y} \left( #5 \right)%
}\\%
 & \uncover<13->{ = } %
\uncover<13->{%
\alert<handout:0| 13>{#1^{#2}} \left( #5 \right).%
}%
\end{align*}
\end{example}
}


%
%  An example of logarithmic differentiation of a function.
%  It looks as follows:
%
%  Differentiate y = (#1 #2)/#3.
%  Take logarithms of both sides:
%  ln y = ln((#1 #2)/#3)
%  ln y = ln#1 + ln#2 - ln#3
%  ln y = #4 + #5 - #6
%  Differentiate implicitly with respect to x:
%  (1/y)y' = #7 + #8 - #9
%  y' = y(#7 + #8 - #9)
%  y' = ((#1 #2)/#3)(#7 + #8 - #9)
%
\newcommand{\logdifftwouponedown}[9]{
\begin{example}[Logarithmic Differentiation%
]
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad \alert<handout:0| 18>{y} %
 & \alert<handout:0| 18>{=} %
\alert<handout:0| 18>{%
\frac{#1 #2}{#3}%
}.%
\uncover<2->{%
\intertext{
Take logarithms of both sides:%
}
}%
\uncover<2->{%
\ln y
}%
 & \uncover<2->{ = } %
\uncover<2->{%
\ln \frac{\alert<handout:0| 3-4>{#1}\alert<handout:0| 5-6>{#2}}{\alert<handout:0| 7-8>{#3}}%
}\\%
\uncover<2->{%
\ln y
}%
 & \uncover<2->{ = } %
\uncover<2->{%
\ln \alert<handout:0| 3-4>{#1} + \ln \alert<handout:0| 5-6>{#2} -  \ln \alert<handout:0| 7-8>{#3}%
}\\%
\uncover<3->{%
\alert<handout:0| 9-10>{\ln y}%
}%
 & \uncover<3->{ = } %
\uncover<3->{%
\alert<handout:0| 3-4,11-12>{%
\left( \uncover<4->{#4}\right) %
}%
\alert<handout:0| 5-6>{%
\uncover<6->{+} \alert<handout:0| 13-14>{\left( \uncover<6->{#5}\right)} %
}%
\alert<handout:0| 7-8>{%
\uncover<8->{-} \alert<handout:0| 15-16>{\left( \uncover<8->{#6}\right)} %
}%
}%
\uncover<9->{%
\intertext{
Differentiate implicitly with respect to $x$:%
}%
}%
\uncover<10->{%
\alert<handout:0| 10>{\frac{1}{\alert<handout:0| 17>{y}} y'}%
}%
 & \uncover<9->{ = } %
\uncover<9->{%
\alert<handout:0| 11-12>{\left( \uncover<12->{#7} \right)} + %
\alert<handout:0| 13-14>{\left( \uncover<14->{#8} \right)} - %
\alert<handout:0| 15-16>{\left( \uncover<16->{#9} \right)} %
}\\%
\uncover<17->{%
y'%
}%
 & \uncover<17->{ = } %
\uncover<17->{%
\alert<handout:0| 17-18>{y} \left( #7 + #8 - #9 \right)%
}\\%
 & \uncover<18->{ = } %
\uncover<18->{%
\alert<handout:0| 18>{\frac{#1 #2}{#3}} \left( #7 + #8 - #9 \right)%
}%
\end{align*}
\end{example}
}


%
%  An example of a derivative with the Product Rule, using the symbol f(x).
%  It looks as follows:
%
%  Differentiate f(x) = #1 #2.
%  Product Rule: f'(x) = (#1)(d/dx)(#2) + (#2)(d/dx)(#1)
%   = (#1)(#4) + (#2)(#3)
%   = #5.
%
%  #6 appears in the subtitle of the example.
%
\newcommand{\productrulefofx}[6]{%
\begin{example}[Product Rule%
\ifthenelse{\equal{#6}{0}}%
{}%
{, #6}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad f(x) & = #1 #2.\\%
\uncover<2->{%
\text{Product Rule:}\quad f'(x)%
}%
& \uncover<2->{%
 = \left( #1 \right) \alert<handout:0| 3-4>{\frac{\diff}{\diff x}\left( #2 \right)} + \left( #2 \right) \alert<handout:0| 5-6>{\frac{\diff}{\diff x}\left( #1 \right)}%
}\\%
& \uncover<3->{%
 = \left( #1 \right) \alert<handout:0| 3-4>{\left(\uncover<4->{ #4 }\right)} + \left( #2 \right) \alert<handout:0| 5-6>{\left( \uncover<6->{#3} \right)}%
}\\%
& \uncover<7->{%
 = #5.%
}%
\end{align*}
\end{example}
}


%
%  An example of a derivative with the Constant Multiple Rule.
%  It looks as follows:
%
%  Find the derivative of #1 = #2.
%   #1 = (#3)(#4).
%   d#1/dx = (d/dx)((#3)(#4))
% Constant Multiple Rule: = (#3)(d/dx)(#4)
%   = (#3)(#5)
%   = #6.
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\constantmultiple}[7]{%
\begin{example}[Constant Multiple Rule%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find the derivative of}\quad #1 & = #2.\\%
\uncover<2->{%
#1 %
}%
& \uncover<2->{%
 = \left( #3\right)\left( #4\right).
}\\%
\uncover<3->{%
\frac{\diff #1}{\diff x} %
}%
& \uncover<3->{%
 = \frac{\diff}{\diff x}\left[ \alert<handout:0| 4>{\left( #3\right)}\left( #4\right)\right]
}\\%
\uncover<4->{%
\text{Constant Multiple Rule:}\quad %
}%
& \uncover<4->{%
 =  \alert<handout:0| 4>{\left( #3\right)}\alert<handout:0| 5-6>{\frac{\diff}{\diff x}\left( #4\right)}
}\\%
& \uncover<5->{%
 =  \left( #3\right)\alert<handout:0| 5-6>{\left( \uncover<6->{#5}\right)}
}\\%
& \uncover<7->{%
 =  #6.
}%
\end{align*}
\end{example}
}


%
%  An example of a derivative with the Quotient Rule, using the symbol y.
%  It looks as follows:
%
%  Differentiate y = #1 / #2.
%  Quotient Rule: dy/dx = ((#2)(d/dx)(#1)-(#1)(d/dx)(#2))/(#2)^2
%   = ((#2)(#3)-(#1)(#4))/(#2)^2
%   = #5
%   = #6.
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\quotientruley}[7]{%
\begin{example}[Quotient Rule%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad y & = \frac{#1}{#2}.%
\uncover<2->{%
\intertext{Quotient Rule:}%
}%
%&\\%
\uncover<2->{%
\frac{\diff y}{\diff x}%
}%
& \uncover<2->{%
 = \frac%
{\left( #2 \right) \alert<handout:0| 3-4>{\frac{\diff}{\diff x}\left( #1 \right)} - \left( #1 \right) \alert<handout:0| 5-6>{\frac{\diff}{\diff x}\left( #2 \right)}}%
{\left( #2\right)^2}%
}\\%
& \uncover<3->{%
 = \frac%
{\left( #2 \right) \alert<handout:0| 3-4>{\left(\uncover<4->{ #3 }\right)} - \left( #1 \right) \alert<handout:0| 5-6>{\left( \uncover<6->{#4} \right)}}%
{\left( #2\right)^2}%
}\\%
& \uncover<7->{%
 = #5%
}\\%
& \uncover<8->{%
 = #6.%
}%
\end{align*}
\end{example}
}

%
%  An example of an indefinite integral with the Substitution Rule.
%  It looks as follows:
%
%  Find \int (#1, with nothing substituted for UU and VV).
%  Let u = #2
%  Then du = #3.
%  Therefore #4 = #5.
%  Substitute: \int (#1, with the alert command for u and du
%          substituted for UU and VV respectively)
%  = \int (#6, with the alert command for u and du substituted for UU and VV)
%  = (#7, with u substituted for UU) + C
%  = (#8, with #2 substituted for UU) + C
%
%  #9 appears in the subtitle of the example.
%
\newcommand{\subrule}[9]{%
\begin{example}[Substitution Rule%
\ifthenelse{\equal{#9}{0}}%
{}%
{, #9}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \int %
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{3}}{VV}{6-7}\noexploregroups\expandarg. & \\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 2-3,8,13>{u}%
}%
& \uncover<2->{%
\alert<handout:0| 2-3,8,13>{ = \uncover<3->{#2.}}%
}\\%
\uncover<4->{%
\text{Then}\quad \alert<handout:0| 4-5>{\diff u}%
}%
& \uncover<4->{%
\alert<handout:0| 4-5>{ = \uncover<5->{#3}}%
}\\%
\uncover<6->{%
\alert<handout:0| 6-7,9>{#4}%
}%
& \uncover<6->{%
\alert<handout:0| 6-7,9>{ = \uncover<7->{#5.}}%
}\\%
\uncover<8->{%
\text{Substitute:}\quad \int%
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{8}}{VV}{9}\noexploregroups\expandarg}%
& \uncover<8->{= \alert<handout:0| 10-11>{\int\noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#6}{UU}{8}}{VV}{9}\noexploregroups\expandarg %
}}\\%
& \uncover<10->{\alert<handout:0| 10-11>{%
 = \uncover<11->{\noexpandarg\exploregroups \StrSubstitute{#7}{UU}{\alert<handout:0| 13>{u}}\noexploregroups\expandarg} \uncover<12->{\alert<handout:0| 12>{+C}}%
}}\\%
& \uncover<13->{%
 = \noexpandarg\exploregroups \StrSubstitute{#8}{UU}{\alert<handout:0| 13>{#2}}\noexploregroups\expandarg +C.%
}%
\end{align*}
\end{example}
}

%
%  An example of a definite integral with the Substitution Rule.
%  There are nine arguments to the function.  The ninth is a string of four
%  groups of the form {AA}{BB}{CC}{DD} where AA is the lower limit of
%  integration, BB is the upper limit of integration, CC is the lower limit
%  of integration with respect to u, and DD is the upper limit of integration
%  with respect to u.
%  It looks as follows:
%
%  Find \int_{AA}^{BB} (#1, with nothing substituted for UU and VV).
%  Let u = #2
%  Then du = #3.
%  #4 = #5.
%  When x = AA, u = CC.
%  When x = BB, u = DD.
%  Substitute: \int_{AA}^{BB} (#1, with the alert command for u and du
%          substituted for UU and VV respectively)
%  = \int_{CC}^{DD} (#6, with the alert command for u and du substituted for UU and VV)
%  = [#7, with u substituted for UU]_{CC}^{DD}
%  = #8.
%
%
\newcommand{\subruledefbounds}[9]{%
\begin{example}[Substitution Rule, Definite Integral%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \int%
_{\StrMid{#9}{1}{1}}%
^{\StrMid{#9}{2}{2}} %
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{3}}{VV}{6-7}\noexploregroups\expandarg. & \\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 2-3,8-12>{u}%
}%
& \uncover<2->{%
\alert<handout:0| 2-3,8-12>{ = \uncover<3->{#2.}}%
}\\%
\uncover<4->{%
\text{Then}\quad \alert<handout:0| 4-5>{\diff u}%
}%
& \uncover<4->{%
\alert<handout:0| 4-5>{ = \uncover<5->{#3}}%
}\\%
\uncover<6->{%
\alert<handout:0| 6-7,13>{#4}%
}%
& \uncover<6->{%
\alert<handout:0| 6-7,13>{ = \uncover<7->{#5.}}%
}\\%
\uncover<8->{%
\alert<handout:0| 8-9,14>{\text{When } x = \StrMid{#9}{1}{1}, \quad u }%
}%
& \uncover<8->{%
\alert<handout:0| 8-9,14>{ = \uncover<9->{\StrMid{#9}{3}{3}.}}%
}\\%
\uncover<10->{%
\alert<handout:0| 10-11,15>{\text{When } x = \StrMid{#9}{2}{2}, \quad u }%
}%
& \uncover<10->{%
\alert<handout:0| 10-11,15>{ = \uncover<11->{\StrMid{#9}{4}{4}.}}%
}\\%
\uncover<12->{%
\text{Substitute:}\quad \int%
_{\alert<handout:0| 14>{\StrMid{#9}{1}{1}}}%
^{\alert<handout:0| 15>{\StrMid{#9}{2}{2}}} %
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{12}}{VV}{13}\noexploregroups\expandarg}%
& \uncover<12->{= \alert<handout:0| 16-17>{{\int}%
_{\uncover<14->{\alert<handout:0| 14>{
\StrMid{#9}{3}{3}}}}%
^{\uncover<15->{
\alert<handout:0| 15>{
\StrMid{#9}{4}{4}}}} %
\noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#6}{UU}{12}}{VV}{13}\noexploregroups\expandarg %
}}\\%
& \uncover<16->{\alert<handout:0| 16-17>{%
 = {\left[ \uncover<17->{%
\noexpandarg\exploregroups\StrSubstitute{#7}{UU}{u}\noexploregroups\expandarg %
}\right]}_{\StrMid{#9}{3}{3}}^{\StrMid{#9}{4}{4}}%
}}\\%
& \uncover<18->{%
 = #8.
}%
\end{align*}
\end{example}
}


%
%  An example of a definite integral with the Substitution Rule.
%  There are nine arguments to the function.  The ninth is a string of two
%  groups of the form {AA}{BB} where AA is the lower limit of
%  integration and BB is the upper limit of integration.
%  It looks as follows:
%
%  Find \int_{AA}^{BB} (#1, with nothing substituted for UU and VV).
%  Let u = #2
%  Then du = #3.
%  #4 = #5.
%  Substitute: \int (#1, with the alert command for u and du
%          substituted for UU and VV respectively)
%  = \int (#6, with the alert command for u and du substituted for UU and VV)
%  = #7, with u substituted for UU
%  = #8.
%  Therefore int_{AA}^{BB} (#1, with nothing substituted for UU and VV)
%      = [#8]_{AA}^{BB}
%  = #9.
%
%
\newcommand{\subruledefvar}[9]{%
\begin{example}[Substitution Rule, Definite Integral%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \int%
_{\StrMid{#9}{1}{1}}%
^{\StrMid{#9}{2}{2}} %
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{3}}{VV}{6-7}\noexploregroups\expandarg. & \\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 2-3,8,12>{u}%
}%
& \uncover<2->{%
\alert<handout:0| 2-3,8,12>{ = \uncover<3->{#2.}}%
}\\%
\uncover<4->{%
\text{Then}\quad \alert<handout:0| 4-5>{\diff u}%
}%
& \uncover<4->{%
\alert<handout:0| 4-5>{ = \uncover<5->{#3}}%
}\\%
\uncover<6->{%
\alert<handout:0| 6-7,9>{#4}%
}%
& \uncover<6->{%
\alert<handout:0| 6-7,9>{ = \uncover<7->{#5.}}%
}\\%
\uncover<8->{%
\text{Substitute:}\quad \int%
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{8}}{VV}{9}\noexploregroups\expandarg}%
& \uncover<8->{= \alert<handout:0| 10-11>{{\int}%
\noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#6}{UU}{8}}{VV}{9}\noexploregroups\expandarg %
}}\\%
& \uncover<10->{%
 \alert<handout:0| 10-11>{ = \uncover<11->{%
\noexpandarg\exploregroups{\StrSubstitute{#7}{UU}{\alert<handout:0| 12>{u}}}\noexploregroups\expandarg%
}}%
  \uncover<12->{%
 = \noexpandarg\exploregroups{\StrSubstitute{#7}{UU}{\alert<handout:0| 12>{#2}}}\noexploregroups\expandarg.%
}%
}\\%
\uncover<13->{%
\text{Therefore}\quad \int%
_{\StrMid{#9}{1}{1}}%
^{\StrMid{#9}{2}{2}} %
 \noexpandarg\exploregroups\StrSubstitute{\StrSubstitute{#1}{UU}{0}}{VV}{0}\noexploregroups\expandarg}%
& \uncover<13->{%
 = \left[%
 \noexpandarg\exploregroups{\StrSubstitute{#7}{UU}{#2}}\noexploregroups\expandarg%
\right]%
_{\StrMid{#9}{1}{1}}%
^{\StrMid{#9}{2}{2}} %
}\\%
& \uncover<14->{%
 = #8.
}%
\end{align*}
\end{example}
}

%
%  An example of a derivative with the Chain Rule, using the symbol y.
%  It looks as follows:
%
%  Differentiate y = #1.
%  Let u = #2
%  Then y = #3
%  Chain Rule: dy/dx = (dy/du)(du/dx)
%  = (#4, with u substituted for UU)(#5)
%  = #6, with #2 substituted for UU
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\chainruley}[7]{%
\begin{example}[Chain Rule%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad y & = #1.\\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 2-3,8-10>{u}%
}%
& \uncover<2->{%
\alert<handout:0| 2-3,8-10>{ = \uncover<3-| handout:0>{#2.}}%
}\\%
\uncover<4->{%
\text{Then}\quad \alert<handout:0| 6-7>{y}%
}%
& \uncover<4->{%
\alert<handout:0| 6-7>{ = \uncover<4-| handout:0>{#3.}}%
}\\%
\uncover<5->{%
\text{Chain Rule:}\quad%
\frac{\diff y}{\diff x}%
}%
& \uncover<5->{%
 = \alert<handout:0| 6-7>{\frac{\diff y}{\diff u}}%
\alert<handout:0| 8-9>{\frac{\diff u}{\diff x}}%
}\\%
& \uncover<6->{%
 = \alert<handout:0| 6-7>{\left( \uncover<7-| handout:0>{\noexpandarg\exploregroups\StrSubstitute{#4}{UU}{\alert<handout:0| 10>{u}}\noexploregroups\expandarg}\right)}%
\alert<handout:0| 8-9>{\left( \uncover<9-| handout:0>{#5}\right)}%
}\\%
& \uncover<10->{ = } \uncover<10-| handout:0>{%
 \noexpandarg\exploregroups \StrSubstitute{#6}{UU}{\alert<handout:0| 10>{#2}}.\noexploregroups\expandarg%
}%
\end{align*}
\end{example}
}





%
%  An example of a derivative with the Chain Rule, using the symbol f(x).
%  It looks as follows:
%
%  Differentiate f(x) = #1.
%  Let h(x) = #2
%  Let g(x) = #3
%  Then f(x) = g(h(x))
%  f'(x) = g'(h(x))h'(x)
%  = (#4, with h(x) substituted for UU)(#5)
%  = #6, with #2 substituted for UU
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\chainrulefofx}[7]{%
\begin{example}[Chain Rule%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate}\quad f(x) & = #1.\\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 2-3,9-11>{h(x)}%
}%
& \uncover<2->{%
\alert<handout:0| 2-3,9-11>{ = \uncover<3-| handout:0>{#2.}}%
}\\%
\uncover<2->{%
\text{Let}\quad\alert<handout:0| 4-5,7-8>{g(x)}%
}%
& \uncover<2->{%
\alert<handout:0| 4-5,7-8>{ = \uncover<5-| handout:0>{#3.}}%
}\\%
\uncover<2-| handout:0>{%
\text{Then}\quad f(x)%
}%
& \uncover<2-| handout:0>{%
 = g(h(x)).%
}\\%
\uncover<6-| handout:0>{%
\text{Chain Rule:}\quad%
f'(x)%
}%
& \uncover<6-| handout:0>{%
 = \alert<handout:0| 7-8>{g'(h(x))}%
\alert<handout:0| 9-10>{h'(x)}%
}\\%
& \uncover<7-| handout:0>{%
=}\uncover<7-| handout:0>{\alert<handout:0| 7-8>{\left( \uncover<8-| handout:0>{\noexpandarg\exploregroups\StrSubstitute{#4}{UU}{\alert<handout:0| 11>{h(x)}}\noexploregroups\expandarg}\right)}%
\alert<handout:0| 9-10>{\left( \uncover<10-| handout:0>{#5}\right)}%
}\\%
& \uncover<11-| handout:0>{=} \uncover<11-| handout:0>{%
 \noexpandarg \exploregroups \StrSubstitute{#6}{UU}{\alert<handout:0| 11>{#2}}.\noexploregroups \expandarg%
}%
\end{align*}
\end{example}
}

%
%  Similar to chainrulefofx but in different style.
%  It looks as follows:
%
%  Recall the chain rule (...).
%******************************
%  Differentiate f(x) = #1.
%  h(x) = #2
%  Let g(u) = #3
%  Then g'(u)=#4
%  Then f(x) = g(u)
%  f'(x) = g'(u)h'(x)
%  = (#4, with h(x) substituted for UU)(#5)
%  = #6, with #2 substituted for UU
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\chainruleStyleOne}[7]{%
{\renewcommand{\arraystretch}{1.2}
$
\begin{array}{rclll}
\alert<1-| handout:0>{\left(g(h(x))\right)'}&\alert<1-| handout:0>{=}&\alert<1-| handout:0>{g'(h(x))\cdot  h'(x)}&& \text{(notation 1)} {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} \\
(g(u))'&\alert<handout:0|0>{=}&g'(u) u'&\text{where } u=h(x)& \text{(notation 2)}\\
\displaystyle\frac{\diff y}{\diff x} &\alert<handout:0|0>{=}& \displaystyle\frac{\diff y}{\diff u}  \frac{\diff u}{\diff x} &\text{where } y=g(u)& \text{(notation 3)}\quad.\\
\end{array}
$
}
\begin{example}[Chain Rule, Notation 1%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\[
\begin{array}{rrcl}
\text{Differentiate } & f(x) & =& #1.\\%
\uncover<2->{%
\text{Let}&\alert<handout:0| 2-3,9-11>{h(x)}%
}%
&\uncover<2-| handout:0>{\alert<handout:0| 2-3,9-11>{=}}&\displaystyle \uncover<2-| handout:0>{%
\alert<handout:0| 2-3,9-11>{ \uncover<3-| handout:0>{#2.}}%
}\\%
\uncover<2->{%
\text{Let}&\alert<handout:0| 4-5,7-8>{g(u)}%
}
&\uncover<2->{\alert<handout:0| 4-5,7-8>{=}}&\displaystyle
\uncover<2->{\alert<handout:0| 4-5,7-8>{\uncover<5-| handout:0>{#3.}}%
}\\%
\uncover<2-| handout:0>{%
\text{Then}& f(x)
}%
&\uncover<2-| handout:0>{{=}}&\uncover<2-| handout:0>{%
 g(h(x)).%
}\\%
\uncover<6->{%
\text{Chain Rule:} &
f'(x)%
}%
&\uncover<6->{=}& \uncover<6->{%
 \alert<handout:0| 7-8>{g'(h(x))}%
\alert<handout:0| 9-10>{h'(x)}%
}\\%
&&\uncover<7-| handout:0>{=}& \displaystyle
\uncover<7-| handout:0>{\alert<handout:0| 7-8>{ \left( \uncover<8-| handout:0>{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 11>{h(x)}} \noexploregroups\expandarg}\right)}%
\alert<handout:0| 9-10>{\left( \uncover<10-| handout:0>{#5}\right)}%
}\\%
&&\uncover<11-| handout:0>{=}&\displaystyle \uncover<11-| handout:0>{%
 \noexpandarg \exploregroups \StrSubstitute{#6}{UU}{\alert<handout:0| 11>{#2}}.\noexploregroups \expandarg%
}%
\end{array}
\]
\end{example}
}

%
%  Similar to chainrulefofx but in different style.
%  It looks as follows:
%
%  Recall the chain rule (...).
%******************************
%  Differentiate f(x) = #1.
%  Let u= #2
%  Let g(u) = #3
%  Then g'(u)=#4
%  Then f(x) = g(u)
%  f'(x) = g'(u)h'(x)
%  = (#4, with h(x) substituted for UU)(#5)
%  = #6, with #2 substituted for UU
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\chainruleStyleTwo}[7]{%
{\renewcommand{\arraystretch}{1.2}
$
\begin{array}{rclll}
\alertNoH{0}{\left(g(h(x))\right)'}&\alertNoH{0}{=}&g'(h(x))  \cdot  h'(x)&& \text{(notation 1)} {~~~~~~~~~~~~~~~~~~~~} \\
\alertNoH{1-}{(g(u))'}&\alertNoH{1-}{=}&\alertNoH{1-}{g'(u) u'}&\text{where } u=h(x)& \text{(notation 2)}\\
\displaystyle\frac{\diff y}{\diff x} &\alertNoH{0}{=}& \displaystyle\frac{\diff y}{\diff u}  \frac{\diff u}{\diff x} &\text{where } y=g(u)& \text{(notation 3)}\quad.\\
\end{array}
$
}
\begin{example}[Chain Rule, Notation 2%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\[
\begin{array}{rrcl}
\text{Differentiate } & f(x) & =& #1.\\%
\uncover<2->{%
\text{Let}&\alert<handout:0| 2-3,9-11>{u}%
}%
&\uncover<2->{\alert<handout:0| 2-3,9-11>{=}}&\displaystyle \uncover<2->{%
\alert<handout:0| 2-3,9-11>{ \uncover<3-| handout:0>{#2.}}%
}\\%
\uncover<2->{%
\text{Let}&\alert<handout:0| 4-5,7-8>{g(u)}%
}
&\uncover<2->{\alert<handout:0| 4-5,7-8>{=}}&\displaystyle
\uncover<2->{\alert<handout:0| 4-5,7-8>{\uncover<5-| handout:0>{#3.}}%
}\\%
\uncover<2->{%
\text{Then}& f(x)
}%
&\uncover<2->{{=}}&\uncover<2->{%
 g(u).%
}\\%
\uncover<6->{%
\text{Chain Rule:} &
f'(x)%
}%
&\uncover<6->{=}& \uncover<6->{%
 \alert<handout:0| 7-8>{g'(u)}%
\alert<handout:0| 9-10>{u'}%
}\\%
&& \uncover<7-|handout:0>{=}&\displaystyle \uncover<7-|handout:0>{\alert<handout:0| 7-8>{\left( \uncover<8-| handout:0>{\noexpandarg\exploregroups\StrSubstitute{#4}{UU}{\alert<handout:0| 11>{u}}\noexploregroups\expandarg}\right)}%
\alert<handout:0| 9-10>{\left( \uncover<10-| handout:0>{#5}\right)}%
}\\%
&& \uncover<11-|handout:0>{ = }&\displaystyle \uncover<11-| handout:0>{%
 \noexpandarg \exploregroups \StrSubstitute{#6}{UU}{\alert<handout:0| 11>{#2}}.\noexploregroups \expandarg%
}%
\end{array}
\]
\end{example}
}


%
%  Similar to chainrulefofx but in different style.
%  It looks as follows:
%
%  Recall the chain rule (...).
%******************************
%  Differentiate f(x) = #1.
%  h(x) = #2
%  Let g(u) = #3
%  Then f(x) = g(u)
%  f'(x) = g'(u)h'(x)
%  = (#4, with h(x) substituted for UU)(#5)
%  = #6, with #2 substituted for UU
%
%  #7 appears in the subtitle of the example.
%
\newcommand{\chainruleStyleThree}[7]{%
{\renewcommand{\arraystretch}{1.2}
$
\begin{array}{rclll}
\alertNoH{0}{\left(g(h(x))\right)'}&\alertNoH{0}{=}&g'(h(x))  \cdot  h'(x)&& \text{(notation 1)} {~~~~~~~~~~~~~~~~~~~~} \\
(g(u))'&\alertNoH{0}{=}&g'(u) u'&\text{where } u=h(x)& \text{(notation 2)}\\
\displaystyle\alertNoH{1-}{\frac{\diff y}{\diff x}}&\alertNoH{1-}{=}&\displaystyle\alertNoH{1-}{\frac{\diff y}{\diff u}  \frac{\diff u}{\diff x}} &\text{where } y=g(u)& \text{(notation 3)}\quad.\\
\end{array}
$
}
\begin{example}[Chain Rule, Notation 3%
\ifthenelse{\equal{#7}{0}}%
{}%
{, #7}%
]%
\[
\begin{array}{rrcl}
\text{Differentiate } & y & =& #1.\\%
\uncover<2->{%
\text{Let}&\alert<handout:0| 2-3,9-11>{u}%
}%
&\uncover<2->{\alert<handout:0| 2-3,9-11>{=}}& \displaystyle \uncover<2->{%
\alert<handout:0| 2-3,9-11>{ \uncover<3-| handout:0>{#2.}}%
}\\%
\uncover<2->{%
\text{Then}&\alert<handout:0| 4-5,7-8>{y}%
}
&\uncover<2->{\alert<handout:0| 4-5,7-8>{=}}&\displaystyle
\uncover<2->{\alert<handout:0| 4-5,7-8>{\uncover<5-| handout:0>{#3.}}%
}\\%
\uncover<6->{%
\text{Chain Rule:} &
\displaystyle \frac{\diff y}{\diff x}%
}%
&\uncover<6->{=}&\displaystyle  \uncover<6->{%
 \alert<handout:0| 7-8>{\frac{\diff y}{\diff u}}%
\alert<handout:0| 9-10>{\frac{\diff u}{\diff x}}%
}\\%
&& \uncover<handout:0|7->{ =}&\displaystyle \uncover<handout:0|7->{\alert<handout:0| 7-8>{ \left( \uncover<8-| handout:0>{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 11>{u}} \noexploregroups\expandarg}\right)}%
\alert<handout:0| 9-10>{\left( \uncover<10-| handout:0>{#5}\right)}%
}\\%
&&\uncover<11->{=}&\displaystyle \uncover<11-| handout:0>{%
\noexpandarg \exploregroups \StrSubstitute{#6}{UU}{\alert<handout:0| 11>{#2}}.\noexploregroups \expandarg%
}%
\end{array}
\]
\end{example}
}

%
%  An example of an infinite limit calculation.
%  There are nine arguments to the function.  The ninth is a string of six
%  plus and minus signs.  Let AA, BB, CC, DD, EE, and FF denote these plus
%  and minus signs.  Then the output of the function looks as follows:
%
%  Find lim_{x \to #1^AA} (#2, with x substituted for UU)/(#3, with x substituted for UU).
%  Plug in #1.
%  (#2, with (#1) substituted for UU)/(#3, with (#1) substituted for UU) = #4/0.
%  The numerator is non-zero and the denominator is zero.
%  Therefore the answer is DNE, infty, or -infty.
%  Factor: (#3, with x substituted for UU)/(#4, with x substituted for UU) = (#5 #6)/(#7 #8)
%  \to ((BB)(CC))/((DD)(EE))
%  = (FF).
%  Therefore lim_{x \to #1^AA} (#2, with x substituted for UU)/(#3, with x substituted for UU) = FF infty.
%
\newcommand{\infinitelimit}[9]{%
\begin{example}[Infinite Limit]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \lim_{x\to #1^{\StrMid{#9}{1}{1}}}
\frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
& \\%
\uncover<2->{%
\text{Plug in $#1$:}\quad%
\frac%
{\alert<handout:0| 2-3>{\noexpandarg\StrSubstitute{#2}{UU}{(#1)}\expandarg}}%
{\alert<handout:0| 4-5>{\noexpandarg\StrSubstitute{#3}{UU}{(#1)}\expandarg}}%
}%
& \uncover<2->{= \frac{\uncover<3->{\alert<handout:0| 3>{#4}}}{\uncover<5->{\alert<handout:0| 5>{0}}}}%
\uncover<6->{%
\intertext{The numerator is non-zero and the denominator is zero.  %}
Therefore the answer is DNE, $\infty$, or $-\infty$.}
}%
\uncover<7->{%
\text{Factor:}\quad
}%
\uncover<7->{%
\lim_{x\to #1^{\StrMid{#9}{1}{1}}}%
\frac%
{\alert<handout:0| 8-9>{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}}%
{\alert<handout:0| 10-11>{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}}%
}%
& \uncover<8->{%
 = \lim_{x\to #1^{\StrMid{#9}{1}{1}}}%
\frac%
{%
\uncover<handout:0| 9->{\alert<handout:0| 9>{%
\alert<handout:0| 12-13>{%
#5%
}%
\alert<handout:0| 14-15>{%
#6%
}%
}}%
}{%
\uncover<handout:0| 11->{\alert<handout:0| 11>{%
\alert<handout:0| 16-17>{%
#7%
}%
\alert<handout:0| 18-19>{%
#8%
}%
}}%
}%
}\\%
& \uncover<12->{%
 \to \alert<handout:0| 20-21>{\frac%
{%
\alert<handout:0| 12-13>{(\uncover<handout:0| 13->{%
\StrMid{#9}{2}{2}%
})}%
\alert<handout:0| 14-15>{(\uncover<handout:0| 15->{%
\StrMid{#9}{3}{3}%
})}%
}{%
\alert<handout:0| 16-17>{(\uncover<handout:0| 17->{%
\StrMid{#9}{4}{4}%
})}%
\alert<handout:0| 18-19>{(\uncover<handout:0| 19->{%
\StrMid{#9}{5}{5}%
})}%
}%
}%
}\\%
& \uncover<20->{\alert<handout:0| 20-21>{ = \uncover<handout:0| 21->{\alert<handout:0| 22>{(\StrMid{#9}{6}{6})}}}}\\%
\uncover<22->{%
\text{Therefore}\quad\lim_{x\to #1^{\StrMid{#9}{1}{1}}}%
\frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
}%
& \uncover<22->{ = } \uncover<handout:0| 22->{ \alert<handout:0| 22>{\StrMid{#9}{6}{6}}\infty.}
\end{align*}
\end{example}
}




%
%  An example of a limit calculation with factoring.
%
%  It looks as follows.
%
%  Find lim_{x \to #1} (#2, with x substituted for UU)/(#3, with x substituted for UU).
%  Plug in #1.
%  (#2, with (#1) substituted for UU)/(#3, with (#1) substituted for UU) = 0/0.
%  Zero over zero gives no information.
%  Factor: (#2, with x substituted for UU)/(#3, with x substituted for UU) = ((#4, with x substituted for UU) #6)/((#5, with x substituted for UU) #6)
%  = (#4, with x substituted for UU)/(#5, with x substituted for UU)
%  Plug in #1: = (#4, with (#1) substituted for UU)/(#5, with (#1) substituted for UU)
%  = #7
%  = #8
%
\newcommand{\limitfactor}[8]{%
\begin{example}[Limit with Factoring]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \lim_{x\to #1}
\frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
& \\%
\uncover<2->{%
\text{Plug in $#1$:}\quad%
\frac%
{\alert<handout:0| 2-3>{\noexpandarg\StrSubstitute{#2}{UU}{(#1)}\expandarg}}%
{\alert<handout:0| 4-5>{\noexpandarg\StrSubstitute{#3}{UU}{(#1)}\expandarg}}%
}%
& \uncover<2->{%
= \frac%
{\uncover<3->{\alert<handout:0| 3>{0}}}%
{\uncover<5->{\alert<handout:0| 5>{0}}}%
}%
\uncover<6->{%
\intertext{Zero over zero is undefined, so we can't use direct substitution.}
}%
\uncover<7->{%
\text{Factor:}\quad%
\lim_{x\to #1} \frac%
{\alert<handout:0| 8-9>{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}}%
{\alert<handout:0| 10-11>{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}}%
}%
& \uncover<8->{%
 = \lim_{x\to #1} \frac%
{%
\uncover<handout:0| 9->{\alert<handout:0| 9>{%
(\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg)%
\alert<handout:0| 12>{#6}%
}}%
}{%
\uncover<handout:0| 11->{\alert<handout:0| 11>{%
(\noexpandarg\StrSubstitute{#5}{UU}{x}\expandarg)%
\alert<handout:0| 12>{#6}%
}}%
}%
}\\%
& \uncover<12->{%
 = \lim_{x\to #1} \frac%
{\uncover<handout:0| 12->{\noexpandarg\StrSubstitute{#4}{UU}{\alert<handout:0| 13>{x}}\expandarg}}%
{\uncover<handout:0| 12->{\noexpandarg\StrSubstitute{#5}{UU}{\alert<handout:0| 13>{x}}\expandarg}}%
}\\%
\uncover<13->{%
\text{Plug in $#1$:}\quad%
\lim_{x\to #1} \frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
}%
& \uncover<13->{%
 = \frac%
{\uncover<handout:0| 13->{\noexpandarg\StrSubstitute{#4}{UU}{(\alert<handout:0| 13>{#1})}\expandarg}}%
{\uncover<handout:0| 13->{\noexpandarg\StrSubstitute{#5}{UU}{(\alert<handout:0| 13>{#1})}\expandarg}}%
}\\%
& \uncover<14->{%
= \uncover<handout:0| 14->{#7}%
}\\%
& \uncover<15->{%
= \uncover<handout:0| 14->{#8.}%
}%
\end{align*}
\end{example}
}




%
%  An example of a limit calculation with a conjugate radical.
%
%  It looks as follows.
%
%  Find lim_{x \to #1} (#2, with x substituted for UU)/(#3, with x substituted for UU).
%  Plug in #1.
%  (#2, with (#1) substituted for UU)/(#3, with (#1) substituted for UU) = 0/0.
%  Zero over zero gives no information.
%  Factor: (#2, with x substituted for UU)/(#3, with x substituted for UU) = ((#4, with x substituted for UU) #6)/((#5, with x substituted for UU) #6)
%  = (#4, with x substituted for UU)/(#5, with x substituted for UU)
%  Plug in #1: = (#4, with (#1) substituted for UU)/(#5, with (#1) substituted for UU)
%  = #7
%  = #8
%
\newcommand{\limitradical}[9]{%
\begin{example}[Limit with Conjugate Radical]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
& \text{Find}\quad \lim_{x\to #1}
\frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
 \\%
\uncover<2->{%
& \text{Plug in $#1$:}\quad%
\frac%
{\alert<handout:0| 2-3>{\noexpandarg\StrSubstitute{#2}{UU}{(#1)}\expandarg}}%
{\alert<handout:0| 4-5>{\noexpandarg\StrSubstitute{#3}{UU}{(#1)}\expandarg}}%
}%
 \uncover<2->{%
= \frac%
{\uncover<3->{\alert<handout:0| 3>{0}}}%
{\uncover<5->{\alert<handout:0| 5>{0}}}%
}%
\uncover<6->{%
\intertext{Zero over zero gives no information.  Use a conjugate radical.}
}%
& \uncover<7->{%
\lim_{x\to #1} \frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\alert<handout:0| 7-8>{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}}%
\cdot %
\frac%
{\uncover<8->{\alert<8>{\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg}}}%
{\uncover<8->{\alert<8>{\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg}}}%
}\\%
& \uncover<9->{%
 = \lim_{x\to #1} \frac%
{(\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg)%
\left(\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg\right)}%
{#5}%
}\\%
& \uncover<10->{%
 = \lim_{x\to #1} \frac%
{(\alert<11-12>{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg})%
\left(\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg\right)}%
{\alert<13-14>{#6}}%
}\\%
\uncover<11->{%
\text{Factor:}\quad%
}%
& \uncover<11->{%
 = \lim_{x\to #1} \frac%
{\uncover<12->{\alert<12>{(\noexpandarg\StrSubstitute{#7}{UU}{x}\expandarg)(x-#1)}}%
\left(\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg\right)}%
{\uncover<14->{\alert<14>{(\noexpandarg\StrSubstitute{#8}{UU}{x}\expandarg)(x-#1)}}}%
}\\%
& \uncover<15->{%
 = \lim_{x\to #1} \frac%
{(\noexpandarg\StrSubstitute{#7}{UU}{x}\expandarg)%
\left(\noexpandarg\StrSubstitute{#4}{UU}{x}\expandarg\right)}%
{\noexpandarg\StrSubstitute{#8}{UU}{x}\expandarg}%
}\\%
\uncover<16->{%
\text{Plug in $#1$:}\quad%
}%
& \uncover<16->{%
 = \frac%
{(\noexpandarg\StrSubstitute{#7}{UU}{(#1)}\expandarg)%
\left(\noexpandarg\StrSubstitute{#4}{UU}{(#1)}\expandarg\right)}%
{\noexpandarg\StrSubstitute{#8}{UU}{(#1)}\expandarg}%
}\\%
& \uncover<17->{%
#9.
}%
\end{align*}
\end{example}
}


%
%  An example of a limit calculation with direct substitution.
%
%  It looks as follows.
%
%  Find lim_{x \to #1} (#2, with x substituted for UU)/(#3, with x substituted for UU).
%  Plug in #1.
%  (#2, with (#1) substituted for UU)/(#3, with (#1) substituted for UU) = 0/0.
%  Zero over zero gives no information.
%  Factor: (#2, with x substituted for UU)/(#3, with x substituted for UU) = ((#4, with x substituted for UU) #6)/((#5, with x substituted for UU) #6)
%  = (#4, with x substituted for UU)/(#5, with x substituted for UU)
%  Plug in #1: = (#4, with (#1) substituted for UU)/(#5, with (#1) substituted for UU)
%  = #7
%  = #8
%
\newcommand{\limitsub}[7]{%
\begin{example}[%
\ifthenelse{\equal{#6}{0}}%
{Limit in Which Direct Substitution Doesn't Work}%
{Limit with Direct Substitution}%
]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Find}\quad \lim_{x\to #1}
\frac%
{\noexpandarg\StrSubstitute{#2}{UU}{x}\expandarg}%
{\noexpandarg\StrSubstitute{#3}{UU}{x}\expandarg}%
& \\%
\uncover<2->{%
\text{Plug in $#1$:}\quad%
\frac%
{\alert<handout:0| 2-3>{\noexpandarg\StrSubstitute{#2}{UU}{(#1)}\expandarg}}%
{\alert<handout:0| 4-5>{\noexpandarg\StrSubstitute{#3}{UU}{(#1)}\expandarg}}%
}%
& \uncover<2->{%
= \frac%
{\uncover<3->{\alert<handout:0| 3>{#4}}}%
{\uncover<5->{\alert<handout:0| 5>{#5}}}%
}\\%
\ifthenelse{\equal{#6}{0}}%
{ }%
{&}%
\uncover<6->{%
\ifthenelse{\equal{#6}{0}}%
{\intertext{Dividing by zero is undefined, so we can't use direct substitution.}}%
{ = #7.}%
}%
\ifthenelse{\equal{#6}{0}}%
{ }%
{ \text{Therefore}= #7.}%
\end{align*}
\end{example}
}



%
%  An example Newton's Method.
%
%  It looks as follows.
%
%  Starting with x_1 = #1, find the third approximation x_3 to the root of the equation #2.
%
%  f(x) = (#3, with x substituted for UU).
%  f'(x) = (#4, with x substituted for UU).
%  Newton's Method: x_{n+1} = x_n - f(x_n)/f'(x_n) = x_n - (#3, with x_n substituted for UU)/(#4, with x_n substituted for UU).
%
%  x_2 = x_1 - (#3, with x_1 substituted for UU)/(#4, with x_1 substituted for UU)     x_3 = x_2 - (#3, with x_2 substituted for UU)/(#4, with x_2 substituted for UU)
%   = (#1) - (#3, with (#1) substituted for UU)/(#4, with (#1) substituted for UU)     = (#5) - (#3, with (#5) substituted for UU)/(#4, with (#5) substituted for UU)
%  = #5.      = #6.
%
\newcommand{\newtonsmethod}[8]{%
\begin{example}[Newton's Method%
\ifthenelse{\equal{#8}{0}}%
{}%
{, #8}%
]%
\ifthenelse{\equal{#7}{0}}%
{%
Starting with $x_1 = #1$, find the third approximation $x_3$ to the root of the equation $#2$.
}%
{#7}%
\abovedisplayskip=0pt
\belowdisplayskip=10pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\uncover<2->{%
\alert<handout:0| 2-3,7>{f(x)}%
& \alert<handout:0| 2-3,7>{ = \uncover<3->{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{x}.\noexploregroups \expandarg}}%
}\\%
\uncover<4->{%
\alert<handout:0| 4-5,8>{f'(x)}%
& \alert<handout:0| 4-5,8>{ = \uncover<5->{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{x}.\noexploregroups \expandarg}}%
}\\%
\uncover<6->{%
\text{Newton's Method:}\quad %
x_{n+1} & = x_n - \frac{\alert<handout:0| 7>{f(x_n)}}{\alert<handout:0| 8>{f'(x_n)}}%
}
\uncover<7->{%
 = x_n - \frac%
{\alert<handout:0| 7>{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{x_n}\noexploregroups \expandarg}}%
{\alert<handout:0| 8>{\uncover<8->{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{x_n}\noexploregroups \expandarg}}}%
}
\end{align*}
\begin{align*}
\uncover<9->{%
x_2 %
}%
& \uncover<9->{%
 = \alert<handout:0| 10>{x_1} - \frac%
{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{\alert<handout:0| 10>{x_1}}\noexploregroups \expandarg}%
{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 10>{x_1}}\noexploregroups \expandarg}%
}%
& \uncover<12->{%
x_3 %
}%
& \uncover<12->{%
 = \alert<handout:0| 13>{x_2} - \frac%
{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{\alert<handout:0| 13>{x_2}}\noexploregroups \expandarg}%
{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 13>{x_2}}\noexploregroups \expandarg}%
}\\%
& \uncover<10->{%
 = \alert<handout:0| 10>{(#1)} - \frac%
{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{\alert<handout:0| 10>{(#1)}}\noexploregroups \expandarg}%
{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 10>{(#1)}}\noexploregroups \expandarg}%
}%
& %
& \uncover<13->{%
 = \alert<handout:0| 13>{(#5)} - \frac%
{\noexpandarg \exploregroups \StrSubstitute{#3}{UU}{\alert<handout:0| 13>{(#5)}}\noexploregroups \expandarg}%
{\noexpandarg \exploregroups \StrSubstitute{#4}{UU}{\alert<handout:0| 13>{(#5)}}\noexploregroups \expandarg}%
}\\%
& \uncover<11->{%
 = #5.%
}%
& %
& \uncover<14->{%
 = #6.
}%
\end{align*}
\end{example}
}


%
%  An example of a derivative using the Chain Rule twice, using dy/dx.
%  It looks as follows:
%
%  Differentiate: y = #1.
%		  dy\dx  = d\dx(#1)
%  Chain Rule:     = (#2) (d/dx)(#3)
%  Chain Rule:     = (#2)(#4) d/dx(#5)
%  #7 [optional]    = (#2)(#3)(#6)
%                             = (#8)
%                             = (#9)    [optional]
%

\newcommand{\chainruletwice}[9]{%
\begin{example}[Using the Chain Rule twice]%
\abovedisplayskip=0pt
\belowdisplayskip=0pt
\abovedisplayshortskip=0pt
\belowdisplayshortskip=0pt
\begin{align*}
\text{Differentiate:}\quad y & = #1.\\%
\uncover<2->{\frac{\diff y}{\diff x} & = \alert<handout:0|3-5>{\frac{\diff}{\diff x}\left( #1\right)}}\\%
\uncover<4->{\text{Chain Rule:} \ \ \quad &= \alert<handout:0|4-5>{\left(\uncover<5-| handout:0>{#2} \right)\alert<handout:0|6-8>{\frac{\diff}{\diff x} \left(\uncover<4-| handout:0>{#3}\right)}}} \\%
\uncover<7->{\text{Chain Rule:} \ \ \quad &= \left(\uncover<7-| handout:0>{#2}\right) \alert<handout:0|7-8>{\left(\uncover<8-| handout:0>{#4}\right) \alert<handout:0|9-10>{\frac{\diff}{\diff x}\left( \uncover<7-| handout:0>{#5} \right)}}}\\%
\uncover<9->{\uncover<10->{\ifthenelse{\equal{#7}{}}{}{\text{#7 :} \ \ \quad}}& = \left(\uncover<9-| handout:0>{#2} \right) \left(\uncover<9-| handout:0>{#4}\right)\alert<handout:0|9-10>{\left( \uncover<10-| handout:0>{#6} \right) }} \\%
\uncover<11->{& = \uncover<11-| handout:0>{#8 \ifthenelse{\equal{#9}{}}{.}{\\}}}%
\ifthenelse{\equal{#9}{}}{}{\uncover<12->{& = \uncover<12-| handout:0>{#9.}}}
\end{align*}
\end{example}
}


 %warning this path is relative to the file that uses the \usepackage command, not relative to the style file.
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../lectures/pstricks-commands.tex
\usepackage{etex, ifthen}
\usepackage [dvips={-o -Ppdf}, pspdf={-dNOSAFER -dAutoRotatePages=/None}, pdfcrop={}]
{auto-pst-pdf}
\usepackage{pst-plot}
\usepackage{pst-math}
%WARNING THE FOLLOWING PACKAGE IS BROKEN use only with EXTREME CAUTION
%\usepackage{pst-3dplot}

\makeatletter
\begingroup
\catcode `P=12  % digits and punct. catcode
\catcode `T=12  % digits and punct. catcode
\lowercase{%
\def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}}
\expandafter\endgroup\x%
\newcommand{\stripPoints}[1]{\expandafter\rem@pt\the#1}
\makeatother

\newcommand{\fcShiftX}{0}
\newcommand{\fcShiftY}{0}
\newcommand{\fcXLabel}{$x$}
\newcommand{\fcYLabel}{$y$}
\newcommand{\fcZLabel}{$z$}
\newcommand{\fcDelta}{0.5}
\newcommand{\fcZBufferNumXIntervals}{20}
\newcommand{\fcZBufferNumYIntervals}{20}
\newcommand{\fcZBufferRowColumnsUnderInvestigation}{(empty) (empty)}
\newcommand{\fcZBufferUparameterPointUnderInvestigation}{(empty) (empty)}
\newcommand{\fcZBufferVparameterPointUnderInvestigation}{(empty) (empty)}
%\newcommand{\fcContourDebugged}{-1}
\newcommand{\fcStartXIId}{0}
\newcommand{\fcStartYIId}{0}
\newcommand{\fcIterationsX}{9\space}
\newcommand{\fcIterationsY}{9\space}
\newcommand{\fcIterationsU}{9\space}
\newcommand{\fcIterationsV}{9\space}
\newcommand{\fcNumCountourSegmentsPatchU}{10\space}
\newcommand{\fcNumCountourSegmentsPatchV}{10\space}
\newcommand{\fcScreenStyle}{z}
\newcommand{\fcColorLine}{black}
\newcommand{\fcForceForeground}{false}
\newcommand{\fcLineWidth}{1}
\newcommand{\fcScale}{1\space}
\newcommand{\fcArrows}{}
\newcommand{\fcPlotPoints}{200}
\newcommand{\fcLineStyle}{0}
\newcommand{\fcDashLength}{2}
\newcommand{\fcContourOptions}{
[(\fcArrows) (->) eq (\fcArrows) (<-) eq (\fcArrows) (<->) eq or or [\fcGetColorCode{\fcColorLine}] \fcLineWidth [\fcDashes] (\fcLineStyle)]
}
\newcommand{\fcDashes}{[1 1] 0}
\newcommand{\fcColorPatchUV}{1 0.5 0.5}
\newcommand{\fcColorPatchVU}{0.7 0.2 0.2}
\newcommand{\fcFastPatchSort}{false}
\newcommand{\fcDashesCode}{%
(\fcLineStyle) (dashed) eq %
{[\fcDashLength\space \fcDashLength] 0 setdash}%
{[] 0 setdash}%
ifelse\space %
}
\newcommand{\fcScreen}{[-1 1 -0.75] -1} %default projection plane. Renew this command to change projection plane.

\newcommand{\fcSet}[1]{\setkeys{fcGraphics}{#1}}

\makeatletter %needed for define@key command.
\define@key{pstricks,pst-plot}{xLabel}[]{}
\define@key{pstricks,pst-plot}{yLabel}[]{}
\define@key{pstricks,pst-plot}{zLabel}[]{}
\define@key{fcGraphics}{Delta}[\renewcommand{\fcDelta}{1}]{\renewcommand{\fcDelta}{#1}}
\define@key{fcGraphics}{shiftX}[\renewcommand{\fcShiftX}{0}]{\renewcommand{\fcShiftX}{#1}}
\define@key{fcGraphics}{shiftY}[\renewcommand{\fcShiftY}{0}]{\renewcommand{\fcShiftY}{#1}}
\define@key{fcGraphics}{startX}[\renewcommand{\fcStartXIId}{0}]{\renewcommand{\fcStartXIId}{#1}}
\define@key{fcGraphics}{startY}[\renewcommand{\fcStartYIId}{0}]{\renewcommand{\fcStartYIId}{#1}}
\define@key{fcGraphics}{colorUV}[\renewcommand{\fcColorPatchUV}{1 0.5 0.5}]{\renewcommand{\fcColorPatchUV}{#1\space}}
\define@key{fcGraphics}{colorVU}[\renewcommand{\fcColorPatchVU}{0.7 0.2 0.2}]{\renewcommand{\fcColorPatchVU}{#1\space}}
\define@key{fcGraphics}{iterationsU}[\renewcommand{\fcIterationsU}{9\space}]{\renewcommand{\fcIterationsU}{#1\space}}
\define@key{fcGraphics}{iterationsV}[\renewcommand{\fcIterationsU}{9\space}]{\renewcommand{\fcIterationsV}{#1\space}}
\define@key{fcGraphics}{forceForeground}[\renewcommand{\fcForceForeground}{false\space}]{\renewcommand{\fcForceForeground}{#1\space}}
\define@key{fcGraphics}{iterationsX}[\renewcommand{\fcIterationsX}{9\space}]{\renewcommand{\fcIterationsX}{#1\space}}
\define@key{fcGraphics}{scale}[\renewcommand{\fcScale}{1}]{\renewcommand{\fcScale}{#1\space}}
%\define@key{fcGraphics}{debugContour}[\renewcommand{\fcContourDebugged}{-1\space}]{\renewcommand{\fcContourDebugged}{#1\space}}
\define@key{fcGraphics}{iterationsY}[\renewcommand{\fcIterationsY}{9\space}]{\renewcommand{\fcIterationsY}{#1\space}}
\define@key{fcGraphics}{screenStyle}[\renewcommand{\fcScreenStyle}{z}]{\renewcommand{\fcScreenStyle}{#1}}
\define@key{fcGraphics}{xLabel}[\renewcommand{\fcXLabel}{$x$}]{\renewcommand{\fcXLabel}{#1}}
\define@key{fcGraphics}{yLabel}[\renewcommand{\fcYLabel}{$y$}]{\renewcommand{\fcYLabel}{#1}}
\define@key{fcGraphics}{zLabel}[\renewcommand{\fcZLabel}{$z$}]{\renewcommand{\fcZLabel}{#1}}
\define@key{fcGraphics}{linecolor}[\renewcommand{\fcColorLine}{black}]{\renewcommand{\fcColorLine}{#1}}
\define@key{fcGraphics}{linewidth}[\renewcommand{\fcLineWidth}{1}]{\renewcommand{\fcLineWidth}{#1}}
\define@key{fcGraphics}{linestyle}[\renewcommand{\fcLineStyle}{0}]{\renewcommand{\fcLineStyle}{#1}}
\define@key{fcGraphics}{linestyle}[\renewcommand{\fcLineStyle}{0}]{\renewcommand{\fcLineStyle}{#1}}
\define@key{fcGraphics}{fastsort}[\renewcommand{\fcFastPatchSort}{false}]{\renewcommand{\fcFastPatchSort}{#1}}
\define@key{fcGraphics}{dashes}[\renewcommand{\fcDashes}{[1 1] 0}]{\renewcommand{\fcDashes}{#1}}
\define@key{fcGraphics}{arrows}[\renewcommand{\fcArrows}{}]{\renewcommand{\fcArrows}{#1}}
\makeatother %undoes \makeatletter.


\newcommand{\fcHollowDot}[2]{
\pscircle*[fillcolor=white, linecolor=red](#1, #2){0.07}
\pscircle*[fillcolor=white, linecolor=white](#1, #2){0.04}
}

\newcommand{\fcFullDot}[3][linecolor=red]{
\setkeys{fcGraphics}{#1}
\pscircle*[#1](! #2 #3){! 0.07 \fcScale\space mul}
}

\newcommand{\fcFullDotCode}{
gsave
\fcCoordsPStricksToPS [0.02 0] \fcCoordsPStricksToPS pop 0 360 arc 1 0 0 setrgbcolor fill stroke
grestore
}

\newcommand{\fcHollowDotCode}{
gsave
\fcCoordsPStricksToPS [0.04 0] \fcCoordsPStricksToPS pop 0 360 arc 0 1 0 setrgbcolor stroke
grestore
}

\newcommand{\fcHashString}{
2 dict begin
/theString exch def
/counter -1 def
0
theString length {
/counter counter 1 add def
theString counter get cvi counter 1 add mul add
}repeat
20 string cvs
end
}

\newcommand{\fcToString}{
1 dict begin
/ToString
{
5 dict begin
cvlit
/theData exch def
theData type (arraytype) eq{
([)
theData{ToString ( )} forall
(])
theData length 2 mul 2 add \fcConcatenateMultiple
}
{theData 20 string cvs}
ifelse
end
} def %
ToString
end\space
}

\newcommand{\fcConcatenate}{ %Code taken from stackexchange, many thanks!
exch dup length
2 index length add string
dup dup 4 2 roll copy length
4 -1 roll putinterval
}

\newcommand{\fcConcatenateMultiple}{ %Code taken from stackexchange, many thanks!
%Usage: (s1) (s2) (s3) ... (sN) n  \fcConcatenateMultiple  (s1s2s3...sN)
% s1 s2 s3 .. sN n                   % first sum the lengths
dup 1 add  % s1 s2 s3 .. sN n n+1
copy       % s1 s2 s3 .. sN n  s1 s2 s3 .. sN n
0 exch     % s1 s2 s3 .. sN n  s1 s2 s3 .. sN 0 n
{exch length add} repeat % s1 s2 s3 .. sN  n   len  % then allocate string
string exch          % s1 s2 s3 .. sN str   n
0 exch               % s1 s2 s3 .. sN str  off  n
-1 1 {               % s1 s2 s3 .. sN str  off  n  % copy each string
  2 add -1 roll       % s2 s3 .. sN str  off s1  % bottom to top
  3 copy putinterval  % s2 s3 .. sN str' off s1
  length add          % s2 s3 .. sN str' off+len(s1)
                      % s2 s3 .. sN str' off'
} for                               % str' off'
pop  % str'
}

\newcommand{\fcRiemannSum}[6][linecolor=\fcColorGraph]{%
\pstVerb{%
15 dict begin 
/numIntervals #5\space def
/leftEnd #2\space def
/rightEnd #3\space def
/pointRatio #6\space def
/DeltaX rightEnd leftEnd sub numIntervals div def
/function {#4} def
}%
\multido{\ra=0+1}{#5}{%
\pstVerb{/iteration \ra\space def
/currentLeft iteration DeltaX mul leftEnd add def
/x pointRatio DeltaX mul currentLeft add def
}%
\psline*[linecolor=cyan](! currentLeft 0)(! currentLeft DeltaX add 0)(! currentLeft DeltaX add function)(! currentLeft function) (! currentLeft 0)%
\psline[linecolor=blue](! currentLeft 0)(! currentLeft DeltaX add 0)(! currentLeft DeltaX add function)(! currentLeft function) (! currentLeft 0)%
}%
\psplot[#1]{leftEnd}{rightEnd}{function}%
\pstVerb{end}%
}

\newcommand{\fcRectangularRiemannSumCode}{
/theRiemannSumFigure exch def
theRiemannSumFigure \fcSetupFiles
graphicsCached not{
theRiemannSumFigure \fcArrayToStack
20 dict begin
/theFunction exch def
/yIterations exch def
/xIterations exch def
/yMax exch def
/xMax exch def
/yMin exch def
/xMin exch def
/DeltaX xMax xMin sub xIterations div def
/DeltaY yMax yMin sub yIterations div def
/theSideColor exch def
/theContourColor exch def
/x xMin def
xIterations{
/y yMin def
yIterations{
/xOld x def
/yOld y def
/x x DeltaX 2 div add def
/y y DeltaY 2 div add def
/z theFunction def
[xOld yOld 0]
[xOld DeltaX add yOld 0]
[xOld yOld DeltaY add 0]
[xOld yOld z]
theContourColor
theSideColor
true
false
[\fcDashes]
\fcBoxIIIdFilledCode
/x xOld def
/y yOld DeltaY add def
}repeat
/x x DeltaX add def
}repeat
end
}if
}

\newcommand{\fcRectangularRiemannSum}[8][]{
\setkeys{fcGraphics}{#1}
\pscustom{%
\code{%
[[\fcGetColorCode{\fcColorLine}] [\fcGetColorCode{\fcColorPatchUV}]  #2\space #3\space #4\space #5 \space #6\space #7\space {#8}\space]
\fcRectangularRiemannSumCode
}%
}%
}

\newcommand{\fcTextCode}{
/Times-Roman findfont
4 scalefont
setfont
newpath
\fcCoordsPStricksToPS moveto
show
stroke
}

\newcommand{\fcHollowDotBlue}[2]{
\pscircle*[fillcolor=white, linecolor=blue](#1, #2){0.07}
\pscircle*[fillcolor=white, linecolor=white](#1, #2){0.04}
}
\newcommand{\fcFullDotBlack}[2]{
\pscircle*[fillcolor=white, linecolor=black](#1, #2){0.07}
}
\newcommand{\fcFullDotBlue}[2]{
\pscircle*[fillcolor=white, linecolor=blue](#1, #2){0.07}
}
\newcommand{\fcXTickColored}[2]{\psline[linecolor=#1](#2, -0.1)(#2,0.1)}

\newcommand{\fcXTick}[1]{\psline(! #1\space -0.1)(! #1 \space 0.1)}
\newcommand{\fcYTick}[1]{\psline(! -0.1 #1)(! 0.1 #1)}
\newcommand{\fcXYTick}[2]{\fcXTick{#1} \fcYTick{#2}}

\newcommand{\fcXTickWithLabel}[2]{\fcXTick{#1}\rput[t](! #1\space -0.2){#2}}
\newcommand{\fcYTickWithLabel}[2]{\fcYTick{#1}\rput[r](! -0.2 #1){#2}}

\newcommand{\fcLabelNumberXaxis}[1]{\fcXTickWithLabel{#1}{#1}}
\newcommand{\fcLabelNumberYaxis}[1]{\fcYTickWithLabel{#1}{#1}}

\newcommand{\fcLabelNumberXYaxes}[2]{\fcLabelNumberXaxis{#1} \fcLabelNumberYaxis{#2} }

\newcommand{\fcLabelXOne}{\fcLabelNumberXaxis{1} }
\newcommand{\fcLabelYOne}{\fcLabelNumberYaxis{1} }

\newcommand{\fcLabelOnXaxis}[2]{\fcXTick{#1}\rput[t](#1,-0.2){#2}}
\newcommand{\fcLabelOnYaxis}[2]{\fcYTick{#1}\rput[r](-0.2, #1){#2}}

\newcommand{\fcLabels}[1][$x$]{%
  \def\ArgpsXAxisLabel{{#1}}%
  \fcLabelsRelay
}
\newcommand\fcLabelsRelay[3][$y$]{\rput[t](! #2 -0.1){\ArgpsXAxisLabel}\rput[r](! -0.1 #3){#1}}

\newcommand{\fcLabelsWithOnes}[2]{\psline(1, -0.1)(1,0.1) \rput[t](1, -0.2 ) { $1$} \psline(-0.1, 1)(0.1, 1) \rput[r](-0.2, 1 ) { $1$} \fcLabels{#1}{#2}}

\newcommand{\fcDefaultXLabel}{$x$}
\newcommand{\fcDefaultYLabel}{$y$}

\newcommand{\fcBoundingBox}[4]{%
\psframe*[linecolor=white](! #1\space #2)(! #3\space #4)%
\psline[linecolor=black!1](! #1 #2 )(! #1 #2 0.01 add)%
\psline[linecolor=black!1](! #3 #4 )(! #3 #4 0.01 add)%
}
\newcommand{\fcAxesStandardNoFrame}[5][]{%
\psaxes[ticks=none, labels=none,#1]{<->}(0,0)(#2,#3)(#4,#5)% \fcLabels[\fcDefaultXLabel][\fcDefaultYLabel]{#3}{#4}%
}%

\newcommand{\fcAxesStandard}[5][]{%
\psframe*[linecolor=white](! #2\space #3)(! #4 \space 0.1 add #5 \space 0.1 add)%
\fcAxesStandardNoFrame[#1]{#2}{#3}{#4}{#5}%
}%
\newcommand{\fcColorTangent}{blue}
\newcommand{\fcColorGraph}{red}
\newcommand{\fcColorAreaUnderGraph}{cyan}
\newcommand{\fcColorNegativeAreaUnderGraph}{orange}

\newcommand{\fcMachine}[2]{
\pscustom*[linecolor=#2]{
\psline(1,1.1)(1,0.1)(1.5,0.1)(2, 0.6)(2.5, 0.6)(2.5, -0.6)(2, -0.6)(1.5,-0.1)(1,-0.1)(1,-1.1)(-1,-1.1)(-1,-0.1)(-1.5,-0.1)(-2, -0.6)(-2.5, -0.6)(-2.5, 0.6)(-2, 0.6)(-1.5,0.1)(-1,0.1)(-1,1.1)
}
\pscircle*[linecolor=white](0,0){0.3}
\rput(0,0){#1}
}

%command format
%first argument gives you formula for the direction field in
%postscript notation, for example x y add.
%second and third argument give the starting x,y coordinates
\newcommand{\fcDirectionFieldOneTangent}[6]{%
\pstVerb{%
3 dict begin%
/x #2 \space def%
/y #3 \space def%
/F #1 \space def%
}%
\psline[#6](! x F ATAN 57.295 mul cos #4 mul sub y F ATAN 57.295 mul sin #4 mul sub)(! x F ATAN 57.295 mul cos #4 mul add y F ATAN 57.295 mul sin #4 mul add)%
\pscircle*[linecolor=red!60](! x y){#5}%
\pstVerb{%
end%
}%
}

\newcommand{\fcDirectionFieldOneTangentDefault}[3]{%
\fcDirectionFieldOneTangent{#1}{#2}{#3}{0.3}{0.03}{linecolor=blue}%
}

%command format
%first argument gives you formula for the direction field in
%postscript notation, for example x y add.
%second and third argument give the starting x,y coordinates
%fourth coordinate gives the delta x=delta y
%fifth argument gives the number of iterations delta x
%sixth argument gives the number of iterations delta y
%seventh argument gives the length of the vector
%eighth  argument gives the circle radius
%ninth argument gives the arguments of the psline command
\newcommand{\fcDirectionFieldFull}[9]{%
\multido{\ra=#2+#4}{#5}{%
\multido{\rb=#3+#4}{#6}{%
\fcDirectionFieldOneTangent{#1}{\ra}{\rb}{#7}{#8}{#9}%
}%end multido
}%end multido
}%end newcommand

\newcommand{\fcDirectionFieldDefault}[5]{%
\fcDirectionFieldFull{#1}{#2}{#3}{#4}{#5}{#5}{0.2}{0.02}{linecolor=blue}%
}%
\newcommand{\fcDirectionFieldDefaultRange}[1]{%
\fcDirectionFieldFull{#1}{-4}{-4}{0.5}{21}{21}{0.2}{0.02}{linecolor=blue}%
}

\newcommand{\fcMatrixTimesMatrix}{
10 dict begin
/matrixRight exch def
/matrixLeft exch def
/rowCounter -1 def
[
matrixLeft length {
/rowCounter rowCounter 1 add def
/columnCounter -1 def
[
matrixRight 0 get length{
/columnCounter columnCounter 1 add def
/thirdCounter -1 def
/accum 0 def
matrixLeft rowCounter get length{
/thirdCounter thirdCounter 1 add def
/accum accum
matrixLeft rowCounter get thirdCounter get
matrixRight thirdCounter get columnCounter get
mul add def
}repeat
accum
}repeat
]
}repeat
]
end
}

\newcommand{\fcMatrixTimesVector}{
10 dict begin
/theVector exch def
/theMatrix exch def
/rowCounter -1 def
[
theMatrix length {
/rowCounter rowCounter 1 add def
/columnCounter -1 def
/accum 0 def
theVector length{
/columnCounter columnCounter 1 add def
/accum accum
theMatrix rowCounter get columnCounter get theVector columnCounter get mul
add def
}repeat
accum
}repeat
]
end
}

\newcommand{\fcVectorProjectOntoVector}{%
\fcVectorNormalize dup 3 1 roll \fcVectorScalarVector \fcVectorTimesScalar%
} %

%fcAngleIIId Arguments:
%first optional: pstricks options
%second: vector describing arm of first angle
%third: vector describing arm of second angle
%fourth: radius of arc representing the angle
\newcommand{\fcAngleIIId}[4][]{%
\pstVerb{%
3 dict begin%
/firstV #2 \fcVectorNormalize def%
/orthonormalV #3 dup firstV  \fcVectorProjectOntoVector \fcVectorMinusVector \fcVectorNormalize def%
/theAngle firstV #3\space \fcVectorNormalize \fcVectorScalarVector arccos def%
}%
\parametricplot[#1]{0}{theAngle}{firstV t cos #4 mul \fcVectorTimesScalar orthonormalV t sin #4 mul \fcVectorTimesScalar \fcVectorPlusVector \fcCoordsIIIdToPStricks}%
\pstVerb{end}%
}

\newcommand{\fcAngleDegrees}[5][linecolor=red]{%
\parametricplot[#1]{#2}{#3}{t cos #4\space mul t sin #4\space mul}%
\rput(! #2\space #3\space add 2 div dup cos #4\space 1.2 mul mul exch sin #4\space 1.2 mul mul){#5}%
}

\newcommand{\fcAngleBetweenVectors}[5][linecolor=\fcColorGraph]{%
\pstVerb{%
3 dict begin%
/firstV #2 \fcVectorNormalize def%
/orthonormalV #3 dup firstV  \fcVectorProjectOntoVector \fcVectorMinusVector \fcVectorNormalize def%
/theAngle firstV #3\space \fcVectorNormalize \fcVectorScalarVector arccos def%
}%
\parametricplot[#1]{0}{theAngle}{firstV t cos #4 mul \fcVectorTimesScalar orthonormalV t sin #4 mul \fcVectorTimesScalar \fcVectorPlusVector \fcArrayToStack}%
\rput(! firstV theAngle 2 div cos #4 mul \fcVectorTimesScalar orthonormalV theAngle 2 div sin #4 mul \fcVectorTimesScalar \fcVectorPlusVector \fcArrayToStack){#5}
\pstVerb{end}%
}

\makeatletter
\newcommand{\fcAngle}[5][linecolor=\fcColorGraph]{%
\ifPst@algebraic{%
\parametricplot[#1, algebraic=true]{#2}{#3}{#4*cos(t)| #4*sin(t)}%
\rput(! #2\space #3\space add 2 div 57.29578 mul cos #4\space 0.2 add mul #2\space #3\space add 2 div 57.29578 mul sin #4\space 0.2 add mul){#5}%
}%
\else%
\parametricplot[#1, algebraic=false]{#2}{#3}{t 57.29578 mul cos #4\space mul t 57.29578 mul sin #4\space mul}%
\rput(! #2\space #3\space add 2 div 57.29578 mul cos #4\space 0.2 add mul #2\space #3\space add 2 div 57.29578 mul sin #4\space 0.2 add mul){#5}%
\fi%
}
\makeatother

\newcommand{\fcDistance}{ \fcVectorMinusVector \fcVectorNorm\space}

\newcommand{\fcLengthIndicator}[5]{
\psline[arrows=<-, linecolor=red](! #1 #2)(! #1 0.58 mul #3 0.42 mul add #2 0.58 mul #4 0.42 mul add)
\psline[arrows=->, linecolor=red]{->}(! #1 0.42 mul #3 0.58 mul add #2 0.42 mul #4 0.58 mul add)(! #3 #4)
\rput(! #1 #3 add 0.5 mul #2 #4 add 0.5 mul){ #5}
}

\newcommand{\fcLengthIndicatorTwo}[6][t]{%
\pstVerb{5 dict begin
/pointA [#2\space #3] def 
/pointB [#4\space #5] def 
}%
\psline[arrows=|-|](! pointA \fcArrayToStack)(! pointB \fcArrayToStack)%
\rput[#1](! pointA pointB \fcVectorPlusVector 0.5 \fcVectorTimesScalar \fcArrayToStack){#6}%
\pstVerb{end}%
%\rput[#1](0 ,0){#1}%
}

\makeatletter
\newcommand{\fcDrawPolar}[4][linecolor=\fcColorGraph]{%
\ifPst@algebraic{%
\parametricplot[#1]{#2}{#3}{(#4) *cos(t) | (#4) * sin(t)}%
}%
\else%
\parametricplot[#1]{#2}{#3}{#4 t 57.29578 mul cos mul #4 t 57.29578 mul sin mul}%
\fi%
}
\makeatother

\newcommand{\fcPolarWedge}[4][fillstyle=solid, linecolor=blue, fillcolor=\fcColorAreaUnderGraph]{%
\pstVerb{%
2 dict begin%
/theta {t 57.295779513 mul} def%
/r {#4} def%
}%
\pscustom[#1]{%
\psline(0,0)%
(! 1 dict begin /t #2\space def theta cos r mul theta sin r mul end)%
(! 1 dict begin /t #3\space def theta cos r mul theta sin r mul end)%
(0,0)%
} %
\pstVerb{end}%
}%

\newcommand{\fcPolarWedgeSequence}[4]{%
\multido{\ra=#1+#2}{#3}{%
\fcPolarWedge{\ra}{\ra\space #2 add}{#4}%
}%
}

\newcommand{\fcRegularNgon}[3][linecolor=\fcColorGraph]{%
\multido{\ra=0+1}{#2}{%
\psline[#1](! \ra \space #2 div 360 mul cos #3 mul \ra \space #2 div 360 mul sin #3 mul)(! \ra \space 1 add #2 div 360 mul cos #3 mul \ra \space 1 add #2 div 360 mul sin #3 mul)%
}%end multido
}

\newcommand{\fcEvaluateT}[2]{%
1 dict begin /t #1 def #2 end
}

\newcommand{\fcPolylineAlongCurve}[5][linecolor=\fcColorGraph]{%
\multido{\ra=0+1}{#2}{%
\psline[#1](! \fcEvaluateT{\ra\space #2 div #3 mul 1 \ra \space #2 div sub #4 mul add}{#5})(! \fcEvaluateT{\ra\space 1 add #2 div #3 mul 1 \ra \space 1 add #2 div sub #4 mul add}{#5})%
\rput(! \fcEvaluateT{\ra\space #2 div #3 mul 1 \ra \space #2 div sub #4 mul add}{#5}){\fcFullDot{0}{0}}%
}%
\rput(! \fcEvaluateT{#3}{#5}){\fcFullDot{0}{0}}%
}

\newcommand{\fcPolylineAlongCurveWithLabels}[6][linecolor=\fcColorGraph]{%
\fcPolylineAlongCurve[#1]{#2}{#3}{#4}{#5}%
\multido{\ia=0+1}{#2}{%
\rput[b](! \fcEvaluateT{\ia\space #2 div #3 mul 1 \ia \space #2 div sub #4 mul add}{#5} 0.1 add){${#6}_{\ia}$}%
}%
\rput[b](! \fcEvaluateT{#3}{#5}){${#6}_{#2}$}%
}

\newcommand{\fcVectorNormalize}{ %
1 dict begin %
/theV exch def % theV is our vector
theV 1 theV \fcVectorNorm div \fcVectorTimesScalar %
end %
} %pushes elements of array onto the stack

\newcommand{\fcArrayToStack}{ %
aload pop
} %pushes elements of array onto the stack

\newcommand{\fcSpliceArrayOperationArray}{ %
5 dict begin %
/theOp exch def %
/secondV exch def %
/firstV exch def %
/counter 0 def %
/dimension firstV length def %
[dimension {firstV counter get secondV counter get theOp /counter counter 1 add def } repeat] %
end %
} %splices two arrays and operation, for example [a b] [c d] {op} -> [a c op b d op]

\newcommand{\fcSpliceArrayOperation}{ %
4 dict begin %
/theOp exch def %
/firstV exch def %
/counter 0 def %
/dimension firstV length def %
[ dimension {firstV counter get theOp /counter counter 1 add def } repeat ] %
end %
} %splices array with operation. [a b] {op} -> [a op b op]

\newcommand{\fcArrayOperation}{ %
4 dict begin %
/theOp exch def %
/firstV exch def %
/counter 0 def%
/dimension firstV length def %
dimension {firstV counter get /counter counter 1 add def} repeat %
dimension 1 sub {theOp} repeat %
end %
} %applies operation n-1 times to array. Example: [a b c] {op} -> a b c op op

\newcommand{\fcVectorScalarVector}{%
{mul} \fcSpliceArrayOperationArray {add}\fcArrayOperation
} %Scalar product two vectors

\newcommand{\fcVectorPlusVector}{%
{add} \fcSpliceArrayOperationArray %
} %Adds two vectors

\newcommand{\fcVectorMinusVector}{%
{sub} \fcSpliceArrayOperationArray %
} %Adds two vectors

\newcommand{\fcVectorTimesScalar}{ %
2 dict begin %
/theScalar exch def %
/theV exch def %
theV {theScalar mul} \fcSpliceArrayOperation %
end %
} %

\newcommand{\fcVectorTripleProduct}{%
\fcVectorCrossVector \fcVectorScalarVector\space %
}

\newcommand{\fcVectorCrossVector}{ %
8 dict begin %
/vectB exch def %
/vectA exch def %
vectA \fcArrayToStack %
/a3 exch def %The three coordinates of Vector a
/a2 exch def %
/a1 exch def %
vectB \fcArrayToStack %
/b3 exch def %The three coordinates of Vector b
/b2 exch def %
/b1 exch def %
[a2 b3 mul a3 b2 mul sub a3 b1 mul a1 b3 mul sub a1 b2 mul a2 b1 mul sub] %the cross product of a and b
end %
}

\newcommand{\fcVectorNorm}{%
dup \fcVectorScalarVector sqrt %
} %

\newcommand{\fcVectorNormSquared}{%
dup \fcVectorScalarVector %
} %

\newcommand{\fcMarkClean}{
mark\space
}

\newcommand{\fcMarkCleanCheck}{
counttomark 0 ne {(ERROR: procedure did not clean up properly. Printing stack: ) print pstack == error}if pop
}

\newcommand{\fcProjectOntoScreen}{%
3 dict begin %
\fcScreen\space %
/theD exch def %
/theNormal exch def %
/theV exch def %
theV theNormal theD theV theNormal \fcVectorScalarVector sub theNormal \fcVectorNormSquared div \fcVectorTimesScalar \fcVectorPlusVector %
end %
} %Projection of point onto a plane. First argument is point, second argument is plane normal, third argument is the scalar product you need to have with the normal to be in the plane. Format: [1 2 3] [4 5 6] 7, corresponds to projecting the point (1,2,3) onto the plane 4x+5y+6z=7

\newcommand{\fcCoordsIIIdToPStricks}{%
5 dict begin %
/theV exch def %
/theVprojected theV \fcProjectOntoScreen [0 0 0] \fcProjectOntoScreen  \fcVectorMinusVector def%
/theNormalizedNormal \fcScreen\space pop \fcVectorNormalize def %
(\fcScreenStyle) (z) eq %
{ %
/theYUnitV [0 0 1] \fcProjectOntoScreen [0 0 0] \fcProjectOntoScreen \fcVectorMinusVector \fcVectorNormalize def %
/theXUnitV theNormalizedNormal theYUnitV \fcVectorCrossVector def %
} %
{ %
(\fcScreenStyle) (x) eq %
{
/theXUnitV [1 0 0] \fcProjectOntoScreen [0 0 0] \fcProjectOntoScreen \fcVectorMinusVector \fcVectorNormalize def %
/theYUnitV theXUnitV theNormalizedNormal \fcVectorCrossVector def%
}
{
/theYUnitV \fcScreenStyle \fcProjectOntoScreen [0 0 0] \fcProjectOntoScreen \fcVectorMinusVector \fcVectorNormalize def%
/theXUnitV theNormalizedNormal theYUnitV \fcVectorCrossVector def%
} ifelse%
}%
ifelse %
%(normalized normal: ) == theNormalizedNormal ==
%(y unit v) == theYUnitV ==
%(x unit v: ) == theXUnitV ==
theVprojected theXUnitV \fcVectorScalarVector theVprojected theYUnitV \fcVectorScalarVector
end %
}

\newcommand{\fcCoordsIIIdToPS}{%
[ exch \fcCoordsIIIdToPStricks ] \fcCoordsPStricksToPS
}

\newcommand{\fcBoxIIId}[5][]{%
\pstVerb{%
4 dict begin%
/visibleCorner #2 def%
/vectorOne #3 #2 \fcVectorMinusVector def%
/vectorTwo #4 #2 \fcVectorMinusVector def%
/vectorThree #5 #2 \fcVectorMinusVector def%
}%
\fcPolyLineIIId[#1]{visibleCorner dup vectorOne \fcVectorPlusVector dup vectorTwo \fcVectorPlusVector dup vectorOne \fcVectorMinusVector dup vectorTwo \fcVectorMinusVector visibleCorner}%
\fcPolyLineIIId[#1]{visibleCorner dup vectorOne \fcVectorPlusVector dup vectorThree \fcVectorPlusVector dup vectorOne \fcVectorMinusVector dup vectorThree \fcVectorMinusVector}%
\fcPolyLineIIId[#1]{visibleCorner vectorTwo \fcVectorPlusVector dup vectorThree \fcVectorPlusVector dup vectorTwo \fcVectorMinusVector}%
\fcPolyLineIIId[#1, linestyle=dashed]{visibleCorner vectorOne  vectorTwo vectorThree \fcVectorPlusVector \fcVectorPlusVector \fcVectorPlusVector dup vectorOne \fcVectorMinusVector}%
\fcPolyLineIIId[#1, linestyle=dashed]{visibleCorner vectorOne  vectorTwo vectorThree \fcVectorPlusVector \fcVectorPlusVector \fcVectorPlusVector dup vectorTwo \fcVectorMinusVector}%
\fcPolyLineIIId[#1, linestyle=dashed]{visibleCorner vectorOne  vectorTwo vectorThree \fcVectorPlusVector \fcVectorPlusVector \fcVectorPlusVector dup vectorThree \fcVectorMinusVector}%
\pstVerb{end}%
}

\newcommand{\fcParallelogramIIIdCode}{
4 dict begin
/v2 exch def
/v1 exch def
/v0 exch def
/secondRun false def
2 {
newpath
v0 \fcCoordsPStricksToPS moveto
v0 v1 \fcVectorPlusVector \fcCoordsPStricksToPS lineto
v0 v1 v2 \fcVectorPlusVector \fcVectorPlusVector \fcCoordsPStricksToPS lineto
v0 v2 \fcVectorPlusVector \fcCoordsPStricksToPS lineto
v0 \fcCoordsPStricksToPS lineto
closepath
secondRun not {fill} if
stroke
/secondRun true def
}repeat
end
}

\newcommand{\fcPatchMakeFromThreeCorners}{
5 dict begin
/options exch def
/v2 exch def
/v1 exch def
/v0 exch def
/v3 v1 v2 \fcVectorPlusVector v0 \fcVectorMinusVector def
[v0 v1 v2 v3 [v0 v1 v1 v3 v3 v2 v2 v0] options]
end
}

\newcommand{\fcZDepth}{
\fcScreen\space pop \fcVectorScalarVector
}

\newcommand{\fcBoxIIIdFilledCode}{
%input order
% corner0 corner1 corner2 corner3
15 dict begin
/currentDashes exch def
/contourIsDashedIndependentOfVisibility exch def
/sidesVisible exch def
/colorSides exch def
/colorContour exch def
/options [colorSides colorSides true true colorContour contourIsDashedIndependentOfVisibility currentDashes] def
/corner3 exch def
/corner2 exch def
/corner1 exch def
/corner0 exch def
/v1 corner1 corner0 \fcVectorMinusVector def
/v2 corner2 corner0 \fcVectorMinusVector def
/v3 corner3 corner0 \fcVectorMinusVector def
%the following code selects the corner closest to the viewing screen
v1 \fcScreen\space pop \fcVectorScalarVector 0 lt
{/corner0 corner0 v1 \fcVectorPlusVector def /v1 v1 -1 \fcVectorTimesScalar def }if
v2 \fcScreen\space pop \fcVectorScalarVector 0 lt
{/corner0 corner0 v2 \fcVectorPlusVector def /v2 v2 -1 \fcVectorTimesScalar def }if
v3 \fcScreen\space pop \fcVectorScalarVector 0 lt
{/corner0 corner0 v3 \fcVectorPlusVector def /v3 v3 -1 \fcVectorTimesScalar def }if
%the closest corner is selected, we are recomputing the box corners
/corner1 corner0 v1 \fcVectorPlusVector def
/corner2 corner0 v2 \fcVectorPlusVector def
/corner3 corner0 v3 \fcVectorPlusVector def
[
corner0 corner1 corner2 options \fcPatchMakeFromThreeCorners
corner0 corner2 corner3 options \fcPatchMakeFromThreeCorners
corner0 corner3 corner1 options \fcPatchMakeFromThreeCorners
%corner1 corner1 v2 \fcVectorPlusVector corner1 v3 \fcVectorPlusVector options \fcPatchMakeFromThreeCorners
%corner2 corner2 v3 \fcVectorPlusVector corner2 v1 \fcVectorPlusVector options \fcPatchMakeFromThreeCorners
%corner3 corner3 v1 \fcVectorPlusVector corner3 v2 \fcVectorPlusVector options \fcPatchMakeFromThreeCorners
]
/LeftGreaterThanRight {\fcPatchGetPoint \fcZDepth exch \fcPatchGetPoint \fcZDepth gt} def
\fcMergeSort
sidesVisible{dup {\fcPatchPaintFilledDirectly }forall }if
{\fcPatchPaintContourDirectly}forall
/cornerop corner0 v1 v2 v3 \fcVectorPlusVector \fcVectorPlusVector \fcVectorPlusVector def
\fcLineFormatCode
currentDashes \fcArrayToStack setdash
[v1 v2 v3]
{
newpath
cornerop \fcCoordsIIIdToPS moveto
cornerop exch \fcVectorMinusVector \fcCoordsIIIdToPS lineto
stroke
}forall
end
}

\newcommand{\fcBoxIIIdFilledNew}[5][]{%
\setkeys{fcGraphics}{#1}%
\pscustom{%
\code{%
\fcSetUpGraphicsToScreen %
#2\space #3\space #4\space #5\space[ \fcGetColorCode{\fcColorLine} ] [\fcGetColorCode{\fcColorPatchUV}] true (\fcLineStyle) (dashed) eq [\fcDashes] \fcBoxIIIdFilledCode%
}%
}%
}

\newcommand{\fcBoxIIIdHollowNew}[5][]{%
\setkeys{fcGraphics}{#1}%
\pscustom{%
\code{%
\fcSetUpGraphicsToScreen %
#2\space #3\space #4\space #5\space[ \fcGetColorCode{\fcColorLine} ] [\fcGetColorCode{\fcColorPatchUV}] false (\fcLineStyle) (dashed) eq [\fcDashes] \fcBoxIIIdFilledCode%
}%
}%
}

\newcommand{\fcBoxIIIdFilled}[5][]{%
\pscustom*[#1]{%
\fcPolyLineIIId{4 dict begin%
/visibleCorner #2 def%
/vectorOne #3 #2 \fcVectorMinusVector def%
/vectorTwo #4 #2 \fcVectorMinusVector def%
/vectorThree #5 #2 \fcVectorMinusVector def %
visibleCorner vectorOne \fcVectorPlusVector dup vectorTwo \fcVectorPlusVector dup vectorOne \fcVectorMinusVector dup vectorThree \fcVectorPlusVector dup vectorTwo \fcVectorMinusVector dup vectorOne \fcVectorPlusVector visibleCorner vectorOne \fcVectorPlusVector end %
}%
}%
}

\newcommand{\fcParallelogramIIId}[4][linecolor=cyan!30]{%
\pscustom*[#1]{%
\fcParallelogramHollowIIId{#2}{#3}{#4}%
}%
}

\newcommand{\fcParallelogramHollowIIId}[4][]{ %
\fcPolyLineIIId[#1]{3 dict begin /corner #2 def /vectorOne #3 #2 \fcVectorMinusVector def /vectorTwo #4 #2 \fcVectorMinusVector def corner dup vectorOne \fcVectorPlusVector dup vectorTwo \fcVectorPlusVector dup vectorOne \fcVectorMinusVector corner end
}%
}

\newcommand{\fcParallelogramHalfVisibleIIId}[4][]{%
\pstVerb{3 dict begin /corner #2 def /vectorOne #3 #2 \fcVectorMinusVector def /vectorTwo #4 #2 \fcVectorMinusVector def}%
\fcPolyLineIIId[#1]{corner vectorOne \fcVectorPlusVector corner dup vectorTwo \fcVectorPlusVector}%
\fcPolyLineIIId[#1,linestyle=dashed]{corner vectorOne \fcVectorPlusVector dup vectorTwo \fcVectorPlusVector dup vectorOne \fcVectorMinusVector}%
\pstVerb{end}%
}

\newcommand{\fcPolyLineIIId}[2][linecolor=black]{%
\listplot[#1]{ [#2] {\fcCoordsIIIdToPStricks} \fcSpliceArrayOperation \fcArrayToStack}%
}

%\newcommand{\fcCoordsPStricksToPS}{\fcArrayToStack \fcConvertPSYUnit exch \fcConvertPSXUnit exch\space }
\makeatletter
\newcommand{\fcCoordsPStricksToPS}{\fcArrayToStack \tx@ScreenCoor\space }
\makeatother

\newcommand{\fcLine}[3][]{%
\setkeys{fcGraphics}{#1}
\pscustom{%
\code{%
\fcLineFormatCode
newpath %
#2\space \fcCoordsPStricksToPS moveto %
#3\space \fcCoordsPStricksToPS lineto %
stroke %
}%
}%
}

\newcommand{\fcEllipsoidInScene}[2][iterationsU=22, iterationsV=22]{%
\setkeys{fcGraphics}{#1}%
\pstVerb{%
/theIIIdObjects%
[theIIIdObjects \fcArrayToStack [0 0 180 360%
{ #2\space 6 dict begin%
  /c exch def%
  /b exch def%
  /a exch def%
  /z1 exch def%
  /y1 exch def%
  /x1 exch def%
  [ u sin v cos mul a mul x1 add %
    u sin v sin mul b mul y1 add %
    u cos c mul z1 add%
  ]%
  end%
}%
{true}%
\fcIterationsU\space \fcIterationsV\space %
\fcPatchOptions %
\fcContourOptions %
(surface)%
]%
]%
def%
}%
}

\newcommand{\fcLineFormatCode}{\fcDashesCode \fcLineWidth\space setlinewidth \fcGetColorCode{\fcColorLine} setrgbcolor}

\newcommand{\fcCurveCode}{%
%(calling fcCurveCode) == %
5 dict begin %
%newpath 0 0 moveto 1000 1000 lineto stroke
/theCurve exch def %
%theCurve == %
/tMin exch def%
/tMax exch def%
/Delta tMax tMin sub \fcPlotPoints \space 1 sub div def %
/t tMin def %
\fcLineFormatCode %
newpath %
theCurve \fcCoordsPStricksToPS moveto %
\fcPlotPoints\space 1 sub {/t t Delta add def theCurve \fcCoordsPStricksToPS lineto %
} repeat %
stroke %
end\space%
}

\newcommand{\fcCurve}[4][]{%
\setkeys{fcGraphics}{#1}%
\pstVerb{#2\space #3\space {#4} \space \fcCurveCode}%
}

\newcommand{\fcLineIIId}[3][linecolor=black]{%
\psline[#1](! #2 \space \fcCoordsIIIdToPStricks)(! #3 \space \fcCoordsIIIdToPStricks)%
}

\newcommand{\fcAxesIIIdFull}[4][linecolor=black, arrows=->]{%
\fcAxesIIId[#1]{#2}{#3}{#4}%
\fcLineIIId[#1]{[0 0 0]}{[#2\space -1 mul 0 0]}%
\fcLineIIId[#1]{[0 0 0]}{[0 #3\space -1 mul 0]}%
\fcLineIIId[#1]{[0 0 0]}{[0 0 #4\space -1 mul]}%
} %

\newcommand{\fcAxesIIIdInScene}[4][linecolor=black, arrows=->]{%
\setkeys{fcGraphics}{#1}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[#2 0 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 #3 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 0 #4]}%
\rput[l](! [#2 0 0] \fcCoordsIIIdToPStricks){~\fcXLabel}%
\rput[l](! [0 #3 0] \fcCoordsIIIdToPStricks){~\fcYLabel}%
\rput[r](! [0 0 #4] \fcCoordsIIIdToPStricks){\fcZLabel~}%
}%

\newcommand{\fcAxesIIIdFullInScene}[4][linecolor=black, arrows=->]{%
\setkeys{fcGraphics}{#1}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[#2 0 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 #3 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 0 #4]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[#2\space-1 mul 0 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 #3\space-1 mul 0]}%
\fcLineIIIdInScene[#1]{[0 0 0]}{[0 0 #4\space-1 mul]}%
}

\newcommand{\fcAxesIIId}[4][linecolor=black, arrows=->]{%
\setkeys{fcGraphics}{#1}%
\fcLineIIId[#1]{[0 0 0]}{[#2 0 0]}%
\fcLineIIId[#1]{[0 0 0]}{[0 #3 0]}%
\fcLineIIId[#1]{[0 0 0]}{[0 0 #4]}%
\rput[l](! [#2 0 0] \fcCoordsIIIdToPStricks){~\fcXLabel}%
\rput[l](! [0 #3 0] \fcCoordsIIIdToPStricks){~\fcYLabel}%
\rput[r](! [0 0 #4] \fcCoordsIIIdToPStricks){\fcZLabel~}%
}

\newcommand{\fcDotIIId}[2][linecolor=\fcColorGraph]{%
\pscircle*[#1](! #2 \fcCoordsIIIdToPStricks){0.07} %
} %

\newcommand{\fcPutIIId}[3][]{ \rput[#1](! #2 \fcCoordsIIIdToPStricks) {#3}%
} %

\newcommand{\fcPaintCone}{ %
\fcArrayToStack %
15 dict begin %
/c exch def %
/b exch def %
/a exch def %
/z1 exch def %
/y1 exch def %
/x1 exch def %
/zmax exch def %
/zmin exch def %
}

\newcommand{\fcZBufferRowColumn}{ %
%input: vector on the top of the stack.
%output: row column of point in the z-buffer.
\fcCoordsIIIdToPStricks %
2 dict begin %
/rowIndex exch \space getZBufferYmin sub getZBufferYmax getZBufferYmin sub div zBufferNumRows mul floor cvi def %
/columnIndex exch getZBufferXmin sub getZBufferXmax getZBufferXmin sub div zBufferNumCols mul floor cvi def %
rowIndex zBufferNumRows ge {/rowIndex rowIndex 1 sub def}if %
columnIndex zBufferNumCols ge {/columnIndex columnIndex 1 sub def}if %
rowIndex zBufferNumRows ge {(ERROR: bad row index!!!) == rowIndex ==}if %
columnIndex zBufferNumCols ge {(ERROR: bad column index: ) == columnIndex == }if %
rowIndex 0 lt {/rowIndex rowIndex 1 add def}if %
columnIndex 0 lt {/columnIndex columnIndex 1 add def}if %
rowIndex 0 lt {(ERROR: bad row index!!!) == rowIndex ==}if %
columnIndex 0 lt {(ERROR: bad column index: ) == columnIndex ==  }if %
rowIndex columnIndex %
end %
}

\newcommand{\fcPointIsBehindOrInFrontOfPatch}[1]{ %
%(entering fcPointIsBehindOrInFrontOfPatch) ==
%a patch is assumed to be on the top of the stack
12 dict begin %
/thePatch exch def
/point exch def
thePatch \fcPatchGetInBounds
{
/v0 thePatch \fcPatchGetvZero def %
/v1 thePatch \fcPatchGetvOne def %
/v2 thePatch \fcPatchGetvTwo def %
/v3 thePatch \fcPatchGetvThree def %
/normalLeft v1 v0 \fcVectorMinusVector \fcScreen\space pop \fcVectorCrossVector def %
/normalRight v3 v2 \fcVectorMinusVector \fcScreen\space pop \fcVectorCrossVector def %
/normalBottom v2 v0 \fcVectorMinusVector \fcScreen\space pop \fcVectorCrossVector def %
/normalTop v3 v1 \fcVectorMinusVector \fcScreen\space pop \fcVectorCrossVector def %
/patchNormal v1 v0 \fcVectorMinusVector v2 v0 \fcVectorMinusVector \fcVectorCrossVector def %
point v0 \fcVectorMinusVector normalLeft \fcVectorScalarVector %
v2 point \fcVectorMinusVector normalRight \fcVectorScalarVector %
mul 0 ge { %
point v0 \fcVectorMinusVector normalBottom \fcVectorScalarVector %
v1 point \fcVectorMinusVector normalTop \fcVectorScalarVector %
mul 0 ge %
{ %
point v0 \fcVectorMinusVector patchNormal \fcVectorScalarVector %
\fcScreen\space pop patchNormal \fcVectorScalarVector %
mul #1{0.00001  gt}{-0.00001 lt}ifelse %
{true}{false}ifelse %
}{false}ifelse %
}{false}ifelse %
}{false}ifelse
end %
}

\newcommand{\fcIsInForeground}{ %
15 dict begin %
/theNeighborhood exch def %
/thePoint theNeighborhood 0 get def %
%(neighborhood: ) print
%theNeighborhood ==
%(thePoint:) print
%thePoint ==
thePoint \fcZBufferRowColumn %
/column exch def %
/row exch def %
/theZBuffEntry theZBuffer row get column get def %
/result true def %
/counterZBuff -1 def %
theZBuffEntry length { %
/counterZBuff counterZBuff 1 add def %
/theZbuffPatchIndex theZBuffEntry counterZBuff get def %
/theZbuffPatch thePatchCollection theZbuffPatchIndex get def %
theZbuffPatchIndex theNeighborhood \fcContains not{ %
%(patch) == theZbuffPatch == (is not contained in neighborhood ) ==
%theNeighborhood ==
thePoint theZbuffPatch \fcPointIsBehindOrInFrontOfPatch{true}
{/result false def
exit
}
{ %(point is in front of patch) ==
}
ifelse
}
{ %(patch coincides with zbuff patch) ==
}
ifelse %
}repeat %
result %
end %
}

\newcommand{\fcZBufferBoundingBoxPatch}{ %
5 dict begin %
/thePatch exch def
/v3 thePatch \fcPatchGetvThree def %
/v2 thePatch \fcPatchGetvTwo def %
/v1 thePatch \fcPatchGetvOne def %
/v0 thePatch \fcPatchGetvZero def %
v0 \fcZBufferBoundingBoxPoint %
v1 \fcZBufferBoundingBoxPoint %
v2 \fcZBufferBoundingBoxPoint %
v3 \fcZBufferBoundingBoxPoint %
v1 v2 \fcVectorPlusVector v0 \fcVectorMinusVector \fcZBufferBoundingBoxPoint %
end %
}

\newcommand{\fcZBufferBoundingBoxPoint}{ %
%Account bounding box:
\fcCoordsIIIdToPStricks %
dup dup getZBufferYmin lt {setZBufferYmin}{pop}ifelse %
dup getZBufferYmax gt {setZBufferYmax}{pop}ifelse %
dup dup getZBufferXmin lt {setZBufferXmin}{pop}ifelse %
dup getZBufferXmax gt {setZBufferXmax}{pop}ifelse \space%
}

\newcommand{\fcZBufferEllipsoid}{ %
%(calling fcZBufferEllipsoid with input: ) == dup == %
\fcArrayToStack
6 dict begin
/c exch def %
/b exch def %
/a exch def %
/z1 exch def %
/y1 exch def %
/x1 exch def %
[a -1 mul x1 add b -1 mul y1 add c -1 mul z1 add a x1 add b y1 add c z1 add] %
end
}

\newcommand{\fcSegmentBoundingBox}{ %
\fcZBufferBoundingBoxPoint %
\fcZBufferBoundingBoxPoint %
}

\newcommand{\fcZBufferPaintCellContainingPoint}{
10 dict begin
/thePoint exch def
thePoint \fcZBufferRowColumn
/column exch def
/row exch def
\fcZBufferComputeDeltaXDeltaY
/lowerLeftX getZBufferXmin DeltaX column mul add def
/lowerLeftY getZBufferYmin DeltaY row mul add def
gsave
0.6 0.6 1 setrgbcolor
newpath
[lowerLeftX lowerLeftY] \fcCoordsPStricksToPS moveto
[lowerLeftX DeltaX add lowerLeftY] \fcCoordsPStricksToPS lineto
[lowerLeftX DeltaX add lowerLeftY DeltaY add] \fcCoordsPStricksToPS lineto
[lowerLeftX lowerLeftY DeltaY add] \fcCoordsPStricksToPS lineto
[lowerLeftX lowerLeftY] \fcCoordsPStricksToPS lineto
stroke
grestore
end
}

\newcommand{\fcZBufferComputeDeltaXDeltaY}{
/DeltaX getZBufferXmax getZBufferXmin sub zBufferNumCols div def %
/DeltaY getZBufferYmax getZBufferYmin sub zBufferNumRows div def %
}

\newcommand{\fcPaintZbuffForDebug}{ %
6 dict begin %
\fcZBufferComputeDeltaXDeltaY
gsave %
0.1 setlinewidth %
/x getZBufferXmin def %
0.5 0.5 0.5 setrgbcolor %
zBufferNumRows {newpath [x getZBufferYmin] \fcCoordsPStricksToPS moveto [x getZBufferYmax] \fcCoordsPStricksToPS lineto stroke /x x DeltaX add def}repeat %
/y getZBufferYmin def %
zBufferNumCols { newpath [getZBufferXmin y] \fcCoordsPStricksToPS moveto [getZBufferXmax y] \fcCoordsPStricksToPS lineto stroke /y y DeltaY add def}repeat %
/y getZBufferYmin DeltaY 2 div add def %
/counterY 0 def %
zBufferNumRows { %
/x getZBufferXmin DeltaX 2 div add def %
/counterX 0 def %
zBufferNumCols { %
theZBuffer counterY get counterX get length 0 gt{ %
[x y] \fcFullDotCode %
} if %
/x x DeltaX add def %
/counterX counterX 1 add def %
}repeat %
/y y DeltaY add def %
/counterY counterY 1 add def %
}repeat %
grestore %
end %
}

\newcommand{\fcStartIIIdScene}{%
\pstVerb{1 dict begin /theIIIdObjects [] def}%
}%

\newcommand{\fcZBufferPrint}{ %
(printing Zbuffer...) == %
getZBufferXmin == %
getZBufferXmax == %
getZBufferYmin == %
getZBufferYmax == %
theZBuffer == %
}

\newcommand{\fcZBufferLoad}{ %
\fcZBufferInitialize %
/theZBuffer exch def %
setZBufferYmax %
setZBufferYmin %
setZBufferXmax %
setZBufferXmin %
}

\newcommand{\fcZBufferInitialize}{ %
/ZBufferRectangle [0 0 0 0] def %
/setZBufferXmin {ZBufferRectangle exch 0 exch put} def %
/setZBufferYmin {ZBufferRectangle exch 1 exch put} def %
/setZBufferXmax {ZBufferRectangle exch 2 exch put} def %
/setZBufferYmax {ZBufferRectangle exch 3 exch put} def %
/getZBufferXmin {ZBufferRectangle 0 get} def %
/getZBufferYmin {ZBufferRectangle 1 get} def %
/getZBufferXmax {ZBufferRectangle 2 get} def %
/getZBufferYmax {ZBufferRectangle 3 get} def %
/zBufferNumCols \fcZBufferNumXIntervals\space def
/zBufferNumRows \fcZBufferNumYIntervals\space def
thePatchCollection length zBufferNumCols zBufferNumRows mul lt
{ /zBufferNumCols thePatchCollection length sqrt round cvi def
  zBufferNumCols 3 lt {/zBufferNumCols 3 def}if
  /zBufferNumRows zBufferNumCols def
  (There are only a few patches in the scene, I decreased z-buffer size to ) print zBufferNumCols == (rows and columns. ) print
}if
/getZBufferDeltaX {getZBufferXmax getZBufferXmin sub zBufferNumCols div} def %
/getZBufferDeltaY {getZBufferYmax getZBufferYmin sub zBufferNumRows div} def %
/theZBuffer [zBufferNumRows {[zBufferNumCols{[]} repeat]}repeat] def %
}

\newcommand{\fcPaintCachedFile}{
graphicsFile run
}

\newcommand{\fcSetUpGraphicsToScreen}{
/movetoVirtual {moveto} def
/linetoVirtual {lineto} def
/strokeVirtual {stroke} def
/closepathVirtual {closepath} def
/newpathVirtual {newpath} def
/fillVirtual {fill} def
/arrowVirtual {} def
/setrgbcolorVirtual {setrgbcolor} def
/setlinewidthVirtual {setlinewidth} def
/plotArrowHeadVirtual {\fcArrowHeadPlotCode} def
/setdashVirtual {setdash} def
}

\newcommand{\fcSetUpGraphicsToFileAndScreen}{
graphicsFile ( /plotArrowHeadVirtual {\fcArrowHeadPlotCode} def ) writestring
/storeNumberPairToGraphicsFile{
\fcMarkClean 3 1 roll
20 string cvs exch 20 string cvs graphicsFile exch writestring graphicsFile ( ) writestring graphicsFile exch writestring graphicsFile ( ) writestring
\fcMarkCleanCheck
} def
/movetoVirtual {
2 copy moveto
storeNumberPairToGraphicsFile
graphicsFile (moveto ) writestring
} def
/setlinewidthVirtual {
dup setlinewidth
20 string cvs graphicsFile exch writestring graphicsFile ( setlinewidth ) writestring
} def
/linetoVirtual {
2 copy lineto
storeNumberPairToGraphicsFile
graphicsFile (lineto ) writestring
} def
/strokeVirtual {
stroke
graphicsFile (stroke ) writestring
} def
/newpathVirtual {
newpath
graphicsFile (newpath ) writestring
} def
/closepathVirtual {
closepath
graphicsFile ( closepath ) writestring
} def
/fillVirtual {
fill
graphicsFile ( fill ) writestring
} def
/setrgbcolorVirtual {
3 copy
setrgbcolor
graphicsFile 4 -1 roll \fcToString writestring graphicsFile ( ) writestring
graphicsFile 3 -1 roll \fcToString writestring graphicsFile ( ) writestring
graphicsFile exch \fcToString writestring
graphicsFile ( setrgbcolor ) writestring
} def
/setdashVirtual {
2 copy setdash
20 string cvs exch \fcToString graphicsFile exch writestring graphicsFile ( ) writestring graphicsFile exch writestring graphicsFile ( setdash ) writestring
} def
/plotArrowHeadVirtual {
2 copy \fcArrowHeadPlotCode\space
\fcToString exch \fcToString graphicsFile exch writestring graphicsFile ( ) writestring graphicsFile exch writestring graphicsFile ( plotArrowHeadVirtual ) writestring
}def
}

\newcommand{\fcSetupFiles}{
\fcSetUpGraphicsToScreen
/graphicsCached false def
/graphicsFileAvailable true def
/graphicsFileName (graphicsCacheSafeToDelete) (\fcScreen) [[1 0] \fcCoordsPStricksToPS] \fcToString [[0 1] \fcCoordsPStricksToPS] \fcToString 6 -1 roll \fcToString \fcHashString (.txt) 6 \fcConcatenateMultiple def
/graphicsFile (file not open) def
errordict begin
/invalidfileaccess
{ userdict begin /graphicsFileAvailable false def end
(ERROR: failed to open file for caching large IIId rendering operations. ) print
(This is not fatal but will cause your graphics to compile incredibly slowly. ) print
(To fix this, compile with pdflatex --shell-escape. ) print
(Make sure the file is executed in a folder with write priviledges. \string\n) print
pop pop
} def
/undefinedfilename{
(File doesn't exist. ) print
 pop pop
} def
end
(Opening file ) print graphicsFileName print (. ) print
/graphicsFile graphicsFileName (r) file def
graphicsFile type (filetype) eq {
/graphicsCached true def
\fcPaintCachedFile
graphicsFile closefile
}
{ /graphicsFile graphicsFileName (w) file def
  graphicsFile type (filetype) ne{
  /graphicsFileAvailable false def
  }
  { \fcSetUpGraphicsToFileAndScreen
  }
  ifelse
}ifelse
}

\newcommand{\fcComputePatchesAndContours}{
/totalNumPatches 0 def
/totalNumContours 0 def
\fcMarkClean
theIIIdObjects {\fcObjectGetNumPatches /totalNumPatches exch totalNumPatches add def} forall
\fcMarkCleanCheck
\fcMarkClean
theIIIdObjects {\fcObjectGetNumContours /totalNumContours exch totalNumContours add def} forall
\fcMarkCleanCheck
/thePatchCollection [totalNumPatches {(empty)}repeat] def
/theContourCollection [totalNumContours{(empty)} repeat] def
(\string\n) print (Expected number of patches, contours: ) print
thePatchCollection length 20 string cvs print (, ) print
theContourCollection length 20 string cvs print
(. Computing patches and contours ...) print
/numPatchesComputedSoFar 0 def
/numContoursComputedSoFar 0 def
/counter -1 def
theIIIdObjects length {
/counter counter 1 add def
theIIIdObjects counter get \fcObjectComputePatchesAndContours
theIIIdObjects counter get \fcObjectGetNumPatches
/numPatchesComputedSoFar exch numPatchesComputedSoFar add def
theIIIdObjects counter get \fcObjectGetNumContours
/numContoursComputedSoFar exch numContoursComputedSoFar add def
} repeat
thePatchCollection{(empty) eq {(ERROR: declared patch not computed!)}if }forall
theContourCollection{(empty) eq {(ERROR: declared contour not computed!)}if }forall
(... computing patches and contours done!\string\n) print
}

\newcommand{\fcPaintPatches}{
thePatchIndices {\fcPaintPatchIndexFilledDirectly} forall
}

\newcommand{\fcPaintPatchLabels}{
/counter -1 def
0 0 0 setrgbcolorVirtual
thePatchCollection length
{/counter counter 1 add def
counter thePatchCollection counter get \fcPatchPaintLabel
}repeat
}

\newcommand{\fcPaintPatchSortOrder}{
/counter -1 def
0 0 0 setrgbcolorVirtual
thePatchIndices length
{/counter counter 1 add def
counter thePatchCollection thePatchIndices counter get get \fcPatchPaintLabel
}repeat
}

\newcommand{\fcPaintContours}{
theContourCollection{\fcPaintContour} forall %
}

\newcommand{\fcProcessCurrentZBuffer}{
/counterI -1 def
%(currentZBuffer is: ) ==
%currentZBuffer ==
currentZBuffer length {
/counterI counterI 1 add def
/counterJ -1 def
currentZBuffer length{
/counterJ counterJ 1 add def
counterI counterJ ne{
/leftIndex currentZBuffer counterI get def
/rightIndex currentZBuffer counterJ get def
rightIndex leftIndex \fcLeftPatchIsBehind {
rightIndex thePatchIncidenceGraph leftIndex get \fcContains not {
thePatchIncidenceGraph leftIndex
[ thePatchIncidenceGraph leftIndex get \fcArrayToStack rightIndex
]
put
}if
}if
}if
}repeat
}repeat
}

\newcommand{\fcComputePatchOrder}{
/thePatchIncidenceGraph [thePatchCollection length {[]}repeat] def
/rowCounter -1 def
(computing patch order... ) print
(processing z-buffer row, column:) print
theZBuffer length {
/rowCounter rowCounter 1 add def
/columnCounter -1 def
theZBuffer rowCounter get length {
/columnCounter columnCounter 1 add def
/currentZBuffer theZBuffer rowCounter get columnCounter get def
% % % % %
(\string\n) print rowCounter == columnCounter ==
(out of: ) print theZBuffer length == theZBuffer rowCounter get length ==
% % % % %
\fcProcessCurrentZBuffer
}repeat
}repeat
(... computing patch order done ) print
}

\newcommand{\fcSortPatchIndices}{
(sorting a total of ) print thePatchCollection length == ( patches... ) print
fastPatchSort
{ (\string\n Sorting patches by their z-depth. This may be inaccurate but is fast. ) print
  /counter -1 def
  /thePatchIndices [thePatchCollection length {/counter counter 1 add def counter} repeat] def
  20 dict begin
  /LeftGreaterThanRight
  { 4 dict begin
  	/rightPatch exch thePatchCollection exch get def
  	/leftPatch  exch thePatchCollection exch get def
    rightPatch \fcPatchGetForcedForegroundStatus leftPatch \fcPatchGetForcedForegroundStatus not and {true}{
    leftPatch \fcPatchGetForcedForegroundStatus rightPatch \fcPatchGetForcedForegroundStatus not and
    {false}{
  	leftPatch  \fcPatchGetPoint \fcScreen\space pop \fcVectorScalarVector
  	rightPatch \fcPatchGetPoint \fcScreen\space pop \fcVectorScalarVector
  	lt
  	}ifelse}ifelse
    end
  } def
  thePatchIndices \fcMergeSort
  end
  /thePatchIndices exch def
  (\string\n Sorting patches done. ) print
}
{
(\string\n Sorting patches via the partial order induced by their visibility. This is slow but somewhat accurate. ) print
%thePatchIncidenceGraph shall have one entry for each patch.
%The entry will consist of a list of all patch indices of
%patches that are behind our patch.
/thePatchIndices [thePatchCollection length {(empty)} repeat] def
20 dict begin
\fcComputePatchOrder
(patch incidence graph:) ==
thePatchIncidenceGraph ==
/accountPatch {
  /patchIndex exch def
  (accounting patch: ) print
  patchIndex ==
  /numAccountedLastCycle numAccountedLastCycle 1 add def
  accountedPatches patchIndex true put
  thePatchIndices numAccountedSoFar patchIndex put
  /numAccountedSoFar numAccountedSoFar 1 add def
} def
/accountedPatches [thePatchCollection length {false} repeat] def
/numAccountedSoFar 0 def
{
/numAccountedLastCycle 0 def
/patchIndex -1 def
thePatchIncidenceGraph length {
/patchIndex patchIndex 1 add def
accountedPatches patchIndex get not
{/patchIsNext true def
/patchBehindIndex -1 def
/patchesBehindCurrent thePatchIncidenceGraph patchIndex get def
patchesBehindCurrent length{
/patchBehindIndex patchBehindIndex 1 add def
accountedPatches patchesBehindCurrent patchBehindIndex get get not{
/patchIsNext false def exit
}if
}repeat
patchIsNext{
patchIndex accountPatch
}if
}if
}repeat
numAccountedLastCycle 0 eq{
(We have cyclically overlapping patches!) ==
/patchIndex -1 def
thePatchIncidenceGraph length {
/patchIndex patchIndex 1 add def
accountedPatches patchIndex get not
{ patchIndex accountPatch exit
}if
}repeat
}if
numAccountedSoFar thePatchIndices length eq{exit} if
}loop
(sorting patches done) print
%thePatchIndices ==
%(thePatchCollection: ) ==
%thePatchCollection ==
end
}ifelse
}

\newcommand{\fcFinishIIIdScene}[1][fastsort=false]{%
\setkeys{fcGraphics}{#1}%
\pscustom{%
\code{%
%print the objects we are about to paint:
theIIIdObjects length 0 gt { %
%(about to process IIId scene given by: ) print %
%theIIIdObjects == %
} if %
60 dict begin %
theIIIdObjects \fcSetupFiles
graphicsCached not{
/fastPatchSort \fcFastPatchSort\space def
% % % % % % % % % % % % % % % % % % %
\fcComputePatchesAndContours
% % % % % % % % % % % % % % % % % % %
\fcZBufferInitialize %
(computing bounding box IIId scene... ) print %
theContourCollection {\fcZBufferBoundingBoxPatchContour} forall
thePatchCollection {\fcZBufferBoundingBoxPatch} forall
%extend slightly the bounding box to take care of floating point errors at the
%border
getZBufferXmin 0.1 sub setZBufferXmin %
getZBufferXmax 0.1 add setZBufferXmax %
getZBufferYmin 0.1 sub setZBufferYmin %
getZBufferYmax 0.1 add setZBufferYmax %
(bounding box computed: ) == ZBufferRectangle == %
% % % % % % % % % % % % % % % % % % % % % % % % % %
(computing z-buffer IIId scene... ) print %
/counter -1 def
thePatchCollection length { /counter counter 1 add def counter \fcZBufferPatchIndex} repeat %
(z buffer computed.) print %
% % % % % % % % % % % % % % % % % % % % % % % % % %
\fcSortPatchIndices
\fcPaintPatches
\fcPaintContours
%\fcPaintPatchSortOrder
%\fcPaintPatchLabels
%[
%thePatchCollection { \fcPatchGetPoint \fcScreen \space pop \fcVectorScalarVector } forall
%] ==
% % % % % %
%(z buffer sorted) print %
% % % % % % % % % % % % % % % % % % % % % % % % % %
%\fcZBufferPrint %
%(painting patches) ==
%\fcZBufferPaintPatches
% %
%\fcPaintZbuffForDebug %
% %
end %
(done, printing stack to make sure no trash is left) == %
pstack %
} %if graphics is not cached
if
}%
}%
\pstVerb{end}%
}%

\newcommand{\fcObjectGetNumContours}{%
\fcArrayToStack %
1 dict begin %
/HandlerNotFound true def %
HandlerNotFound{dup (surface) eq {pop \fcSurfaceGetNumContours /HandlerNotFound false def} if} if %
HandlerNotFound{dup (curve) eq {pop \fcCurveInit 1 /HandlerNotFound false def} if} if %
HandlerNotFound{dup (triangle) eq {pop \fcTriangleInSceneInit 1 /HandlerNotFound false def} if} if %
HandlerNotFound{== (ERROR: OBJECT GET NUMBER OF CONTOURS HANDLER NOT FOUND)} if %
end %
}%

\newcommand{\fcObjectGetNumPatches}{%
\fcArrayToStack %
1 dict begin %
/HandlerNotFound true def %
HandlerNotFound{dup (surface) eq {pop \fcSurfaceGetNumPatches /HandlerNotFound false def} if} if %
HandlerNotFound{dup (curve) eq {pop \fcCurveInit 0 /HandlerNotFound false def} if} if %
HandlerNotFound{dup (triangle) eq {pop \fcTriangleInSceneInit 1 /HandlerNotFound false def} if} if %
HandlerNotFound{== (ERROR: OBJECT NUMBER OF PATCHES HANDLER NOT FOUND)} if %
end %
}%

\newcommand{\fcObjectComputePatchesAndContours}{%
\fcMarkClean exch
\fcArrayToStack %
1 dict begin %
/HandlerNotFound true def %
HandlerNotFound{dup (surface) eq {pop \fcSurfaceComputePatchesAndContours /HandlerNotFound false def} if} if %
HandlerNotFound{dup (curve) eq {pop \fcCurveComputeContour /HandlerNotFound false def} if} if %
HandlerNotFound{dup (triangle) eq {pop \fcTriangleComputePatchesAndContours /HandlerNotFound false def} if} if %
HandlerNotFound{== (ERROR: OBJECT PATCH-CONTOUR HANDLER NOT FOUND)} if %
end %
\fcMarkCleanCheck
}%

\newcommand{\fcZBufferBoundingBoxPatchContour}{ %
2 dict begin %
/theContour exch def %
/counter -1 def %
theContour length 1 sub { /counter counter 1 add def theContour counter get 0 get \fcZBufferBoundingBoxPoint}repeat %
end %
}

\newcommand{\fcPaintPointForegroundData}{
20 dict begin %
gsave
/theNeighborhood exch def %
/thePoint theNeighborhood 0 get def %
(theNeighborhood:)==
theNeighborhood ==
thePoint \fcZBufferRowColumn
/column exch def
/row exch def
/theZBufferCurrent theZBuffer row get column get def
/counter 0 def
/numPatchesInNeighborhood 0 def %
theNeighborhood length 1 sub {
/counter counter 1 add def
1.8 setlinewidth
0.5 1 0.5 setrgbcolor
theNeighborhood counter get theZBufferCurrent \fcContains not
{3 setlinewidth 1 0 0 setrgbcolor
}if
theNeighborhood counter get \fcPatchPaintContourDirectly
theNeighborhood counter get type (arraytype) eq
{/numPatchesInNeighborhood numPatchesInNeighborhood 1 add def}if
}repeat
/counter -1 def
theZBufferCurrent length {
/counter counter 1 add def %
1.1 setlinewidth
1 0.7 0.7 setrgbcolor
thePoint thePatchCollection theZBufferCurrent counter get get \fcPointIsBehindOrInFrontOfPatch{true}
{1 0 0 setrgbcolor
}if
thePatchCollection theZBufferCurrent counter get get \fcPatchPaintContourDirectly
}repeat
thePoint \fcZBufferPaintCellContainingPoint %
[thePoint \fcCoordsIIIdToPStricks] theNeighborhood \fcIsInForeground
{\fcFullDotCode}{\fcHollowDotCode}ifelse %
0 0 0 setrgbcolor
(nsize: ) numPatchesInNeighborhood 20 string cvs \fcConcatenate [thePoint \fcCoordsIIIdToPStricks ] \fcTextCode
(bsize: ) theZBufferCurrent length 20 string cvs \fcConcatenate [thePoint \fcCoordsIIIdToPStricks 0.2 sub ] \fcTextCode
grestore
end
}

\newcommand{\fcZBufferRowColumnIsInvestigated}{
\fcZBufferRowColumnsUnderInvestigation\space column eq exch row eq and
}

\newcommand{\fcArrowHeadAndTailPlotCode}{
2 copy 
10 dict begin
/pointRight exch def
/pointLeft exch def
newpath %
pointLeft \fcCoordsPStricksToPS moveto %
pointRight \fcCoordsPStricksToPS lineto %
stroke %
end
\fcArrowHeadPlotCode
}

\makeatletter
\newcommand{\fcArrowHeadPlotCode}{
10 dict begin
/pointRight exch [ exch \fcCoordsPStricksToPS ] def
/pointLeft  exch [ exch \fcCoordsPStricksToPS ] def
 gsave
/directionVector [pointRight pointLeft \fcVectorMinusVector \fcArrayToStack] def
directionVector \fcVectorNorm 0 ne{
/directionVector directionVector \fcVectorNormalize def
}if
/xPS directionVector 0 get def
/yPS directionVector 1 get def
[yPS  xPS -1 mul  -1 xPS mul -1 yPS mul pointRight \fcArrayToStack] concat
%[1 0 0 1  pointRight 0 get \fcCoordsIIIdToPS ] concat
 newpath
 false 0.4 1.5 0.4 0.5 \tx@Arrow
 closepath
 stroke
 grestore
end
}
\makeatother

\newcommand{\fcPointOnContourGetVisibility}{
dup length 1 sub get\space
}

\newcommand{\fcContourGetUseArrows}{dup length 1 sub get 0 get\space}
\newcommand{\fcContourGetColor}    {dup length 1 sub get 1 get\space}
\newcommand{\fcContourGetWidth}    {dup length 1 sub get 2 get\space}
\newcommand{\fcContourGetDashes}   {dup length 1 sub get 3 get\space}
\newcommand{\fcContourGetLineStyle}{dup length 1 sub get 4 get\space}

\newcommand{\fcPaintContour}{ %
20 dict begin %
/theContour exch def %
theContour \fcContourGetLineStyle (none) ne{
/numSegments theContour length 2 sub def %
/counter -1 def %
/rightIsInForeground theContour 0 get \fcIsInForeground def %
/style (none) def %
/useArrows theContour \fcContourGetUseArrows def
/currentDashes {theContour \fcContourGetDashes \fcArrayToStack} def
theContour \fcContourGetWidth setlinewidthVirtual
theContour \fcContourGetColor \fcArrayToStack setrgbcolorVirtual
numSegments{ %
  /counter counter 1 add def %
  /pointLeft theContour counter get def %
  /pointRight theContour counter 1 add get def %
  /leftIsInForeground rightIsInForeground def %
  /rightIsInForeground pointRight \fcIsInForeground def %
  /leftIsVisible pointLeft \fcPointOnContourGetVisibility def %
  /rightIsVisible pointRight \fcPointOnContourGetVisibility def %
  /oldStyle style def %
  /style leftIsInForeground rightIsInForeground or {(normal)}{(dashed)}ifelse def %
  /setStyle {style (normal) eq{[] 0 setdashVirtual}{currentDashes setdashVirtual}ifelse } def
  leftIsVisible rightIsVisible and{
	counter 0 eq{newpathVirtual}if
    style oldStyle ne{strokeVirtual setStyle %
    newpathVirtual pointLeft 0 get \fcCoordsIIIdToPS movetoVirtual %
    }if %
    pointRight 0 get \fcCoordsIIIdToPS linetoVirtual
  }if
  leftIsVisible rightIsVisible not and{
    strokeVirtual
    /style (invisible) def
  }if
  leftIsVisible not rightIsVisible and{
    setStyle
    newpathVirtual pointRight 0 get \fcCoordsIIIdToPS movetoVirtual %
  }if
}repeat %
strokeVirtual %
useArrows{[] 0 setdashVirtual [pointLeft 0 get \fcCoordsIIIdToPStricks] [pointRight 0 get \fcCoordsIIIdToPStricks] plotArrowHeadVirtual}if %
}if %
end %
}

\newcommand{\fcCurveInit}{
/contourOptions exch def
/theCurve exch def %
/tMax exch def %
/tMin exch def %
/tIterations \fcPlotPoints\space def %
}

\newcommand{\fcCurveComputeContour}{
30 dict begin %
\fcCurveInit
/DeltaT tMax tMin sub tIterations div def %
/t tMin def %
theContourCollection numContoursComputedSoFar
[
tIterations { %
[theCurve true]
/t t DeltaT add def %
}repeat %
contourOptions
]
put
end %
}

\newcommand{\fcComputeSurfacePatch}{
/oldU u def %
/oldV v def %
/inBounds true def
[ %start of patch data structure
theSurface %(x(u,v), y(u,v), z(u,v))
theRestrictions not {/inBounds false def}if
/u u DeltaU add def %
theSurface %(x(u+Delta,v), y(u+Delta,v), z(u+Delta,v))
theRestrictions not {/inBounds false def}if
/u oldU def %
/v v DeltaV add def %
theSurface %(x(u,v+Delta), y(u,v+Delta), z(u,v+Delta))
theRestrictions not {/inBounds false def}if
/u u DeltaU add def %
theSurface %(x(u+Delta,v+Delta), y(u+Delta,v+Delta), z(u+Delta,v+Delta))
theRestrictions not {/inBounds false def}if
[
/u oldU def
/v oldV def
numContourUSegmentsPerPatch {theRestrictions{theSurface}if /u u DeltaDeltaU add def} repeat
/u oldU DeltaU add def
/v oldV def
numContourVSegmentsPerPatch {theRestrictions{theSurface}if /v v DeltaDeltaV add def} repeat
/v oldV DeltaV add def
numContourVSegmentsPerPatch {theRestrictions{theSurface}if /u u DeltaDeltaU sub def} repeat
/u oldU def
numContourVSegmentsPerPatch {theRestrictions{theSurface}if /v v DeltaDeltaV sub def} repeat
]
[colorUVpatch % front color of patch
colorVUpatch % back color of patch
forceForeground %
inBounds %
colorVUpatch %patch built-in contour color, used when drawing patch contour directly
false %is contour dashed independent of visibility?
[] %dashes not used
]
(patch) %
] %patch data structure complete
/u oldU def %
/v oldV def %
}

\newcommand{\fcSurfaceGetNumContours}{
30 dict begin
\fcSurfaceInit %
uIterations 1 add vIterations 1 add add
end
}

\newcommand{\fcSurfaceGetNumPatches}{
30 dict begin
\fcSurfaceInit %
uIterations vIterations mul
end
}

\newcommand{\fcSurfaceInit}{%
/contourOptions exch def%
/patchOptions exch def%
/forceForeground patchOptions 2 get def%
/colorUVpatch patchOptions 0 get def%
/colorVUpatch patchOptions 1 get def%
/vIterations exch def %
/uIterations exch def %
/theRestrictions exch def
/theSurface exch def %
/vMax exch def %
/uMax exch def %
/vMin exch def %
/uMin exch def %
}

\newcommand{\fcSurfaceComputePatchesAndContours}{%
30 dict begin %
{ %begin loop, used to simulate a jump instruction
%exiting the loop = jumping at loop end
\fcSurfaceInit
/u uMin def
/v vMin def
mark
theSurface type (arraytype) ne {(\string\n ERROR: surface must be an array. \string\n) print cleartomark exit}if cleartomark
\fcMarkClean
/DeltaU uMax uMin sub uIterations div def %
/DeltaV vMax vMin sub vIterations div def %
/getPatchIndex {exch vIterations mul add numPatchesComputedSoFar add} def
/accountPatch {getPatchIndex dup thePatchCollection exch get (empty) eq {thePatchCollection exch 3 -1 roll put}{pop pop}ifelse
} def
/numContourVSegmentsPerPatch \fcNumCountourSegmentsPatchV \space def
/numContourUSegmentsPerPatch \fcNumCountourSegmentsPatchU \space def
/DeltaDeltaV DeltaV numContourVSegmentsPerPatch div def %
/DeltaDeltaU DeltaU numContourUSegmentsPerPatch div def %
% % % % % % % % % % % % % % % % % % % % %
%process uv-contours
/u uMin def %
/counterU -1 def %
uIterations 1 add{ %
/counterU counterU 1 add def %
/counterV -1 def %
/v vMin def %
/patchLeftIndex (empty) def %
/patchRightIndex (empty) def %
[
vIterations { %
/counterV counterV 1 add def
/patchLeftBackIndex patchLeftIndex def %
/patchRightBackIndex patchRightIndex def %
/patchLeftIndex counterU uIterations lt
{\fcComputeSurfacePatch counterU counterV accountPatch counterU counterV getPatchIndex}
{(empty)}
ifelse def %
/patchRightIndex counterU 0 ne {counterU 1 sub counterV getPatchIndex}
{(empty)} ifelse def %
/vOld v def %
[theSurface patchLeftIndex patchRightIndex patchLeftBackIndex patchRightBackIndex theRestrictions]
numContourUSegmentsPerPatch 1 sub{/v v DeltaDeltaV add def [theSurface patchLeftIndex patchRightIndex theRestrictions]} repeat
/v vOld DeltaV add def %
}repeat %
[theSurface patchLeftIndex patchRightIndex theRestrictions]
contourOptions
]
/thePatchContour exch def %
%/contourIsUnderInvestigation \fcZBufferVparameterPointUnderInvestigation\space pop counterU eq def
%/indexPointUnderInvestigation
%\fcZBufferVparameterPointUnderInvestigation\space exch pop def
theContourCollection counterU numContoursComputedSoFar add thePatchContour put
/uOld u def %
/u u DeltaU add def %
} repeat %
% % % % % % % % % % % % % % % % % % % % %
%process vu-contours
/v vMin def %
/counterV -1 def %
vIterations 1 add{ %
  /counterV counterV 1 add def %
  /counterU -1 def
  /u uMin def %
  /patchLeftIndex (empty) def %
  /patchRightIndex (empty) def %
  [
  uIterations { %
  /counterU counterU 1 add def
  /patchLeftBackIndex patchLeftIndex def %
  /patchRightBackIndex patchRightIndex def %
  /patchLeftIndex counterV vIterations lt
  {counterU counterV getPatchIndex}
  {(empty)}
  ifelse
  def %
  /patchRightIndex counterV 0 ne {counterU counterV 1 sub getPatchIndex} {(empty)} ifelse def %
  /uOld u def %
  [theSurface patchLeftIndex patchRightIndex patchLeftBackIndex patchRightBackIndex theRestrictions]
  numContourVSegmentsPerPatch 1 sub{/u u DeltaDeltaU add def [theSurface patchLeftIndex patchRightIndex theRestrictions]} repeat
  /u uOld DeltaU add def %
  }repeat %
  [theSurface patchLeftIndex patchRightIndex theRestrictions]
  contourOptions
  ]
  /thePatchContour exch def %
  %/contourIsUnderInvestigation \fcZBufferUparameterPointUnderInvestigation\space pop counterV  eq def
  %/indexPointUnderInvestigation
  %\fcZBufferUparameterPointUnderInvestigation\space exch pop def
  theContourCollection uIterations 1 add counterV add numContoursComputedSoFar add thePatchContour put
  /vOld v def %
  /v v DeltaV add def %
} repeat %
\fcMarkCleanCheck
exit
}loop %this loop is used to simulate a jump instruction
end %
}%

\newcommand{\fcGetColorCode}[1]{%
2 dict begin%
/theColor {0 0 0} def%
/colorNotFound true def%
(#1) (black) eq (#1) (black ) eq or{/theColor {0 0 0} def /colorNotFound false def}if%
(#1) (white) eq (#1) (white ) eq or{/theColor {1 1 1} def /colorNotFound false def}if%
(#1) (red) eq (#1) (red ) eq or{/theColor {1 0 0} def /colorNotFound false def}if%
(#1) (blue) eq (#1) (blue ) eq or{/theColor {0 0 1} def /colorNotFound false def}if%
(#1) (green) eq (#1) (green ) eq or{/theColor {0 1 0} def /colorNotFound false def}if%
(#1) (brown) eq (#1) (brown ) eq or{/theColor {0.6484375 0.1640625 0.1640625} def /colorNotFound false def}if%
(#1) (orange) eq (#1) (orange ) eq or{/theColor {1 0.647058824 0} def /colorNotFound false def}if%
(#1) (cyan) eq (#1) (cyan ) eq or {/theColor {0 1 1} def /colorNotFound false def}if %
(#1) (pink) eq (#1) (pink ) eq or {/theColor {1 0.75390625 0.796875} def /colorNotFound false def}if %
(#1) (gray) eq (#1) (gray ) eq or {/theColor {0.5 0.5 0.5} def /colorNotFound false def}if %
colorNotFound{/theColor {#1} def}if %
theColor %
end%
}%

\newcommand{\fcLineIIIdInScene}[3][arrows=,]{%
\fcCurveIIIdInScene[#1]{0}{1}{#3 t \fcVectorTimesScalar #2 1 t sub \fcVectorTimesScalar \fcVectorPlusVector}%
}

%Format of curve: we store the curve in the format [tmin tmax [x y z] arrows red green blue (curve)]
\newcommand{\fcCurveIIIdInScene}[4][]{%
\setkeys{fcGraphics}{#1}%
\pstVerb{%
[theIIIdObjects \fcArrayToStack [#2\space #3{#4} \fcContourOptions (curve)] ]/theIIIdObjects exch def}%
}%

\newcommand{\fcSegmentCodeNoFirstPoint}{
5 dict begin
/right exch def
/left exch def
/Delta 1 \fcNumCountourSegmentsPatchU div def
/t Delta def
\fcNumCountourSegmentsPatchU {left 1 t sub \fcVectorTimesScalar right t \fcVectorTimesScalar \fcVectorPlusVector /t t Delta add def} repeat
end
}

\newcommand{\fcTriangleComputePatchesAndContours}{
25 dict begin
\fcTriangleInSceneInit
\fcMarkClean
/currentPatch
[ vertex0 vertex1 vertex2 vertex1 vertex2 \fcVectorPlusVector 0.5
\fcVectorTimesScalar
[ vertex0 dup vertex1 \fcSegmentCodeNoFirstPoint vertex1 vertex2 \fcSegmentCodeNoFirstPoint vertex2 vertex0 \fcSegmentCodeNoFirstPoint]
patchOptions (patch)
] def
/currentContour
[
currentPatch \fcPatchGetContour {[exch true]}forall
contourOptions
]
def
thePatchCollection numPatchesComputedSoFar currentPatch put
theContourCollection numContoursComputedSoFar currentContour put
\fcMarkCleanCheck
end
}

\newcommand{\fcTriangleInSceneInit}{
/contourOptions exch def
/patchOptions exch def
/vertex2 exch def
/vertex1 exch def
/vertex0 exch def
}

\newcommand{\fcBoxIIIdInScene}[5][]{%
\fcPatchInScene[#1]{#2}{#4}{#3}%
\fcPatchInScene[#1]{#2}{#5}{#4}%
\fcPatchInScene[#1]{#2}{#3}{#5}%
\fcPatchInScene[#1]{#3}{#3 #4 #2 \fcVectorMinusVector \fcVectorPlusVector}{#3 #5 #2 \fcVectorMinusVector \fcVectorPlusVector}%
\fcPatchInScene[#1]{#4}{#4 #5 #2 \fcVectorMinusVector \fcVectorPlusVector}{#4 #3 #2 \fcVectorMinusVector \fcVectorPlusVector}%
\fcPatchInScene[#1]{#5}{#5 #3 #2 \fcVectorMinusVector \fcVectorPlusVector}{#5 #4 #2 \fcVectorMinusVector \fcVectorPlusVector}%
}

%We give the patch by its corners v0, v1, v2.
\newcommand{\fcTriangleInScene}[4][]{%
\setkeys{fcGraphics}{#1}%
\pstVerb{%
/theIIIdObjects [theIIIdObjects \fcArrayToStack [#2\space #3\space #4\space \fcPatchOptions \fcContourOptions (triangle)] ] def%
}%
}

%Format of patch: we give the patch by its corners v0, v1, v2. The patch is spanned by v1-v0 and v2-v0
\newcommand{\fcPatchInScene}[4][]{%
\fcSurfaceInScene[#1, iterationsU=1, iterationsV=1]{0}{0}{1}{1}{%
3 dict begin %
/v0 #2\space def %
/t1 #3\space v0 \fcVectorMinusVector def %
/t2 #4\space v0 \fcVectorMinusVector def %
v0 %
t1 u \fcVectorTimesScalar %
t2 v \fcVectorTimesScalar %
\fcVectorPlusVector \fcVectorPlusVector %
end %
}{}%
}

%Format of surface: we store the surface in the format
%[umin vmin umax vmax
%[x(u,v) y(u,v) z(u,v)] %coordinate functions
% restrictions %boolean function in u,v, when the function evaluates to false the surface is not drawn. A great tool for cutting surfaces.
%uIterations vIterations   %number of curvilinear u,v-segments
%[red green blue] %color of patches whose u,v-side is visible
%[red green blue] %color of patches whose v,u-side is visible
%[red green blue] %color of contours
% foregroundstatus %true or false
%(surface)].
\newcommand{\fcSurfaceInScene}[7][]{%
\setkeys{fcGraphics}{#1}%
\pstVerb{%
[theIIIdObjects \fcArrayToStack [#2\space #3\space #4\space #5\space {#6} {#7} length 0 ne {{#7}}{{true}}ifelse \fcIterationsU\space \fcIterationsV%
\fcPatchOptions%
\fcContourOptions%
(surface)] ]/theIIIdObjects exch def}%
}%

\newcommand{\fcCurveIIIdNoSceneCode}{%
15 dict begin%
/theCurve exch def%
/tMax exch def%
/tMin exch def%
/numPoints \fcPlotPoints\space def%
/Delta tMax tMin sub numPoints 1 sub div def%
/t tMin def %
\fcLineFormatCode %
newpath %
theCurve \fcCoordsIIIdToPS moveto %
numPoints 1 sub {/t t Delta add def theCurve \fcCoordsIIIdToPS lineto } repeat %
stroke %
end %
}%

\newcommand{\fcZBufferBoundingBoxPolyline}{ %
{\fcZBufferBoundingBoxPoint} forall
}

\newcommand{\fcContains}{ %
%format: theElement theArray -> true if theElement is in the array, false else.
3 dict begin %
/theArray exch def %
/theElement exch def %
false %
/counter 0 def %
theArray length { %
theElement theArray counter get \fcAreEqual {pop true exit}if %
/counter counter 1 add def %
}repeat %
end %
}

\newcommand{\fcAreEqual}{ %
1 dict begin
/areEqual
{5 dict begin
/left exch def
/right exch def
left type  right type ne{false}
{ left type (arraytype) ne{ left right eq}
{ left length right length ne{false}
{ /counter 0 def %
true %
left length { left  counter get right counter get areEqual not{pop false exit }if /counter counter 1 add def }repeat
}ifelse
}ifelse
}ifelse
end
} def %
areEqual
end
}

\newcommand{\fcZBufferAccountPatchIndexAtXY}{ %
5 dict begin %
/currentArray theZBuffer row get column get def %
/counter 0 def %
thePatchIndex currentArray \fcContains not
{theZBuffer row get column [currentArray \fcArrayToStack thePatchIndex ] put}if
end %
}

\newcommand{\fcMergeSort}{
2 dict begin
/theArray exch def
/mergeSortStartIndexLength {
10 dict begin
/theLength exch def
/startIndex exch def
{ theLength 1 eq
  { [theArray startIndex get]
  	exit
  } if
  theLength 2 eq
  { theArray startIndex get theArray startIndex 1 add get
    LeftGreaterThanRight
    { [theArray startIndex 1 add get theArray startIndex get]
    }
    { [theArray startIndex get theArray startIndex 1 add get]
    } ifelse
    exit
  } if
  /leftLength theLength 2 div cvi def
  /rightLength theLength leftLength sub def
  /leftSorted startIndex leftLength mergeSortStartIndexLength def
  /rightSorted startIndex leftLength add rightLength mergeSortStartIndexLength def
  /counterLeft 0 def
  /counterRight 0 def
  [ theLength{
      counterLeft leftLength ge{
        /leftNext false def
      }{
        counterRight rightLength ge{
          /leftNext true def
        }{
          /leftNext leftSorted counterLeft get rightSorted counterRight get  LeftGreaterThanRight not def
        } ifelse
      } ifelse
      leftNext{
        leftSorted counterLeft get /counterLeft counterLeft 1 add def
      }{
        rightSorted counterRight get /counterRight counterRight 1 add def
      }ifelse
    } repeat
  ]
  exit
}loop
end
} def
theArray length 0 gt {
  0 theArray length mergeSortStartIndexLength
}{
  theArray
} ifelse
end
}

\newcommand{\fcBubbleSort}{
5 dict begin
/a exch def
/n a length 1 sub def
n 0 gt {
% at this point only the n+1 items in the bottom of a remain to be sorted
% the largest item in that block is to be moved up into position n
n {
0 1 n 1 sub {
/i exch def
a i get a i 1 add get LeftGreaterThanRight {
% if a[i] > a[i+1] swap a[i] and a[i+1]
a i 1 add
a i get
a i a i 1 add get
% set new a[i] = old a[i+1]
put
% set new a[i+1] = old a[i]
put
} if
} for
/n n 1 sub def
} repeat
} if
end
}

\newcommand{\fcGaussianElimination}{
15 dict begin
/theMatrix exch def
/numRows theMatrix length def
/numCols theMatrix 0 get length def
/rowIndex 0 def
/columnIndex -1 def
{ /columnIndex columnIndex 1 add def
  columnIndex numCols ge {exit}if
  /candidateIndex -1 def
  /counter rowIndex 1 sub def
  numRows rowIndex sub {
    /counter counter 1 add def
    theMatrix counter get columnIndex get 0 ne {/candidateIndex counter def exit}if
  }repeat
  candidateIndex -1 ne{
    /temp theMatrix rowIndex get def
    theMatrix rowIndex theMatrix candidateIndex get put
    theMatrix candidateIndex temp put
    /pivotRow theMatrix rowIndex get def
    /theCoeff 1 pivotRow columnIndex get div def
    /pivotRow pivotRow  theCoeff \fcVectorTimesScalar def
    theMatrix rowIndex pivotRow put
    /counter -1 def
    numRows {
      /counter counter 1 add def
      counter rowIndex ne{
      theMatrix counter get dup columnIndex get pivotRow exch \fcVectorTimesScalar \fcVectorMinusVector theMatrix exch counter exch put
      }if
    }repeat
    /rowIndex rowIndex 1 add def
  }if
  rowIndex numRows ge {exit}if
}loop
theMatrix
end\space
}

\newcommand{\fcLeftSegmentIsBehindSegmentsAreSkew}{
%Let l1 l2 be the endpoints of the left segment,
%r1, re - the endpoints of the right.
%Let pl1, pl2, pr1, pr2 denote the projections onto the viewing
%screen of the corresponding endpoints.
%Let
%(a,c) be the vector pl1-pl2
%(b,d) be the vector pr2-pr1
%(e,f) be the vector pr2-pl2
%We need to solve the system
%(a b) (s)= (e)
%(c d) (t)= (f)
%The determinant of the system must be non-zero, else the segments are non-skew.
% the projections of the segments intersect if 0 <= s<=1
% and 0<=t<=1.
%In that case the point on the left segment that projects onto the point of interest is s*l1 +(1-s)l2. The point on the right segment that projects onto the point of interest is t*r1 +(1-t)*r2
%
25 dict begin
\fcArrayToStack
/r1 exch def
/r2 exch def
\fcArrayToStack
/l1 exch def
/l2 exch def
/pr1 [r1 \fcCoordsIIIdToPStricks] def
/pr2 [r2 \fcCoordsIIIdToPStricks] def
/pl1 [l1 \fcCoordsIIIdToPStricks] def
/pl2 [l2 \fcCoordsIIIdToPStricks] def
pl1 pl2 \fcVectorMinusVector \fcArrayToStack
/c exch def
/a exch def
pr2 pr1 \fcVectorMinusVector \fcArrayToStack
/d exch def
/b exch def
pr2 pl2 \fcVectorMinusVector \fcArrayToStack
/f exch def
/e exch def
/theMatrix [[a b e][c d f]] \fcGaussianElimination def
/a theMatrix 0 get 0 get def
/d theMatrix 1 get 1 get def
/e theMatrix 0 get 2 get def
/f theMatrix 1 get 2 get def
a 0 eq d 0 eq or {false}{
/s e a div def
/t f d div def
s 0 gt s 1 lt t 0 gt t 1 lt and and and
{
/leftPoint l1 s \fcVectorTimesScalar l2 1 s sub \fcVectorTimesScalar \fcVectorPlusVector def
/rightPoint r1 t \fcVectorTimesScalar r2 1 t sub \fcVectorTimesScalar \fcVectorPlusVector def
leftPoint  \fcScreen\space pop \fcVectorScalarVector
rightPoint \fcScreen\space pop \fcVectorScalarVector
ge
}
{false}
ifelse
}ifelse
end
}

\newcommand{\fcLeftPatchIsBehind}{
2 dict begin
/rightIndex exch def
/leftIndex exch def
leftIndex rightIndex \fcLeftPatchIsBehindOrPatchesIntersect
{
rightIndex leftIndex \fcLeftPatchIsBehindOrPatchesIntersect not
}
{false}ifelse
end
}

\newcommand{\fcLeftPatchIsBehindOrPatchesIntersect}{
%this function compares two patches:
40 dict begin
/rightIndex exch def
/leftIndex exch def
/rightPatch thePatchCollection rightIndex get def
/leftPatch thePatchCollection leftIndex get def
rightPatch \fcPatchGetForcedForegroundStatus leftPatch \fcPatchGetForcedForegroundStatus not and {true}{
leftPatch \fcPatchGetForcedForegroundStatus rightPatch \fcPatchGetForcedForegroundStatus not and
{false}{
/result false def
{ leftPatch \fcPatchGetContour {rightPatch \fcPointIsBehindOrInFrontOfPatch{true} {/result true def exit}if }forall
result {exit}if
rightPatch \fcPatchGetContour {leftPatch \fcPointIsBehindOrInFrontOfPatch{false} {/result true def exit}if }forall
exit
}loop
result
}ifelse
}ifelse
end
}

\newcommand{\fcLeftPatchIsBehindOrPatchesIntersectOLDAndINCORRECT}{
%this function compares two patches:
40 dict begin
/rightIndex exch def
/leftIndex exch def
/rightPatch thePatchCollection rightIndex get def
/leftPatch thePatchCollection leftIndex get def
rightPatch \fcPatchGetForcedForegroundStatus leftPatch \fcPatchGetForcedForegroundStatus not and {true}{
leftPatch \fcPatchGetForcedForegroundStatus rightPatch \fcPatchGetForcedForegroundStatus not and
{false}{
/lv0 leftPatch \fcPatchGetvZero def
/lv1 leftPatch \fcPatchGetvOne def
/lv2 leftPatch \fcPatchGetvTwo def
/lv3 leftPatch \fcPatchGetvThree def
/rv0 rightPatch \fcPatchGetvZero def
/rv1 rightPatch \fcPatchGetvOne def
/rv2 rightPatch \fcPatchGetvTwo def
/rv3 rightPatch \fcPatchGetvThree def
/ls0 [lv0 lv1] def
/ls1 [lv1 lv3] def
/ls2 [lv2 lv3] def
/ls3 [lv0 lv2] def
/rs0 [rv0 rv1] def
/rs1 [rv1 rv3] def
/rs2 [rv2 rv3] def
/rs3 [rv0 rv2] def
/result false def
4 leftIndex eq  3 rightIndex eq and {(4 behind 3?) == }if
{ lv0 rightPatch \fcPointIsBehindOrInFrontOfPatch{true} {/result true def 4 leftIndex eq  3 rightIndex eq and {(4 IS behind 3 for vertex reasons) == }if exit }if
  lv1 rightPatch \fcPointIsBehindOrInFrontOfPatch{true} {/result true def 4 leftIndex eq 3 rightIndex eq and {(4 IS behind 3 for vertex reasons) == }if exit }if
  lv2 rightPatch \fcPointIsBehindOrInFrontOfPatch{true} {/result true def 4 leftIndex eq 3 rightIndex eq and {(4 IS behind 3 for vertex reasons) == }if exit }if
  lv3 rightPatch \fcPointIsBehindOrInFrontOfPatch{true} {/result true def 4 leftIndex eq 3 rightIndex eq and {(4 IS behind 3 for vertex reasons) == }if exit }if
  [ls0 ls1 ls2 ls3]
  { [rs0 rs1 rs2 rs3]
    {
    3 leftIndex eq  4 rightIndex eq and {(3 behind 4? 2nd) == pstack (STACK) ==}if
    %3 leftIndex eq  3 rightIndex eq and {(ere be i) == pstack }if
    %(printint stack) == pstack (printing stack done ) ==
      exch dup 3 -1 roll \fcLeftSegmentIsBehindSegmentsAreSkew{/result true def exit}if
    }forall
    pop
    result {exit}if
  }forall
  exit
}loop
3 leftIndex eq 4 rightIndex eq and {(and the 34 RESULT result is...) == result ==}if
result
}ifelse
}ifelse
end
}

\newcommand{\fcZBufferPaintPatches}{
10 dict begin
gsave
/row -1 def %
theZBuffer length{ %
/row row 1 add def %
/column -1 def %
theZBuffer row get length{ %
/column column 1 add def %
/currentZBuffer theZBuffer row get column get def %
currentZBuffer {\fcPaintPatchIndexFilledDirectly} forall %
} repeat%
}repeat %
grestore
end
}

\newcommand{\fcPatchGetNormal}{
1 dict begin
/thePatch exch def
thePatch \fcPatchGetvOne thePatch \fcPatchGetvZero \fcVectorMinusVector
thePatch \fcPatchGetvTwo thePatch \fcPatchGetvZero \fcVectorMinusVector
\fcVectorCrossVector
end
}

\newcommand{\fcPatchOptions}{%
[[\fcGetColorCode{\fcColorPatchUV}] [\fcGetColorCode{\fcColorPatchVU}] \fcForceForeground \space true [\fcGetColorCode{\fcColorLine}] ]%
}%

\newcommand{\fcPatchGetvZero}{0 get\space}
\newcommand{\fcPatchGetvOne}{1 get\space}
\newcommand{\fcPatchGetvTwo}{2 get\space}
\newcommand{\fcPatchGetvThree}{3 get \space}
\newcommand{\fcPatchGetContour}{4 get\space}
\newcommand{\fcPatchGetColorUV}{5 get 0 get \fcArrayToStack \space}
\newcommand{\fcPatchGetColorVU}{5 get 1 get \fcArrayToStack \space}
\newcommand{\fcPatchGetForcedForegroundStatus}{5 get 2 get\space}
\newcommand{\fcPatchGetInBounds}{5 get 3 get\space}
\newcommand{\fcPatchGetColorContour}{5 get 4 get \fcArrayToStack \space}
\newcommand{\fcPatchGetIsDashed}{5 get 5 get \space}
\newcommand{\fcPatchGetDashes}{5 get 6 get \fcArrayToStack \space}

\newcommand{\fcPaintPatchIndexFilledDirectly}{
thePatchCollection exch get \fcPatchPaintFilledDirectly
}

\newcommand{\fcPatchGetPoint}{
1 dict begin
/thePatch exch def %
thePatch \fcPatchGetvZero
thePatch \fcPatchGetvOne
thePatch \fcPatchGetvTwo
thePatch \fcPatchGetvThree
\fcVectorPlusVector
\fcVectorPlusVector
\fcVectorPlusVector
0.25 \fcVectorTimesScalar
end
}

\newcommand{\fcPatchPaintLabel}{
3 dict begin
/thePatch exch def
20 string cvs
/Times-Roman findfont
4 scalefont
setfont
newpath
thePatch \fcPatchGetPoint \fcCoordsIIIdToPS moveto
show
stroke
end
}

\newcommand{\fcPlotArrow}{
2 copy
exch
newpath
\fcCoordsIIIdToPS moveto
\fcCoordsIIIdToPS lineto
stroke
exch [ exch \fcCoordsIIIdToPStricks ] exch [exch \fcCoordsIIIdToPStricks ] plotArrowHeadVirtual
}


\newcommand{\fcPatchPaintNormal}{
1 dict begin
/thePatch exch def
2 setlinewidth
0 0 0 setrgbcolorVirtual
thePatch \fcPatchGetPoint
thePatch \fcPatchGetPoint thePatch \fcPatchGetNormal \fcVectorPlusVector
\fcPlotArrow
1 1 0 setrgbcolorVirtual
thePatch \fcPatchGetvZero
thePatch \fcPatchGetvOne
\fcPlotArrow
0 1 1 setrgbcolorVirtual
thePatch \fcPatchGetvZero
thePatch \fcPatchGetvTwo
\fcPlotArrow
end
}

\newcommand{\fcPatchPaintFilledDirectly}{
1 dict begin
/thePatch exch def %
thePatch type (arraytype) eq{
thePatch \fcPatchGetContour length 0 gt{
thePatch \fcPatchGetNormal \fcScreen\space pop \fcVectorScalarVector 0 gt
{ thePatch \fcPatchGetColorVU setrgbcolorVirtual }
{ thePatch \fcPatchGetColorUV setrgbcolorVirtual }
ifelse
0.5 setalpha
newpathVirtual
thePatch \fcPatchGetContour 0 get \fcCoordsIIIdToPS movetoVirtual
thePatch \fcPatchGetContour{\fcCoordsIIIdToPS linetoVirtual}forall
closepathVirtual
fillVirtual
strokeVirtual
%thePatch \fcPatchPaintNormal
}if
}if
end
}

\newcommand{\fcPatchPaintContourDirectly}{
1 dict begin
/thePatch exch def %
thePatch type (arraytype) eq{
thePatch \fcPatchGetIsDashed {thePatch \fcPatchGetDashes setdashVirtual}{[] 0 setdashVirtual}ifelse
thePatch \fcPatchGetContour length 0 gt{
thePatch \fcPatchGetColorContour setrgbcolorVirtual
newpathVirtual
thePatch \fcPatchGetContour 0 get \fcCoordsIIIdToPS movetoVirtual
thePatch \fcPatchGetContour{\fcCoordsIIIdToPS linetoVirtual}forall
closepathVirtual
strokeVirtual
}if
}if
end
}

\newcommand{\fcZBufferPatchIndex}{ %
15 dict begin %
/thePatchIndex exch def %
/thePatch thePatchCollection thePatchIndex get def
%thePatch \fcPatchPaintContourDirectly
/secondPoint thePatch \fcPatchGetvTwo def %
/firstPoint  thePatch \fcPatchGetvOne def %
/basePoint   thePatch \fcPatchGetvZero def %
/firstDirection firstPoint basePoint \fcVectorMinusVector def %
/secondDirection secondPoint basePoint \fcVectorMinusVector def %
/iterationsFirst [firstDirection \fcCoordsIIIdToPStricks\space pop getZBufferDeltaX div firstDirection \fcCoordsIIIdToPStricks\space exch pop getZBufferDeltaY div] \fcVectorNorm 2 mul 2 add round cvi def %
/iterationsSecond [secondDirection \fcCoordsIIIdToPStricks pop  getZBufferDeltaX div secondDirection \fcCoordsIIIdToPStricks exch pop getZBufferDeltaY div] \fcVectorNorm 2 mul 2 add round cvi def
/s 0 def %
iterationsFirst{ %
/firstComponent firstDirection s iterationsFirst 1 sub div  \space\fcVectorTimesScalar basePoint \fcVectorPlusVector def%
/t 0 def %
iterationsSecond{ %
secondDirection t iterationsSecond 1 sub div \fcVectorTimesScalar %
firstComponent \fcVectorPlusVector \fcZBufferRowColumn %
/column exch def %
/row exch def %
\fcZBufferAccountPatchIndexAtXY %
/t t 1 add def %
}repeat
/s s 1 add def %
}repeat
end %
}

\newcommand{\fcCurveIIId}[4][linecolor=\fcColorGraph]{%
\parametricplot[#1]{#2}{#3}{#4 \fcCoordsIIIdToPStricks}%
}

\newcommand{\fcZeroVector}{[exch {0} repeat]}

\newcommand{\fcPerpendicularComputeHeel}[3]{%
\pstVerb{%
7 dict begin%
/thePoint #1 def%
/heelSize #3 def %
mark #2 %
counttomark 1 eq {%
/directionUnitVector exch \fcVectorNormalize def%
/basePoint thePoint length \fcZeroVector def%
}{%
/basePoint exch def%
/directionUnitVector exch basePoint \fcVectorMinusVector \fcVectorNormalize def%
} ifelse %
pop%
/heel directionUnitVector thePoint basePoint \fcVectorMinusVector directionUnitVector \fcVectorScalarVector \fcVectorTimesScalar basePoint \fcVectorPlusVector def%
/perpendicularUnitVector thePoint heel \fcVectorMinusVector \fcVectorNormalize def %
/polyLineInput {%
heel directionUnitVector heelSize \fcVectorTimesScalar \fcVectorMinusVector %
dup perpendicularUnitVector heelSize \fcVectorTimesScalar \fcVectorPlusVector %
heel perpendicularUnitVector heelSize \fcVectorTimesScalar \fcVectorPlusVector%
} def%
}%
}

\newcommand{\fcPerpendicular}[4][ ]{%
\fcPerpendicularComputeHeel{#2}{#3}{#4}%
\psline[#1](! thePoint \fcArrayToStack)(! heel \fcArrayToStack)%
\listplot[linecolor=red]{ [polyLineInput] {\fcArrayToStack} \fcSpliceArrayOperation \fcArrayToStack}%
\pstVerb{end}%
}

\newcommand{\fcPerpendicularIIId}[4][]{%
\fcPerpendicularComputeHeel{#2}{#3}{#4}%
\fcLineIIId[#1]{thePoint}{heel}%
\fcPolyLineIIId[linecolor=red]{polyLineInput}%
\pstVerb{end}%
}%

\newcommand{\fcPlotIIId}[7][]{%
\fcPlotIIIdXconst[#1]{#2}{#3}{#4}{#5}{#6}{#7}%
\fcPlotIIIdYconst[#1]{#2}{#3}{#4}{#5}{#6}{#7}%
}
\newcommand{\fcPlotIIIdXconst}[7][]{%
\setkeys{fcGraphics}{#2}%
\multido{\ra=0+1}{\fcIterationsX}{%
\pstVerb{%
3 dict begin %
/x \ra \space #3 mul \fcIterationsX \space \ra \space sub 1 sub  #5\space mul add \fcIterationsX\space 1 sub div def%
/ymin #4 def%
/ymax #6 def%
}%
\parametricplot[#1]{ymin}{ymax}{%
1 dict begin /y t def  [x y #7] \fcCoordsIIIdToPStricks end%
}%
\pstVerb{end}%
}%end multido
}

\newcommand{\fcPlotIIIdYconst}[7][]{%
\setkeys{fcGraphics}{#2}%
\multido{\ra=0+1}{\fcIterationsY}{%
\pstVerb{%
3 dict begin%
/y \ra \space #4 mul \fcIterationsY \space \ra \space sub 1 sub  #6\space mul add \fcIterationsY\space 1 sub div def%
/xmin #3 def%
/xmax #5 def%
}%
\parametricplot[#1]{xmin}{xmax}{%
1 dict begin /x t def  [x y #7] \fcCoordsIIIdToPStricks end%
}%
\pstVerb{end}%
}%end multido
}

\newcommand{\fcSurfaceIIIdUConst}[7][]{%
\setkeys{fcGraphics}{#2}%
\multido{\ra=0+1}{\fcIterationsX}{%
\pstVerb{%
3 dict begin%
/u \ra \space #3 mul \fcIterationsX \space \ra \space sub 1 sub  #5\space mul add \fcIterationsX\space 1 sub div def%
/vmin #4 def%
/vmax #6 def%
}%
\parametricplot[#1]{vmin}{vmax}{%
1 dict begin /v t def #7 \fcCoordsIIIdToPStricks end%
}%
\pstVerb{end}%
}%end multido
}

\newcommand{\fcSurfaceIIIdVConst}[7][]{%
\setkeys{fcGraphics}{#2}%
\multido{\ra=0+1}{\fcIterationsY}{%
\pstVerb{%
3 dict begin%
/v \ra \space #4 mul \fcIterationsY \space \ra \space sub 1 sub  #6\space mul add \fcIterationsY\space 1 sub div def%
/umin #3 def%
/umax #5 def%
}%
\parametricplot[#1]{umin}{umax}{%
1 dict begin /u t def #7 \fcCoordsIIIdToPStricks end%
}%
\pstVerb{end}%
}%end multido
}

\newcommand{\fcSurfaceDirectDraw}[7][]{%
\fcSurfaceIIIdUConst[#1]{#2}{#3}{#4}{#5}{#6}{#7}%
\fcSurfaceIIIdVConst[#1]{#2}{#3}{#4}{#5}{#6}{#7}%
}%

%Use: \fcVectorFieldCenteredArrow[options]{startX}{startY}{iterationsX}{iterationsY}{Delta}{y -x}
\newcommand{\fcVectorFieldCenteredArrow}[7][linecolor=blue]{%
\multido{\ra=#2+#6}{#4}{%
\multido{\rb=#3+#6}{#5}{%
\pstVerb{%
4 dict begin%
/x \ra\space def%
/y \rb\space def %
#7\space%
/vY exch def%
/vX exch def%
}%
\psline[#1](! x vX 2 div sub y vY 2 div sub)(! x vX 2 div add y vY 2 div add)%
\pscircle*[linecolor=red](! x y){0.02}%
\pstVerb{end}%
}%end multido
}%end multido
}%

%Use: \fcVectorField[options]{startX}{startY}{iterationsX}{iterationsY}{Delta}{y -x}
\newcommand{\fcVectorField}[7][linecolor=blue]{%
\setkeys{fcGraphics}{#1}%
\multido{\ra=#2+#6}{#4}{%
\multido{\rb=#3+#6}{#5}{%
\pstVerb{%
6 dict begin%
/x \ra\space def%
/y \rb\space def %
#7\space %
/vY exch def%
/vX exch def%
}%
\pscustom{%
\code{%
vX 0 ne vY 0 ne or{
\fcLineFormatCode
[x y] [x vX add y vY add] \fcArrowHeadAndTailPlotCode
}if%
}%
}%
\pscircle*[linecolor=red](! x y){0.02}%
\pstVerb{end}%
}%end multido
}%end multido
}%

\newcommand{\fcGrid}[8][]{%
\setkeys{fcGraphics}{#1}%
\pscustom{%
\code{%
20 dict begin
/startX #2\space def
/startY #3\space def
/iterationsX #4\space def
/iterationsY #5\space def
/DeltaX #6\space def
/DeltaY #7\space def
/stickyPiece (#8) () eq (#8) ( ) eq or {0}{#8}ifelse def
\fcLineFormatCode
/counterX -1 def
iterationsX 1 add{
/counterX counterX 1 add def
/currentX1 counterX DeltaX mul startX add def
/currentY1 0        stickyPiece sub DeltaY mul startY add def
/currentY2 iterationsY stickyPiece add DeltaY mul startY add def
/currentX2 currentX1 def
newpath 
[currentX1 currentY1] \fcCoordsPStricksToPS moveto
[currentX2 currentY2] \fcCoordsPStricksToPS lineto
stroke
} repeat
/counterY -1 def
iterationsY 1 add{
/counterY counterY 1 add def
/currentX1 0        stickyPiece sub DeltaX mul startX add def
/currentY1 counterY DeltaY mul startY add def
/currentY2 currentY1 def
/currentX2 iterationsX stickyPiece add DeltaX mul startX add def
newpath 
[currentX1 currentY1] \fcCoordsPStricksToPS moveto
[currentX2 currentY2] \fcCoordsPStricksToPS lineto
stroke
} repeat
end
}%
}%
}

\newcommand{\fcVectorFieldAlongSurfaceInScene}[8][ ]{%
\setkeys{fcGraphics}{#1}%
\fcSurfaceInScene[#1]{#2}{#3}{#4}{#5}{#6}{#7}%
\pstVerb{%
/theIIIdObjects [theIIIdObjects \fcArrayToStack 
30 dict begin
/theField {#8} def
/theSurfaceObject exch def
theSurfaceObject \fcArrayToStack pop \fcSurfaceInit
/DeltaU uMax uMin sub uIterations div def
/DeltaV vMax vMin sub vIterations div def
/counterU -1 def %
uIterations{
/counterU counterU 1 add def
/counterV -1 def %
vIterations{
/counterV counterV 1 add def
/u DeltaU counterU 0.5 add mul uMin add def
/v DeltaV counterV 0.5 add mul vMin add def
/lineStart theSurface def
/lineEnd theSurface theField \fcVectorPlusVector def
[0 1 [lineEnd lineStart {1 t sub \fcVectorTimesScalar exch t \fcVectorTimesScalar \fcVectorPlusVector} \fcArrayToStack] cvx \fcContourOptions (curve)]
}repeat
}repeat
end
] def
}%
}

 %warning this path is relative to the file that uses the \usepackage command, not relative to the style file.

\renewcommand{\Re}{\mathrm{Re~}}
\renewcommand{\Im}{\mathrm{Im~}}
\newcommand{\doublebrace}[4]{\left\{\begin{array}{ll} #1 & #2 \\#3 & #4  \end{array} \right.}
\newcommand{\triplebrace}[6]{\left\{\begin{array}{ll} #1 & #2 \\#3 & #4  \\#5 & #6\end{array} \right.}

\newenvironment{solutionEnvironment}%
{\begin{proof}[\bfseries\upshape Solution]\renewcommand{\qedsymbol}{}}%
{\end{proof}}%
\newcommand{\solution}[1]{\iftoggle{solutions}{\begin{solutionEnvironment}#1\end{solutionEnvironment}}{}}
%solutionExtra is identical to the solution command, except that it useses a different toggle. 
%The solutionExtra command should only be used for
%problems that have already extremely similar counterparts solved. 
%solutionExtra serves to archive LaTeX'ed solution which 
%are to never be given to the students.
\newcommand{\solutionExtra}[1]{\iftoggle{solutionsExtra}{\begin{solutionEnvironment}#1\end{solutionEnvironment}}{}}

\newcommand{\homeworkEnd}{\end{enumerate}\end{document}}
\newcommand{\homeworkStart}[2]{\title{\course \\ Homework \ #1}\date{%
\ifthenelse{\equal{#2}{}}{}{%
Due #2 at \deadline}}%
\begin{document}\maketitle\begin{enumerate}[]
}%
\newcommand{\points}[1]{\stepcounter{enumi}\item[ ({\bf #1 mark\ifthenelse{\equal{#1}{1}}{}{s}}) \arabic{enumi}.]}
\newcommand{\pointsii}[1]{\stepcounter{enumii}\item[ ({\bf #1 mark\ifthenelse{\equal{#1}{1}}{}{s}}) (\alph{enumii})]}
%Default answer command
\newcommand{\answer}[1]{\iftoggle{answers}{ \hfill{~} \rotatebox{180}{\tiny answer: #1}}{}} %
\newcommand{\hiddenanswer}[1]{\iftoggle{solutions}{ %
\iftoggle{answers}{ %
\hfill{~} \rotatebox{180}{\tiny answer: #1}}
{}} %
{}} %
%I am using \renewcommand{\answer} to redo the command to suit my taste; feel free to modify the above line any way you please.


% Default course name
\newcommand{\course}{Freecalc}
% Default deadline
\newcommand{\deadline}{ (to be announced)}

\newcommand{\fcProblemRef}{\theenumi.\theenumii}
\newcommand{\fcSubProblemRef}{\theenumii.\theenumiii}


 %warning folder paths are relative to the file that uses the includepackage

\renewcommand{\answer}[1]{\iftoggle{answers}{ \hfill{~} \rotatebox{180}{\tiny answer: #1}}{} }
\renewcommand{\hiddenanswer}{\answer}
\renewcommand{\points}[1]{\item}
\renewcommand{\pointsii}[1]{\item}
\renewcommand{\Arctan}{\arctan}
\renewcommand{\Arccos}{\arccos}
\renewcommand{\Arcsin}{\arcsin}
\renewcommand{\Arccot}{\operatorname{arccot}}



\toggletrue{solutions}
%\togglefalse{solutions}
\toggletrue{answers}
\newtheorem{problem}{Problem}

\newcommand{\hide}[1]{}

\renewcommand{\fcProblemRef}{\theproblem.\theenumi}
\renewcommand{\fcSubProblemRef}{\theenumi.\theenumii}
\begin{document}
\begin{center}
\Large
Master Problem Sheet \\
Version \today
 \\ Math 141 Calculus II \\ \normalsize Instructor: Todor Milev

\end{center}

%\noindent \textbf{Name:} \hfill{~}
%\begin{tabular}{c|c|c|c|c|c|c|c|c||c}
%Problem&1 &2&3&4&5&6&7&8& $\sum$\\ \hline
%Score&&&&&&&&&\\ \hline
%Max&20&20&20&20&20&10&20&20&150
%\end{tabular}

This master problem sheet contains all freecalc problems on the topics studied in Calculus II. The latest \LaTeX{} source of this file (complete with typo and error fixes) can be downloaded from the freecalc project page below. 

\url{https://sourceforge.net/p/freecalculus/code/HEAD/tree/}

For a list of contributors/authors of the freecalc project (and in particular, the present problem collection) see the following file.
\url{https://sourceforge.net/p/freecalculus/code/HEAD/tree/trunk/contributors.tex}

\tableofcontents


\section{Derivative non-const exponent }
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/derivatives-non-const-exponent-2.tex
Differentiate
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemDifferentiatex^sinx} $x^{\sin x}$.
\answer{$x^{\sin x}\left(\frac{\sin x}{x} +\cos x\ln x\right) $}
\item $x^{\tan x}$.
\answer{$x^{\tan x}\left(\frac{\tan x}{x}+ (\ln x)\sec^2 x \right) $}
\end{enumerate}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/derivatives-non-const-exponent-2-solutions.tex
\solution{\ref{problemDifferentiatex^sinx}.
$\displaystyle \left(x^{\sin x}\right)'=\left(e^{(\ln x)\sin x}\right)'= e^{(\ln x)\sin x} (\ln x\sin x)'=x^{\sin x}\left( \frac{\sin x}{x}+\ln x\cos x\right) $.
}



\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/derivatives-non-const-exponent.tex
Differentiate.
\begin{multicols}{2}
\begin{enumerate}
\item $10^{x^3}$. \answer{$3(\ln 10) x^{2} (10)^{x^{3}}$}
\item $2^{\tan x}$. \answer{ $(\ln 2) 2^{\tan x}  \sec^2 x $  }
\item $x^x $. \answer{$x^x(\log{}(x) +1)$}
\item $x^{x^x}$. \answer{$(\ln(x))^{2}  x^{x^{x}+x}+x^{x^{x}+x-1}+(\ln x) x^{x^{x}+x}$}
\item $(\sin x)^{\cos x}$. \answer{$\frac{- \ln(\sin{}x)  (\sin{}x)^{\cos{}x+2} +(\sin{}x)^{\cos{}x} \cos^{2}{}x}{\sin{}x}$}
\item $(\ln x)^{\ln x}$. \answer{$\ln{}(\ln{}(x)) x^{-1} (\ln{}(x))^{\ln{}(x)}+x^{-1} (\ln{}(x))^{\ln{}(x)}$}
\end{enumerate}
\end{multicols}

\end{problem}
\section{The number $e$ as a limit}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-problems-2.tex
Compute the limit. 
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemlimxtoinfty((x-2)/x)^x} $\displaystyle\lim\limits_{x\to\infty}\left(\frac{x-2}{x}\right)^x.$

\answer{$e^{-2}$}
\item $\displaystyle\lim\limits_{x\to\infty} \left(\frac{x-2 }{x} \right)^{2 x}$ 

\answer{$e^{-4}$.}
\item $\displaystyle \lim\limits_{x\to\infty} \left(\frac{x}{ x + 3} \right)^{2x}$ 

\answer{$e^{-6}$}
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-problems-2-solutions.tex


\noindent \solution{\ref{problemlimxtoinfty((x-2)/x)^x}. Solution I
\[
\begin{array}{rcll|l}
\displaystyle \lim_{x\to \infty }\left( \frac{x-2}{x}\right)^x&=& \displaystyle \lim\limits_{ x \to \infty }\left( 1- \frac{2}{x}\right)^x &&\text{use } \lim\limits_{x\to\infty} \left( 1+ \frac{k}{x}\right)^x=e^k\\
&=&e^{-2}\quad .
\end{array}
\]

\ref{problemlimxtoinfty((x-2)/x)^x}. Solution II
\[
\begin{array}{rcll|l}
\displaystyle \lim_{x\to \infty }\left( \frac{x-2}{x}\right)^x&=& \displaystyle \lim_{ x \to \infty } e^{\ln \left( \left( \frac{x-2}{x}\right)^x\right)} \\
\displaystyle \lim_{x\to \infty} \ln \left( \left( \frac{x-2}{x}\right)^x\right)&=&\displaystyle  \lim_{x\to \infty} x\left( \ln (x-2) -\ln (x) \right)\\
&=&\displaystyle \lim_{x\to\infty } \frac{ \ln (x-2) -\ln (x)}{\frac{1}{x}} &&\text{L'Hospital rule}\\
&=&\displaystyle \lim_{x\to\infty } \frac{ \frac{1}{ x-2} -\frac{1}{x}}{- \frac{ 1}{ x^2 }}\\
&=&\displaystyle \lim_{x\to \infty }\frac{-2x^2}{x^2-2x}=-2 &&\text{Therefore}\\
\displaystyle \lim_{x\to \infty }\left( \frac{x-2}{x}\right)^x&=& \displaystyle \lim_{ x \to \infty } e^{\ln \left( \left( \frac{x-2}{x}\right)^x\right)} \\
&=&e^{\lim\limits_{x\to \infty} \ln \left( \left( \frac{x-2}{x}\right)^x\right) }\\
&=&e^{-2}\quad .
\end{array}
\]
}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-problems.tex
Find the limit.
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \lim\limits_{x\to \infty} \left(1-\frac{2}{x} \right)^x$. \answer{$e^{-2}$}
\item $\displaystyle \lim\limits_{x\to 0} \left(1-x\right)^{\frac{1}{x}}$.
\answer{ $e^{-1}$}
\item $\displaystyle \lim\limits_{x\to \infty} \left(\frac{x}{x-5}\right)^{x}$.
\answer{$e^5$}
\item $\displaystyle \lim\limits_{x\to \infty} \left(\frac{x}{x-2}\right)^{3x+2}$.
\answer{$e^6$}
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-and-compound-interest.tex
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemEasLimitAndCompoundInterest1procentInterest200years} A sum is held under a yearly compound interest of 1\%. Make an approximation by hand (no calculators allowed) by what factor will have the money increased after 200 years. Can you do the computation in your head?
\item \label{problemEasLimitAndCompoundInterestWhatIsMorecompoundInterest2percent150yearsOrsimpleInterest11percent} Decide, without using a calculator, which is more profitable: earning a yearly compound interest of 2\% for 150 years or earning yearly simple interest of 11\% for 150 years?
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-and-compound-interest-solutions.tex
\solution{\ref{problemEasLimitAndCompoundInterest1procentInterest200years}
Each year, the sum increases by a factor of $\left(1+\frac{1}{100}\right)$. Therefore in $200$ years the sum will have increased by 
\[
\begin{array}{rcll|l}
\left( 1+\frac{1}{100}\right)^{200} &=&\left(\left(1+\frac{1}{100}\right)^{100}\right)^{2}&&\text{equals } \left(1+\frac{1}{n}\right)^n \text{ for } n=100\\
&\approx& e^2.
\end{array}
\]
As a rough estimate for $e$ we can take $e\approx 2.7$, and so $e^2\approx 2.7^2=7.29$. Our sum will have increased approximately $7.3$ times. A calculator computation shows that 
\[
\left( 1+\frac{1}{100}\right)^{200}\approx 7.316018 ,
\] 
so our ``in the head'' estimate is fairly accurate. Notice that the calculator computation is on its own an approximation - it was carried using double floating point precision arithmetics, which does introduce some minimal errors. Such round off errors, of course, are also present in modern banking transactions, so we do not need to adjust for those.
}

\solution{\ref{problemEasLimitAndCompoundInterestWhatIsMorecompoundInterest2percent150yearsOrsimpleInterest11percent}
Simple interest of $11\%$ per $150$ years a profit of 
\[
0.11*150= 15+1.5=16.5,
\]
or altogether $17.5$-fold increase of our initial sum. A $2\%$ compound interest for $150$ years yields a 
\[
\begin{array}{rcl}
\left(1+\frac{2}{100}\right)^{150}&=&\left(\left(1+\frac{1}{50}\right)^{50}\right)^3\\
&\approx& e^3
\end{array}
\]
-fold increase of our sum. To establish which of the two options yields more money, we need to compare $e^{3}$ to $17.5$ (without using a calculator). In the solution of \ref{problemEasLimitAndCompoundInterest1procentInterest200years} we established that $e^2\approx 7.3$, so $e^3\approx e\cdot 7.3\approx 2.7\cdot 7.3=2\cdot 7 +2\cdot 0.3 +0.7\cdot7+0.7\cdot 0.3=14+0.6+4.9+0.21=19.71\approx 19.7$. We can say that the compound interest results in approximately $19.7$-fold increase of the initial sum, so the compound interest is more profitable. A calculator computation shows that 
\[
\left(1+\frac{2}{100}\right)^{150}\approx 19.499603\quad .
\]
Our error of approximately $0.2$ was not optimal, yet fairly accurate for an ``in the head'' computation.



}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/logarithms/homework/e-as-a-limit-various-interesting-problems.tex
$1,000,000$ servers are handling Internet users. Suppose we distribute the computation load as follows. The computation load distributing program directs every new user to a server chosen at random (one server is allowed to process more than one user at a time). Suppose one server has defective hardware and crashes. We are testing the system by simulating $X$ Internet users.
\begin{itemize}
\item What is the chance we catch the defective server using $1$ simulated user?
\item Without using a calculator, estimate the chance we fail to catch the defective server using $1,000,000$ simulated users.
\item Using a calculator, estimate the chance we fail to catch the defective server using $100,000$ simulated users. Write an expression using $e$ which approximates this chance. Evaluate the latter with a calculator. Are the two numbers close? 
\end{itemize}

\textbf{Remark.} While such a simple system architecture would not be practical, it is not to be immediately dismissed as terrible. For example, if we need to handle 2 million users per second, our load distributing mechanism might not be fast enough to keep track of each server's load. On the other hand, an inexpensive modern pc will easily generate 2 million random numbers per second.


\end{problem}
\section{Inverse trigonometry}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-1.tex
Let $x\in (0,1)$. Express the following using $x$ and $\sqrt{1-x^2}$.  
\begin{multicols}{2}
\begin{enumerate} [ref={\fcProblemRef}]
\item $\sin(\Arcsin (x))$. 

\answer{$x$}
\pointsii{3} \label{problemsin(2arcsin x)}  $\sin(2\Arcsin (x))$. 

\answer{$2x\sqrt{1-x^2} $}
\item  \label{problemsin(3arcsin x)} $\sin(3\Arcsin (x))$. 

\answer{$ -4x^3+3x $}
\item $\sin(\Arccos (x))$. 

\answer{$\sqrt{1-x^2} $}
\item $\sin(2\Arccos (x))$. 

\answer{$2x \sqrt{1-x^2 }$}
\item \label{problemsin(3arccos(x))}  $\sin(3\Arccos (x))$. 

\answer{
\begin{tabular}{l}
$\left(4x^2-1\right)\sqrt{1-x^2}$ \\= $-4\left(\sqrt{1-x^2}\right)^3+3\sqrt{1-x^2} $
\end{tabular}
}
\item $\cos(2\Arcsin (x))$. 

\answer{$ 1-2x^2$}
\item $\cos(3\Arccos (x))$. 

\answer{$4x^3-3x $}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-1-solutions.tex
\solution{\ref{problemsin(2arcsin x)}.
Let $y = \Arcsin x$.  Then $\sin y = x$, and we can draw a right triangle with opposite side length $x$ and hypotenuse length $1$ to find the other trigonometric ratios of $y$.  

\begin{center}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dotstyle=o,dotsize=3pt 0,linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-3.33,-6.11)(14.05,6.58)
\psline(0,0)(4,0)
\psline(0,0)(4,3)
\psline(4,3)(4,0)
\psline(4,0.2)(3.8,0.2)
\psline(3.8,0.2)(3.8,0)
\rput[tl](0.83,0.5){$y$}
\rput[tl](1.56,1.82){$1$}
\rput[tl](4.1,1.4){$x$}
\rput[tl](1.7,-0.05){$\sqrt{1-x^2}$}
\parametricplot{0.0}{0.6435011087932844}{1*0.66*cos(t)+0*0.66*sin(t)+0|0*0.66*cos(t)+1*0.66*sin(t)+0}
\end{pspicture*}
\end{center}

Then $\cos y = \sqrt{1-x^2}/1 = \sqrt{1-x^2}$.  
Now we use the double angle formula to find $\sin(2\Arcsin x)$.  

\begin{align*}
\sin (2 \Arcsin x) & = \sin (2y) \\
& = 2\sin y\cos y \\
& = 2x\sqrt{1-x^2}.
\end{align*}
}

\solution{\ref{problemsin(3arcsin x)}. 
Use the result of Problem \ref{problemsin(2arcsin x)}. This also requires the addition formula for sine: 
\[
\sin(A+B) = \sin A \cos B + \sin B\cos A,
\]
and the double angle formula for cosine:
\[
\cos (2y) = \cos^2 y - \sin^2 y.
\]  
\[
\begin{array}{r@{~}c@{~}ll|l}
\sin(3\Arcsin x) & =& \sin(3y) \\
& =& \sin (2y + y) \\
& =& \sin(2y)\cos y + \sin y \cos (2y) &&\text{Use addition formula }\\
& =& (2\sin y \cos y)\cos y + \sin y (\cos^2 y - \sin^2 y)&&\text{Use double angle formulas} \\
& =& 2\sin y \cos^2 y + \sin y \cos^2 y - \sin^3 y \\
& =& 3\sin y \cos^2 y - \sin^3 y \\
& =& 3\sin y (1-\sin^2 y) - \sin^3 y \\
& =& 3x(1-x^2) - x^3 \\
& =& 3x - 4x^3.
\end{array}
\]
The solution is complete. A careful look at the solution above reveals a strategy useful for problems similar to this one.
\begin{enumerate}
\item Identify the inverse trigonometric expression- $\Arcsin x, \Arccos x, \Arctan x, \dots$. In the present problem that was $y=\Arcsin x$. 
\item The problem is therefore a trigonometric function of $y$.
\item Using trig identities and algebra, rewrite the problem as a trigonometric expression involving only the trig function that transforms $y$ to $x$. In the present problem we rewrote everything using $\sin y$.
\item Use the fact that $\sin (\Arcsin x)=x$, $\cos (\Arccos x)=x$, \dots, etc. to simplify.
\end{enumerate}
}

\solution{\ref{problemsin(3arccos(x))} We use the same strategy outlined in the end of the solution of Problem \ref{problemsin(3arcsin x)}. Set $y = \Arccos x$ and so $\cos(y) = x$. Therefore:

\[
\begin{array}{rcll|l}
\sin(3y) &=& \sin(2y +y)\\
&=& \sin(2y)\cos y + \sin y \cos (2y)\\
&=& 2\sin y \cos y \cos y + \sin y (2\cos^2y-1)\\
&=& 2\sin y \cos^2y + \sin y (2\cos^2y-1)
\\
&=&\sin y(4\cos^2 y-1) &&\text{use }\begin{array}{rcl} \cos y&=&x\\\sin y &=& \sqrt{1-x^2}\end{array}\\
&=&\sqrt{1-x^2}(4x^2-1)\quad .
\end{array}
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-2.tex
Express as the following as an algebraic expression of $x$. In other words, ``get rid'' of the trigonometric and inverse trigonometric expressions.

\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\cos^2(\Arctan x)$. 

\answer{$\frac{1}{1+x^2} $}
\item \label{problem-sin^2(arccot x) } $-\sin^2(\Arccot x)$. 

\answer{ $-\frac{1}{1+x^2}$}
\item $\frac{1}{\cos(\Arcsin x)}$. 

\answer{$\frac{1}{\sqrt{1-x^2}}$}
\item $-\frac{1}{\sin(\Arccos x)}$.

\answer{$-\frac{1}{\sqrt{1-x^2}}$}
\end{enumerate}
\end{multicols}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-2-solutions.tex
\solution{\ref{problem-sin^2(arccot x) }. We follow the strategy outlined in the end of the solution of Problem \ref{problemsin(3arcsin x)}. We set $y=\Arccot x$. Then we need to express $-\sin^2 y$ via $\cot y$. That is a matter of algebra:

\[\begin{array}{rcll|l}
-\sin^2(\Arccot x)&=&\displaystyle -\sin^2 y&&\text{Set} y=\Arccot x\\
&=&\displaystyle-\frac{\sin^2 y}{\sin^2y+\cos^2 y} && \text{use } \sin^2y+\cos^2y=1\\
&=&\displaystyle-\frac{1}{\frac{\sin^2 y+\cos^2y}{\sin^2 y}}\\
&=&\displaystyle-\frac{1}{1+\cot^2 y}&& \text{Substitute back } \cot y=x\\
&=&\displaystyle-\frac{1}{1+x^2}\quad.
\end{array}
\]

}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-3.tex
Rewrite as a rational function of $t$. This problem will be later used to derive the Euler substitutions (an important technique for integrating).

\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemcos(2arctan t)} $\cos \left(2\Arctan t\right)$.

\answer{$ \frac{1-t^2}{1+t^2}$.}
\item $\sin \left(2\Arctan t\right)$.

\answer{$ \frac{2t}{1+t^2}$}
\item $\tan \left(2\Arctan t\right)$.

\answer{$ \frac{2t}{1-t^2}$}
\item \label{problemcot(2arctan t)}  $\cot \left(2\Arctan t\right)$.

\answer{$ \frac{1}{2}\left(\frac{1}{t}-t\right)$.}
\item $\csc \left(2\Arctan t\right)$.

\answer{$ \frac{ 1}{2} \left(t+\frac{1}{t}\right)$}
\item $\sec \left(2\Arctan t\right)$.

\answer{$\frac{1+t^2}{1-t^2}$}
\item $\cos \left(2\Arccot t\right)$.

\answer{$ \frac{t^2-1}{t^2+1}$}
\item $\sin \left(2\Arccot t\right)$.

\answer{$ \frac{2t}{t^2+1}$}
\item $\tan \left(2\Arccot t\right)$.

\answer{$ \frac{2t}{t^2-1}$}
\item $\cot \left(2\Arccot t\right)$.

\answer{$ \frac{1}{2}\left( t-\frac{1}{t}\right)$}
\item $\csc \left(2\Arccot t\right)$.

\answer{$ \frac{1}{2}\left(t+\frac{1}{t}\right)$}
\item $\sec \left(2\Arccot t\right)$.

\answer{$ \frac{t^2+1}{t^2-1}$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/trig-evaluated-on-inverse-trig-3-solutions.tex
\solution{\ref{problemcos(2arctan t)}
Set $z=\Arctan t$, and so $\tan z= t$. Then
\[
\begin{array}{rcll|l}
\cos (2\Arctan t)&=&\displaystyle \cos (2z) \\
&=&\displaystyle \frac{\cos (2z)}{1}&& \begin{array}{l} \text{use double angle formulas} \\ \text{and } 1=\sin^2z +\cos^2 z\end{array} \\
&=&\displaystyle \frac{\cos^2 z- \sin^2 z}{\cos^2 z +\sin^2 z} && \text{divide top and bottom by } \cos^2z \\
&=&\displaystyle \frac{(\cos^2 z-\sin^2z)\frac{1}{\cos^2 z}}{(\sin^2 z +\cos^2z)\frac{1}{\cos^2 z}}\\
&=&\displaystyle \frac{1-\tan^2z}{1+\tan^2z}\\
&=&\displaystyle \frac{1-t^2}{1+t^2}
\quad .
\end{array}
\]
}
\solution{\ref{problemcot(2arctan t)}
Set $z=\Arctan t$, and so $\tan z= t$. Then
\[
\begin{array}{rcll|l}
\cot (2\Arctan t)&=&\displaystyle \cot (2z) \\
&=&\displaystyle \frac{\cos (2z)}{\sin (2z)}&&\text{use double angle formulas} \\
&=&\displaystyle \frac{\cos^2 z- \sin^2 z}{2\sin z \cos z}\\
&=&\displaystyle \frac{1- \tan^2 z}{2 \tan z}\\
&=&\displaystyle \frac{1-t^2}{2t}\\
&=&\displaystyle \frac{1}{2}\left(\frac{1}{t}-t\right)\quad .
\end{array}
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/inverse-trig-derivatives.tex
Compute the derivative (derive the formula).

\begin{multicols}{2}
\begin{enumerate}
\item $(\Arctan x) '$. \answer{$\frac{1}{1+x^2}$}
\item $(\Arccot x)'$. \answer{$-\frac{1}{1+x^2}$}
\item $(\Arcsin x)'$. \answer{$\frac{1}{\sqrt{1-x^2}}$}
\item $(\Arccos x)'$. \answer{$-\frac{1}{\sqrt{1-x^2}}$}
\item Let $\text{arcsec}$ denote the inverse of the secant function. Compute $(\text{arcsec} x)'$.
\answer{$\frac{1}{x\sqrt{x^2-1}}$}
\end{enumerate}
\end{multicols}

\end{problem}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/artan-sum-problem.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTangentAngleSumLaw}  Let $a+b\neq k\pi $, $a\neq k\pi+\frac{\pi}{2}$ and $b\neq k\pi +\frac{\pi}{2}$ for any $k\in \mathbb Z$ (integers). Prove that
\[
\frac{\tan a + \tan b}{1-\tan a \tan b }= \tan (a+b)\quad .
\]
\item \label{problemArctangentAngleSumLaw} Let $x$ and $y$ be real. Prove that, for $xy\neq 1$, we have
\[\Arctan x+\Arctan y= \Arctan\left( \frac{x+y}{1-xy}\right)
\]
if the left hand side lies between $\left(-\frac{\pi}{2}, \frac{\pi}{2}\right)$.
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/inverse-trig/homework/artan-sum-problem-solution.tex
\solution{\ref{problemTangentAngleSumLaw} We start by recalling the formulas \[\begin{array}{rcl}\cos(a+b)&=&\cos a \cos b-\sin a \sin b\\ \sin (a+b)&=&\sin a \cos b+\sin b \cos a\quad .
\end {array}
\] 
These formulas have been previously studied; alternatively they follow from Euler's formula and the computation 
\[
\begin{array}{rcl}
\cos (a+b) +i\sin (a+b)&=& e^{i(a+b)}= e^{ia}e^{ib}=(\cos a+ i\sin a)(\cos b +i \sin b)\\
&=&\cos a \cos b-\sin a \sin b +i(\sin a \cos b+\sin b \cos a)\quad .
\end{array}
\]
Now \ref{problemTangentAngleSumLaw} is done via a straightforward computation:
\begin{equation}\label{eqTangentAngleSumLaw}
\begin{array}{rcl}
\tan(a+b)&=&\displaystyle \frac{\sin (a+b)}{\cos (a+b)}=\frac{\sin a \cos b+\sin b \cos a}{\cos a\cos b-\sin a\sin b}=\frac{(\sin a\cos b+\sin b \cos a)\frac{1}{\cos a\cos b}}{(\cos a \cos b-\sin a \sin b)\frac{1}{\cos a\cos b}}\\
&=&\displaystyle \frac{\tan a +\tan b}{1-\tan a \tan b}\quad .
\end{array}
\end{equation}
\noindent \ref{problemArctangentAngleSumLaw} is a consequence of \ref{problemTangentAngleSumLaw}. Let $a=\Arctan x$, $b=\Arctan y$. Then \eqref{eqTangentAngleSumLaw} becomes 
\[
\tan (\Arctan x+\Arctan y)= \frac{\tan (\Arctan x)+\tan(\Arctan y)}{1-\tan (\Arctan x)\tan (\Arctan y)}=\frac{x+y}{1-xy}\quad,
\]
where we use the fact that $\tan (\Arctan w)=w$ for all $w$. We recall that $\Arctan (\tan z)=z$ whenever $z\in \left(-\frac{\pi}{2}, \frac{\pi}{2}\right)$. Now take $\Arctan$ on both sides of the above equality to obtain 
\[
\Arctan x +\Arctan y=\Arctan\left(\frac{x+y}{1-xy}\right)\quad .
\]

}



\section{Integration by parts}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integration-by-parts2.tex
Evaluate the indefinite integral. Illustrate the steps of your solutions.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemIntegratex*sin(x)dx} $\displaystyle \int x \sin x \diff x$.

\answer{$ -x \cos x +\sin x +C$}
\item $\displaystyle \int x e^{-x}\diff x$.

\answer{$-(1+x)e^{-x} +C$}
\item \label{problemIntegratex^2e^xdx} $\displaystyle \int x^2 e^x \diff x$.

\answer{$ x^2e^x-2xe^x+2e^x+C$}
\item $\displaystyle \int x\sin (-2x)\diff x$.

\answer{$ \frac{x}{2}\cos (-2x) +\frac{1}{4}\sin (-2x)+C$}
\item $\displaystyle \int x^2\cos (3x)\diff x$.

\answer{$ \frac{x^2}{3}\sin (3x)+\frac{2x}{9}\cos (3x)-\frac{2}{27}\sin (3x)  +C$}
\item \label{problemintx^2e^(-2x)dx} $\displaystyle \int x^2 e^{-2x}\diff x$.

\answer{$-\frac{x^2e^{-2x}}{2}-\frac{xe^{-2x}}{2}- \frac{ e^{-2x}}{4}+C$}
\item $\displaystyle \int x \sin (2x)\diff x$.

\answer{$-\frac{x}{2}\cos (2x)+\frac{1}{4}\sin (2x) +C$}
\item $\displaystyle \int x \cos (3x)\diff x$.

\answer{$\frac{x}{3}\sin (3x)+\frac{1}{9}\cos (3x) +C$}
\item $\displaystyle \int x^2 e^{2x}\diff x$.

\answer{$\frac{x^2}{2}e^{2x}-\frac{x}{2}e^{2x} +\frac{e^{2x}}{4}+C$}
\item $\displaystyle \int x^3 e^x \diff x$.

\answer{$x^3 e^x-3x^2e^x+6x e^x-6e^x +C$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integration-by-parts2-solutions.tex
\solution{\ref{problemIntegratex*sin(x)dx}. 
\[
\begin{array}{rcl}
\displaystyle\int x \underbrace{\sin x \diff x}_{=\diff(-\cos x)} = -\int x \diff(\cos x) = -x\cos x + \int \cos x \diff x = -x \cos x +\sin x +C\quad .
\end{array}
\]
}

\solution{\ref{problemIntegratex^2e^xdx}.
\[
\begin{array}{rcl}
\displaystyle\int x^2 \underbrace{e^x \diff x}_{\diff  (e^x)} &=&\displaystyle \int x^2 \diff e^x= x^2e^x - \int e^x2x\diff x=  x^2e^x - \int 2x\diff e^x \\
&=&\displaystyle x^2e^x- 2xe^x+ \int 2e^x \diff x= x^2e^x-2xe^x+2e^x+C\quad .
\end{array}
\]
}

\solution{\ref{problemintx^2e^(-2x)dx}.
\[
\begin{array}{rcll|l}
\displaystyle \int x^2 e^{-2x}\diff x&=&\displaystyle \int x^2 \diff \left( \frac{e^{-2x}}{-2}\right)&&\text{Integrate by parts}\\
&=&\displaystyle -\frac{x^2e^{-2x}}{2}-\int \left(\frac{ e^{-2 x}}{ -2} \right) \diff \left(x^2\right)\\
&=&\displaystyle -\frac{x^2e^{-2x}}{2}+ \int xe^{-2x}\diff x\\
&=&\displaystyle  -\frac{x^2e^{-2x}}{2}+ \int x \diff \left( \frac{e^{ -2 x}}{ -2}\right)&&\text{Integrate by parts}\\
&=&\displaystyle  -\frac{x^2e^{-2x}}{2}-\frac{xe^{-2x}}{2}+ \frac{1}{2} \int e^{ -2x} \diff x\\
&=&\displaystyle -\frac{x^2e^{-2x}}{2}-\frac{xe^{-2x}}{2}- \frac{ e^{-2x }}{ 4}+C\quad .
\end{array}
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integration-by-parts.tex
Evaluate the indefinite integral. Illustrate the steps of your solutions.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle\int x^2\cos (2x) \diff x$.

\answer{$ \frac{1}{2}x^2\sin(2x)+\frac{1}{2}x\cos(2x) - \frac{1}{4} \sin(2x) +C$}
\item 
$\displaystyle\int x^2e^{a x} \diff x$, where $a$ is a constant.

\answer{$ \frac{1}{a} x^2 e^{a x} -\frac{2}{a^2}x e^{a x}+\frac{2}{a^3} e^{a x}+C$}
\item 
$\displaystyle\int x^2e^{-ax}\diff x$, where $a$ is a constant.

\answer{$ -\frac{1}{a} x^2 e^{-a x} -\frac{2}{a^2}x e^{- a x}-\frac{2}{a^3} e^{-a x}+C$}
\item \label{problemintx^2(e^(ax)+e^(-ax))^2/4dx}
$\displaystyle\int x^2\frac{(e^{ax}+e^{-ax})^2}4\diff x$, where $a$ is a constant. 

\answer{$\begin{array}{l} \frac{1}{8}\left(a^{-1} x^{2} e^{2 a x}- a^{-1} x^{2} e^{-2 a x} \right. \\
\left. - a^{-2} x e^{2 a x}- a^{-2} x e^{-2 a x}+\frac{1}{2} a^{-3} e^{2 a x} \right.\\
\left. -\frac{1}{2} a^{-3} e^{-2 a x}+\frac{2}{3} x^{3} \right) +C
\end{array}
$ }
\item $\displaystyle\int \frac{1}{\cos^2 x}\diff x$.\quad \quad (Hint: This problem does not require integration by parts. What is the derivative of $\tan x$?)

\answer{$\tan x+C$}
\item $\displaystyle\int (\tan^2 x) \diff x $. \quad \quad (Hint: This problem does not require integration by parts. We can use $\tan^2 x = \frac{1}{\cos^2x }-1$ and the previous problem. )


\item \label{problemintxtan^2xdx} $\displaystyle\int x \tan^2 x \diff x $. \quad \quad (Hint: $\tan^2 x \diff x= \diff (F(x))$, where $F(x)$ is the answer from the preceding problem).

\answer{$-\frac{x^2}{2}+x\tan x + \ln |\cos x|+C$}
\item \label{problemint(e^(-sqrtx)dx)}
$ \displaystyle 
\int e^{-\sqrt{x}}\diff x
$.

\answer{$-2\sqrt{x}e^{-\sqrt{x}} -2e^{-\sqrt{x}}+C$}
\item \label{problemintcos^2xdxviaIntByParts}
$\displaystyle\int \cos^2x ~ \diff x$.

\answer{$\frac{1}{4}\sin(2x) +\frac{x}{2} +C$}
\item $\displaystyle\int \frac{x}{1+x^2} \diff x$  (Hint: use substitution rule, don't use integration by parts)

\answer{$\frac{\ln\left(1+x^2\right)}{2}+C$}
\item \label{problemintarctanxdx}
$\displaystyle \int (\Arctan x) \diff x$.

\answer{$x\Arctan x -  \frac{\ln\left(1+ x^2\right) }{2}+C$}
\item 
$\displaystyle \int (\Arcsin x) \diff x
$.

\answer{$x\Arcsin x+ \sqrt{1-x^2}+C$}
\item \label{problemintArcsinSquared} $\displaystyle\int (\Arcsin x)^2 \diff x $. \quad \quad (Hint: Try substituting $x=\sin y$.)

\answer{$x(\arcsin x)^2+ 2\sqrt{1-x^2}\arcsin x - 2x+C$}
\item 
$\displaystyle
\int\Arctan \left(\frac{1}x\right)\diff x
$.

\item \label{problemintsinxe^xdx} $\displaystyle \int \sin x e^x \diff x$

\answer{$ \frac12 \left(e^x\sin x - e^x\cos x\right)+C$ }
\item $\displaystyle \int \cos x e^x \diff x$

\answer{$ \frac12 \left(e^x\cos x + e^x\sin x\right)+C$ }
\item \label{problemintsin(ln x)dx}
$\displaystyle\int \sin (\ln (x)) \diff x $.

\answer{$ \frac{x}{2}\left(\sin (\ln x)-\cos (\ln x) \right) +C$}
\item $\displaystyle\int \cos (\ln (x)) \diff x $.

\answer{$ \frac{x}{2}\left(\cos (\ln x)+\sin (\ln x) \right) +C$}
\item \label{problemintlnxdx} $\displaystyle \int \ln x \diff x $

\answer{$  x\ln |x|-x+C$}
\item $\displaystyle \int x\ln x  ~ \diff x $.

\answer{$ \frac{1}{2}x^2\ln |x| -\frac{x^2}{4} +C$}
\item \label{problemintlnx/sqrt(x)dx} $\displaystyle\int \frac{\ln x}{\sqrt{x}}\diff x $.

\answer{$ 2\sqrt{x}(\ln x-2)+C$ }
\item $\displaystyle\int (\ln x)^2 \diff x$.

\answer{$ x(\ln x)^2 -2x\ln {}x+2x +C$}
\item $\displaystyle\int (\ln x)^3 \diff x$.

\answer{$x(\ln x)^3 -3x(\ln x)^2 +6x\ln {}x-6x+C$}
\item $\displaystyle\int x^2\cos^2x \diff x$. (This problem is related to Problem  \ref{problemintx^2(e^(ax)+e^(-ax))^2/4dx} as $\cos x= \frac{ e^{ix} + e^{-ix}}{2}$).
\end{enumerate}
\end{multicols}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integration-by-parts-solutions.tex
\solution{\ref{problemintxtan^2xdx}
\[
\begin{array}{rcll|l}
\displaystyle\int x \tan^2 x \diff x &=&\displaystyle\int x\left(\sec^2 x-1 \right)\diff x &&\text{use }\sec^2x-1=\tan^2 x\\
&=&\displaystyle\int x\left(\sec^2 x-1 \right)\diff x \\
&=&\displaystyle - \int x\diff x+\int x\sec^2x\diff x&&\text{use }\diff (\tan x)= \sec^2x\diff x\\
&=&\displaystyle - \frac{x^2}{2} +\int x\diff (\tan x)&&\text{integrate by parts}\\
&=&\displaystyle-\frac{x^2}{2} +x\tan x - \int \tan x \diff x \\
&=&\displaystyle-\frac{x^2}{2} +x\tan x - \int \frac{\sin x}{\cos x}\diff x &&\text{use }\sin x\diff x=-\diff (\cos x)\\
&=&\displaystyle -\frac{x^2}{2}+x\tan x+ \int \frac{\diff (\cos x)}{\cos x} &&\text{Set }y=\cos x \\
&=&\displaystyle-\frac{x^2}{2}+x\tan x + \int \frac{1}{y}\diff y\\
&=&\displaystyle-\frac{x^2}{2}+x\tan x + \ln |y|+C&&\text{Substitute back } y=\cos x\\
&=&\displaystyle -\frac{x^2}{2}+x\tan x + \ln |\cos x|+C\quad .

\end{array}
\]

}

\solution{\ref{problemint(e^(-sqrtx)dx)}
\[
\begin{array}{rcll|l}
\displaystyle \int e^{-\sqrt{x}}\diff x&=& \displaystyle \int 2y e^{-y}\diff y&&\text{Subst.: } \begin{array}{rcl} \sqrt{x}&=&y\\
\frac{1}{2\sqrt{x}}\diff x&=&\diff y\\
\diff x&=&2y\diff y
\end{array}
\\
&=&\displaystyle \int 2y \diff \left(-e^{-y}\right) &&\text{int. by parts}\\
&=&-2ye^{-y}+2\int e^{-y}\diff y\\
&=&-2ye^{-y}-2e^{-y}+C\\
&=&-2\sqrt{x}e^{-\sqrt{x}} -2e^{-\sqrt{x}}+C\quad .
\end{array}
\]
}

\solution{\ref{problemintcos^2xdxviaIntByParts}. Later, we shall study general methods for solving trigonometric integrals that will cover this example. Let us however show one way to solve this integral by integration by parts. 

\noindent$
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int \cos^2 x \diff x&=&\displaystyle x\cos^2x - \int x\diff (\cos^2 x)\\
&=&\displaystyle x\cos^2 x - \int x2\cos x (-\sin x)\diff x&& \sin (2x)=2\sin x \cos x\\
&=&\displaystyle x \cos^2x +\int x\sin (2x)\diff x\\
&=&\displaystyle x \cos^2x +\int x \diff \left(\frac{-\cos (2x)}{2}\right)\\
&=&\displaystyle x \cos^2x +x\left(\frac{-\cos (2x)}{2}\right) -\int \left(\frac{-\cos (2x)}{2}\right)\diff x\\
&=&\displaystyle \frac{x}{2}\left(2\cos^2 x - \cos (2x)\right)+ \frac{\sin (2x)}{4}+C &&\cos (2x)=\cos^2x-\sin^2 x \\
&=&\displaystyle \frac{x}{2}\left(2\cos^2x - (\cos^2x-\sin^2x) \right) + \frac{\sin (2x)}{4}+C&&\cos^2x+\sin^2x=1\\
&=&\displaystyle \frac{x}{2} + \frac{\sin (2x)}{4}+C\quad .\\
\end{array}
$
}

\solution{\ref{problemintarctanxdx}
\[
\begin{array}{rcl}
\displaystyle\int \arctan x \diff x &=& x\displaystyle \arctan x - \int x \diff(\arctan x)\\
&=&\displaystyle x\arctan x - \int \frac{x}{x^2+1}\diff x\\
&=& \displaystyle  x\arctan x - \int \frac{\frac{1}2\diff(x^2)}{x^2+1}\\
&=&\displaystyle  x\arctan x - \int \frac{\frac{1}2\diff(x^2+1)}{x^2+1}\\
&=&\displaystyle  x\arctan x - \frac12\ln (x^2+1) +C\quad .
\end{array}
\]
}

\solution{
\ref{problemintArcsinSquared}. 
\[
\begin{array}{rcll|l}
\displaystyle \int (\Arcsin x)^2 \diff x &=&\displaystyle  \int \left(\Arcsin(\sin y)\right)^2 \diff  (\sin y) &&\text{Set } x= \sin y\\
&=&\displaystyle \int y^2 \cos y \diff y =  \int y^2 \diff (\sin y)  &&\text{Integrate by parts}\\
&=&\displaystyle y^2\sin y - \int 2y\sin y  \diff y\\
&=&\displaystyle y^2\sin y + \int 2y  \diff (\cos y ) & &\text{Integrate by parts}\\
&=&\displaystyle y^2\sin y + 2y \cos y - 2\int \cos y \diff y\\
&=&\displaystyle y^2\sin y+2y \cos y - 2\sin y +C &&\text{Substitute } y=\Arcsin x\\
&=& \displaystyle x(\arcsin x)^2 \\
&&\displaystyle+2\sqrt{1-x^2}\arcsin x - 2x+C\quad .
\end{array}
\]
}

\solution{\ref{problemintsinxe^xdx}
\[
\begin{array}{rcll|l}
\displaystyle\int \sin x \underbrace{e^x \diff x}_{=\diff e^x}&=&\displaystyle\sin x e^x - \int e^x\diff (\sin x)=\sin x e^x - \int \cos x \underbrace{e^x \diff x}_{=\diff e^x}\\
&=& \displaystyle\sin x e^x - e^x\cos x +\int e^x \diff (\cos x) \\
&=& e^x\sin x -e^x\cos x-\int e^x\sin x \diff x &&
\begin{array}{l}
\text{add }\int e^x\sin x \diff x\\
\text{to both sides}
\end{array}\\
\displaystyle 2\int \sin x e^x \diff x& =&\displaystyle \sin x e^x-e^x\cos x\\
\displaystyle \int \sin x e^x \diff x&=&\displaystyle \frac{1}{2} \left(\sin x e^x- e^x\cos x\right)\quad .
\end{array}
\]
}

\solution{\ref{problemintsin(ln x)dx}.

\noindent$
\begin{array}{@{\!\!}r@{~}c@{~}ll|l}
\displaystyle \int \sin (\ln x)\diff x&=&\displaystyle  x\sin (\ln x)-\int x\diff (\sin (\ln x)) &&\text{int. by parts}\\
&=&\displaystyle  x\sin (\ln x ) - \int x \left(\cos (\ln x)\right) \left(\ln x\right)'\diff x\\
&=&\displaystyle x\sin (\ln x)-\int \cos (\ln x)\diff x &&\text{int. by parts}\\
&=&\displaystyle  x\sin (\ln x)- \left( x\cos (\ln x)-\int  x\diff (\cos (\ln x)) \right)\\
&=&\displaystyle x\sin (\ln x)-x\cos (\ln x)+\int x (-\sin (\ln x))(\ln x)'\diff x\\
&=&\displaystyle x\sin (\ln x)-x\cos (\ln x)-\int \sin (\ln x)\diff x &&\begin{array}{l}\text{add } \int \sin (\ln x)\diff x\\ \text{to both sides}\end{array}\\
\displaystyle 2\int \sin (\ln x)\diff x&=&\displaystyle  x\sin (\ln x)-x\cos (\ln x)\\
\displaystyle \int \sin (\ln x)\diff x&=&\displaystyle \frac{x}{2} \left(\sin (\ln x)-\cos (\ln x) \right)\quad .
\end{array}
$
}

\solution{\ref{problemintlnxdx}
\[
\int \ln x \diff x = x\ln x - \int x \diff (\ln x)= x\ln x -\int \frac{x}{x}\diff x= x\ln x -x+C\quad .
\]
}

\solution{\ref{problemintlnx/sqrt(x)dx}
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{\ln x}{\sqrt{x}}\diff x&=&\displaystyle \int (\ln x) 2\diff \left(\sqrt{x}\right)&&\text{integrate by parts}\\
&=&\displaystyle (\ln x)2\sqrt{x}- \int 2\sqrt{x}\diff (\ln x)\\ 
&=&\displaystyle 2\sqrt{x}\ln x - 2\int \frac{\sqrt{x}}{x}\diff x\\
&=&\displaystyle 2\sqrt{x}\ln x - 2\int x^{-\frac{1}{2}}\diff x\\
&=&\displaystyle 2\sqrt{x}\ln x - 4\sqrt{x}+C\\
&=&\displaystyle 2\sqrt{x}(\ln x -2)+C\quad .
\end{array}
\]
}





\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integrate-x-power-n-e-power-x.tex
\label{problemintx^ne^xdx}
Compute $\displaystyle \int x^n e^x \diff x$, where $n$ is a non-negative integer.

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/integration-by-parts/homework/integrate-x-power-n-e-power-x-solution.tex
\solution{\ref{problemintx^ne^xdx}

\[
\begin{array}{rcl}
\displaystyle\int x^n e^x \diff x &=& \displaystyle \int x^n \diff e^x\\
&=&\displaystyle  x^n e^x- \int  e^x \diff x^n\\
&=&\displaystyle  x^n e^x- n\int  x^{n-1}e^x \diff x\\
&=&\displaystyle x^ne^x- n\left(\int x^{n-1}\diff e^x \right)\\
&=&\displaystyle  x^ne^x - n\left(x^{n-1}e^x- \int (n-1)x^{n-2}e^x \diff x \right) \\
&=&\displaystyle x^{n}e^x-nx^{n-1}xe^x+n(n-1)\int x^{n-2}e^x \diff x \\
&=&\dots \text{(continue above process)}\dots\\
&=&\displaystyle x^ne^{x}- nx^{n-1}e^x + n(n-1 )x^{n-2 } e^x + \dots \\
&&\displaystyle +(-1)^kn(n-1)(n-2)\dots(n-k+1)x^{n-k}e^x\\
&&+\dots +(-1)^n n! e^x+C\\
&=&\displaystyle C+\sum_{k=0}^{n} (-1)^n\frac{n!}{(n-k)!} x^{n-k} e^x \quad .
\end{array}
\]
}



\section{Integration of rational functions}
\subsection{Building block integrals}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-blocks.tex
Integrate. Illustrate the steps of your solution. %The answer key has not been proofread, use with caution.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \int \frac{1}{x+1}\diff {}x$

\answer{$\ln |x+1|+C$}
\item $\displaystyle \int \frac{x-1}{x+1}\diff {}x$

\answer{$x-2\ln |x+1|+C$}
\item $\displaystyle \int \frac{ 1}{(x+1)^2}\diff {}x$

\answer{$-\frac{1}{x+1}+C$}
\item $\displaystyle \int \frac{x}{(x+1)^2}\diff {}x$

\answer{$\ln |x+1|+\frac{1 }{x+ 1 }+C$}
\item $\displaystyle \int \frac{ 1}{ (2x+3)^2}\diff {}x$

\answer{$-\frac{1}{2(2x+3)}+C$ }
\item $\displaystyle
\int \frac{x}{ 2x^2+3}\diff x
$

\answer{$\frac{1}{4}\ln \left(2 x^2+ 3\right)+C$ }
\item $\displaystyle
\int \frac{1}{ 2x^2+3}\diff x
$

\answer{$\frac{\sqrt{6}}{6} \Arctan \left(\sqrt{ \frac{ 2}{ 3} } x \right) $}
\item \label{problemIntegrate x/(2x^2+x+1) dx}
$\displaystyle\int \frac{x }{2x^2+x+1}\diff{}x\quad .
$

\answer{$\frac{1}{4}\ln \left(x^2+ \frac{1}{2}x+ \frac{ 1 }{2} \right) - \frac{\sqrt{7}}{14} \Arctan\left( \frac{ 4x+1}{\sqrt{7}} \right) +C$}
\item $\displaystyle
\int \frac{x}{ 2x^2+x+3}\diff x
$

\answer{ $\frac{1}{4}\ln \left( 2 x^{2}+x+3 \right)- \frac{1}{ 2 \sqrt{23}} \arctan \left( \frac{ 4x +1}{ \sqrt{23} } \right) +C$}
\item $\displaystyle
\int \frac{x}{ x^2-x+3}\diff x
$

\answer{$ \frac{1}{2} \ln{} \left| x^{2}- x+3\right| + \frac{ \sqrt{11}}{11} \Arctan{} \left( \frac{ x - \frac{ 1}{2} }{ \frac{\sqrt{11}}{2}} \right) + C $}
\item \label{problemint1/(x^2+1)^2dx}  $\displaystyle
\int \frac{1}{ \left(x^2+1\right)^2}\diff x
$

\answer{$ \frac{1}{2} x \left(x^{2}+1\right)^{ -1} + \frac{ 1}{2} \Arctan{}\left( x\right) +C$}
\item \label{problemint1/(x^2+x+1)^2dx} $\displaystyle
\int \frac{1}{ \left(x^2+x +1 \right)^2 } \diff x
$

\answer{$ \frac{2}{3} x \left(x^{2}+x+1\right)^{ -1} + \frac{ 1}{3} \left(x^{2}+x+ 1\right)^{ -1} +\frac{4 }{ 9} \sqrt{3} \Arctan{} \left( \frac{2}{3} \sqrt{3} x +\frac{\sqrt{3}}{3}\right) $}
\item $\displaystyle \int \frac{1}{ \left(x^2+ 1 \right)^3 }\diff x
$

\answer{$\frac{3}{8} x \left(x^{2}+ 1\right)^{ -1} + \frac{1}{4} x \left(x^{2}+1\right)^{-2}+\frac{3}{8} \Arctan{}\left( x\right)+C$}
\end{enumerate}
\end{multicols}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-blocks-solutions.tex
\solution{\ref{problemIntegrate x/(2x^2+x+1) dx}.

\noindent$
\begin{array}{r@{}c@{}l@{}l@{}|l}
\displaystyle\int \frac{x }{2x^2+x+1}\diff x&=&\displaystyle \int \frac{x}{2\left( x^2 + 2x \frac{1}{4} +\frac{1}{2} \right) }\diff x \\
&=&\displaystyle  \int \frac{x}{2\left( x^2 + 2 x \frac{1}{4} +\frac{1}{16}- \frac{1}{16} +\frac{1}{2} \right) }\diff x &&\begin{array}{l} \text{complete square}\\\text{in denominator}\end{array}\\ 
&=&\displaystyle \frac{1}{2}\int \frac{x}{ \left(x+ \frac{1}{4} \right)^2 + \frac{7}{16} } \diff x \\
&=&\displaystyle \frac{1}{2}\int \frac{  x+ \frac{1}{4} - \frac{1}{4}}{ \left(x+ \frac{1}{4} \right)^2 + \frac{7}{16} } \diff \left(x+\frac{1}{4}\right) &&\text{Set } u=x+\frac{1}{4}\\
&=&\displaystyle \frac{1}{2}\int \frac{u-\frac{1}{4}}{u^2+\frac{7}{16}} \diff u \\
&=&\displaystyle \frac{1}{2}\left(\int \frac{u}{u^2+\frac{7}{16}}\diff u - \frac{1}{4}\int \frac{1}{u^2+\frac{7}{16}}\diff u \right) \\
&=&\displaystyle \frac{1}{2} \left(\frac{1}{2}\ln \left(u^2+\frac{7}{16}\right) - \frac{1}{4\sqrt{\frac{7}{16}}}\Arctan\left(\frac{u}{\sqrt{\frac{7}{16}}}\right)\right) +K\\
&=& \displaystyle \frac{1}{4}\ln \left(x^2+ \frac{1}{2}x+\frac{1}{2} \right) - \frac{\sqrt{7}}{14}\Arctan\left(\frac{4x+1}{\sqrt{7}} \right) +K \quad .
\end{array}
$
}

\solution{\ref{problemint1/(x^2+x+1)^2dx}


\[
\begin{array}{rcll|l}
\displaystyle\int \frac{1}{\left(x^2+x+1\right)^2}\diff x &=&\displaystyle \int \frac{1}{\left(\left(x^2 +2x \frac{1}{2} +\frac{1}{4}\right) - \frac{1}{4}+1\right)^2}\diff x &&\text{complete the square}\\
&=&\displaystyle \int \frac{1}{\left(\left(x+\frac{1}{2}\right)^2+\frac{3}{4}\right)^2}\diff \left(x+\frac{1}{2}\right) &&\text{Set } w=x+\frac{1}{2}\\
&=&\displaystyle \int \frac{1}{ \left(w^2+\frac{3}{4}\right)^2} \diff w\\
&=&\displaystyle \int \frac{1}{ \left(\frac{3}{4} \left( \left( \frac{2w}{\sqrt{3}} \right)^2+1 \right)\right)^2 } \frac{\sqrt{3}}{2} \diff \left(\frac{2 w}{\sqrt{3}}\right) &&\text{Set }  z=\frac{2w}{\sqrt{3}} \\
&=&\displaystyle \frac{\frac{\sqrt{3}}{2}}{\left(\frac{3}{4}\right)^2}\int \frac{1}{\left(z^2+1\right)^2}\diff z\\
&=&\displaystyle\frac{8\sqrt{3}}{9} \int \frac{1}{\left(z^2+1\right)^2}\diff z\quad .
\end{array}
\]
The integral $\int \frac{1}{\left(z^2 + 1 \right)^2 } \diff z$ was already studied; it was also given as an exercise in Problem \ref{problemint1/(x^2+1)^2dx}. We leave the rest of the problem to the reader.
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-block-II-and-III-parametric.tex
\label{problemIntegrateBuildingBlockIIaandIIIa} Let $a,b,c,A, B$ be real numbers. Suppose in addition $a\neq 0$ and  $b^2-4ac<0$. Integrate
\[
\int \frac{Ax +B}{ax^2+bx+c}\diff x\quad .
\]

The purpose of this exercise is to produce a formula in form ready for implementation in a computer algebra system.



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-block-II-and-III-parametric-solution.tex
\solution{\ref{problemIntegrateBuildingBlockIIaandIIIa}. 

\noindent$
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle\int \frac{Ax +B}{ax^2+bx+c}\diff x&=&\displaystyle \int \frac{Ax+B}{a\left( x^2 + 2x \frac{b}{2a} +\frac{c}{a} \right) }\diff x \\
&=&\displaystyle  \int \frac{Ax+B}{a\left( x^2 + 2x \frac{b}{2a}+\frac{b^2}{4a^2}- \frac{b^2}{4a^2} +\frac{c}{a} \right) }\diff x &&\begin{array}{l} \text{complete square}\\\text{in denominator}\end{array}\\ 
&=&\displaystyle \frac{1}{a}\int \frac{Ax+B}{ \left(x+ \frac{b}{2a} \right)^2 + \frac{4ac-b^2}{4a^2} } \diff x &&\text{Set }D=  \frac{4ac-b^2}{4a^2} \\
&=&\displaystyle \frac{1}{a}\int \frac{A \left( x+ \frac{b}{2a} - \frac{b}{2a}\right) +B}{ \left(x+ \frac{b}{2a} \right)^2 + D } \diff \left(x+\frac{b}{2a}\right) &&\text{Set } u=x+\frac{b}{2a}\\
&=&\displaystyle \frac{1}{a}\int \frac{Au+ B- \frac{Ab}{2a}}{u^2+D} \diff u &&\text{Set }C=B-\frac{Ab}{2a} \\
&=&\displaystyle \frac{1}{a}\left(A\int \frac{u}{u^2+D}\diff u + C\int \frac{1}{u^2+D}\diff u \right) \\
&=&\displaystyle \frac{1}{a} \left(\frac{A}{2}\ln (u^2+D) + \frac{C}{\sqrt{D}}\Arctan\left(\frac{u}{\sqrt{D}}\right)\right) +K\\
&=& \displaystyle \frac{1}{a} \left(\frac{A}{2}\ln \left(x^2+ \frac{b}{a}x+\frac{c}{a} \right)\right. \\
&&\displaystyle \left.+ \frac{C}{\sqrt{D}}\Arctan\left(\frac{x+\frac{b}{2a}}{\sqrt{D}} \right)\right) +K.
\end{array}
$ 

\noindent The solution is complete. Question to the student: where do we use $b^2-4ac<0$?
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-block-III-b-parametric.tex

Let $a, b, c, A, B$ be real numbers and let $n>1$ be an integer. Suppose in addition $a\neq 0$ and $b^2-4ac<0$. Let 
\[
J(n)=\int \frac{1}{ \left( x^2+\frac{b}{a}x + \frac{ c}{a}\right)^n}\diff x\quad .
\]
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemIntegrateBuildingBlockIIandIIIbPart1} Express the integral 
\[
\int \frac{Ax +B}{ \left( ax^2 +bx +c\right)^n}\diff x
\]
via $J(n)$.
\item \label{problemIntegrateBuildingBlockIIandIIIbPart2} Express $J(n)$ recursively via $J(n-1)$
\end{enumerate}
The purpose of this exercise is to produce a formula in form ready for implementation in a computer algebra system.

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-building-block-III-b-parametric-solution.tex
\solution{\ref{problemIntegrateBuildingBlockIIandIIIbPart1}.

\noindent$
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle\int \frac{Ax +B}{(ax^2+bx+c)^n}\diff x&=&\displaystyle \int \frac{Ax+B}{a^n\left( x^2 + 2x \frac{b}{2a} +\frac{c}{a} \right)^n }\diff x \\
&=&\displaystyle  \int \frac{Ax+B}{a^n\left( x^2 + 2x \frac{b}{2a}+\frac{b^2}{4a^2}- \frac{b^2}{4a^2} +\frac{c}{a} \right)^n }\diff x &&\begin{array}{l} \text{complete square}\\\text{in denominator}\end{array}\\ 
&=& \displaystyle \frac{1}{a^n} \int \frac{Ax+B}{ \left( \left( x + \frac{b}{2a} \right)^2 + \frac{ 4ac-b^2}{4a^2} \right)^n } \diff x &&\text{Set }D=  \frac{ 4ac-b^2}{4a^2} \\
&=&\displaystyle \frac{1}{ a^n}\int \frac{A \left( x+ \frac{b}{2a} - \frac{b}{ 2a} \right) +B}{ \left(\left(x+ \frac{b}{2a} \right)^2 + D \right)^n } \diff \left(x + \frac{ b}{2a}\right) && \text{Set } u=x+\frac{b}{2a}\\
&=& \displaystyle \frac{1}{a^n} \int \frac{Au+ B- \frac{Ab}{2a} }{ \left(u^2+D\right)^n} \diff u &&\text{Set }C = B - \frac{A b}{2 a} \\
&=&\displaystyle \frac{1 }{a^n} \left( A\int \frac{u}{ \left( u^2 +D\right)^n}\diff u + C\int \frac{1}{\left(u^2+D\right)^n}\diff u \right) \\
&=& \displaystyle \frac{1}{a^n} \left(\frac{A}{2(1-n)} \left( u^2 +D\right)^{1-n} + C J(n ) \right) \\
&=&\displaystyle \frac{1}{a^n} \left(\frac{A}{2(1-n)} \left( x^2 + \frac{ b}{a}x + \frac{c }{a } \right)^{1-n} + C J(n ) \right) \\
\end{array}
$
}

\solution{\ref{problemIntegrateBuildingBlockIIandIIIbPart2}.
We use all notation and computations from the previous part of the problem. According to theory, in order to solve that integral, we are supposed to integrate by parts the simpler integral 

\noindent $
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle J\left(n-1\right) &=&\displaystyle \int \frac{1}{\left( x^2 +  \frac{b}{a}x +\frac{c}{a} \right)^{n-1}}\diff x = \int \frac{1}{\left(u^2+D\right)^{n-1}}\diff u &&\text{int. by parts}\\
&=&\displaystyle  \frac{u}{\left(u^2+D\right)^{n-1}}- \int u ~\diff \left(\frac{1}{\left(u^2+D\right)^{n-1}}\right)\\
&=&\displaystyle \frac{u}{\left(u^2+D\right)^{n-1}}+  2(n-1) \int \frac{u^2}{\left(u^2+D\right)^{n}}\diff u \\
&=&\displaystyle \frac{u}{\left(u^2+D\right)^{n-1}}+  2(n-1) \int \frac{u^2+D-D}{\left(u^2+D\right)^{n}}\diff u \\
&=&\displaystyle \frac{u}{\left(u^2+D\right)^{n-1}}+  2(n-1)J\left(n-1\right)-2D(n-1)  \int \frac{1}{\left(u^2+D\right)^{n}}\diff u \\
&=&\displaystyle \frac{u}{\left(u^2+D\right)^{n-1}}+  2(n-1)J\left(n-1\right)-2D(n-1)  J\left(n \right)
\end{array}
$
In the above equality, we rearrange terms to get that
\[
\begin{array}{rcl}
\displaystyle 2D(n-1)  J\left(n \right)& = & \displaystyle \frac{u}{ \left(u^2 + D \right)^{n-1}} + (2n- 3) J\left( n-1\right) \\
J(n)&=&\displaystyle \frac{1}{D} \left( \frac{ u}{2( n-1) \left( u^2 +D\right)^{n-1}} +\frac{2n-3}{2n-2}J(n-1)\right) \\
&=& \displaystyle \frac{1}{D} \left( \frac{x +\frac{b }{2a}}{ (2n-2)\left(x^2+\frac{b}{a}x +\frac{c}{ a} \right)^{n-1}} +\frac{2n-3}{2n-2}J(n-1)\right)\quad .
\end{array}
\]
}


\subsection{Complete algorithm: partial fractions}
\subsubsection{Quadratic term in the denominator}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-quadratics-in-denominator-1.tex
Integrate. Some of the examples require partial fraction decomposition and some do not. Illustrate the steps of your solution. 
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle\int \frac{1}{4x^2+4x+1}\diff x$

\answer{$-\frac{1}{2} (2 x+1)^{-1}+C$}
\item $\displaystyle \int \frac{1}{1-x^2}\diff x$

\answer{$-\frac{1}{2} \ln{}\left|x-1\right|+\frac{1}{2} \ln{} \left| x+1\right|+C $}

\item $\displaystyle \int \frac{1}{5-x^2}\diff x$

\answer{$-\frac{\sqrt{5}}{10} \ln{}\left|x- \sqrt{5} \right|+ \frac{\sqrt{5}}{10} \ln{}\left|x+ \sqrt{5} \right|+C $}
\item $\displaystyle \int \frac{x}{4x^2 +x+ \frac{ 1}{16}}\diff {}x$

\answer{$\frac{1}{4} (8 x+1)^{-1}+\frac{1}{4} \ln{}\left|8 x+1\right|+C $}
\item $\displaystyle \int \frac{x+1}{2x^2+x}\diff {}x$

\answer{$-\frac{1}{2} \ln{}\left|2 x+1\right|+\ln{}\left|x\right| +C$}
\item $\displaystyle \int \frac{x}{4x^2+x+5}\diff {}x$

\answer{$\frac{1}{8} \ln{}\left(x^{2}+\frac{1}{4} x+\frac{5}{4}\right)-\frac{1}{316}\sqrt{79} \Arctan{} \left(\frac{x+\frac{1}{8}}{\frac{1}{8}\sqrt{79}}\right) +C $}
\item $\displaystyle \int \frac{x}{4x^2+x-5}\diff {}x$

\answer{$ \frac{5}{36} \ln{}\left|x+\frac{5}{4} \right|+ \frac{ 1}{9} \ln{}\left|x-1\right|+C$}
\item $\displaystyle \int \frac{x }{3x^2+x-2}\diff{}x$

\answer{$\frac{2}{15} \ln{}\left|x-\frac{2}{ 3} \right| + \frac{ 1}{5} \ln{}\left|x+1\right| +C$}
\item $\displaystyle \int \frac{x }{3x^2+x+2}\diff{}x$

\answer{$\frac{1}{6} \ln{}\left(x^{2}+\frac{1}{3} x+\frac{2}{3}\right)-\frac{\sqrt{23}}{69} \Arctan{}\left(\frac{6}{23}\sqrt{23} x+\frac{\sqrt{23}}{23}\right) +C$}
\item $\displaystyle \int \frac{x}{2x^2+x+1}\diff {}x$

\answer{$\frac{1}{4} \ln\left(x^{2}+\frac{1}{2} x+\frac{1}{2}\right)-\frac{1}{14}\sqrt{7} \Arctan{}\left(\frac{x+\frac{1}{4}}{\frac{1}{4}\sqrt{7}}\right) +C $}
\item \label{problemIntegrate x/(2x^2+x-1)dx}
$\displaystyle\int \frac{x }{2x^2+x-1}\diff{}x
$

\answer{$\displaystyle \frac{1}{3} \ln |x+1|+\frac{1}{6} \ln \left|x-\frac{1}{2}\right| +C$}

\item $\displaystyle\int \frac{1}{x^2+x+1}\diff x$

\answer{$\frac{2}{3}\sqrt{3} \Arctan{} \left( \frac{ x+ \frac{1}{2}}{\frac{1}{2}\sqrt{3}}\right) +C $}
\item $\displaystyle\int \frac{1}{2x^2+5x+1}\diff x$

\answer{$ \frac{\sqrt{17}}{17} \ln{}\left|x- \frac{ \sqrt{17} }{4} + \frac{5}{4}\right|- \frac{ \sqrt{17} }{17} \ln{}\left|x+ \frac{\sqrt{17}}{4}  + \frac{ 5}{4}\right| $}
\end{enumerate}
\end{multicols}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-quadratics-in-denominator-1-solutions.tex
\solution{\ref{problemIntegrate x/(2x^2+x-1)dx}
The quadratic in the denominator has real roots and therefore can be factored using real numbers. We therefore use partial fractions.
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{x }{2x^2+x-1}\diff{}x&=&\displaystyle \int \frac{\frac{1}{2}x}{\left( x+1\right)\left(x-\frac{1}{2}\right)} \diff x &&\text{partial fractions, see below}\\
&=&\displaystyle  \int \frac{\frac{1}{3} }{\left( x+1\right)}\diff {}x +\int \frac{\frac{1}{6}}{ \left(x - \frac{1}{2}\right)} \diff {}x\\
&=&\displaystyle \frac{1}{3} \ln |x+1|+\frac{1}{6} \ln \left|x-\frac{1}{2}\right| +C\quad .
\end{array}
\]
Except for showing how the partial fraction decomposition was obtained, our solution is complete. We proceed to compute the partial fraction decomposition used above. 

We aim to decompose into partial fractions the following function (the denominator has been factored). 
\[
\frac{x }{2x^{2}+x -1}=\frac{x }{ \left(x +1\right)\left(2x -1\right)} = \frac{A_1}{x+1}+\frac{A_2}{2x-1}\quad .
\]
After clearing denominators, we get the following equality. 
\begin{equation}\label{eqproblemIntegrate x/(2x^2+x-1)dx-1}
x = A_{1} (2x -1)+A_{2} (x +1)\quad.
\end{equation}
Next, we need to find values for $A_1$ and $A_2$ such that the equality above becomes an identity. We show two variants to do that: the method of substitutions and the method of coefficient comparison.

\textbf{Variant I.} This variant relies on the fact that if substitute an arbitrary value for $x$ in \eqref{eqproblemIntegrate x/(2x^2+x-1)dx-1} we get a relationship that must be satisfied by the coefficients $A_1$ and $A_2$. We immediately see that setting $x=\frac{1}{2}$ (notice $x=\frac{1}{2}$ is a root of the denominator) will annihilate the term $A_1(2x-1)$ and we can immediately solve for $A_2$. Similarly, setting $x=-1$ ($x=-1$ is the other root of the denominator) annihilates the term $A_2(x+1)$ and we can immediately solve for $A_1$.

\begin{itemize}
\item Set $x=\frac{1}{2}$. The equation \eqref{eqproblemIntegrate x/(2x^2+x-1)dx-1} becomes 

$\begin{array}{rcl}
\displaystyle \frac{1}{2}&=&\displaystyle A_1\cdot 0 + A_2\left(\frac{1}{2}+1\right) \\
\displaystyle \frac{1}{2}&=&\displaystyle \frac{3}{2}A_2\\
\displaystyle A_2&=&\displaystyle \frac{1}{3}.
\end{array}
$
\item Set $x=-1$. The equation \eqref{eqproblemIntegrate x/(2x^2+x-1)dx-1} becomes 

$\begin{array}{rcl}
\displaystyle -1&=&\displaystyle A_1(2\cdot (-1)- 1) + A_2\cdot 0 \\
\displaystyle -1&=&\displaystyle -3A_2\\
\displaystyle A_2&=&\displaystyle \frac{1}{3}.
\end{array}
$
\end{itemize}
Therefore we have the partial fraction decomposition
\[
\begin{array}{rcl}
\displaystyle \frac{x}{2x^2+x-1}&=&\displaystyle \frac{A_1}{x+1}+ \frac{A_2}{2x-1}\\
&=&\displaystyle \frac{\frac{1}{3}}{x+1}+ \frac{\frac{1}{3}}{2x-1}\\
&=&\displaystyle  \frac{\frac{1}{3}}{x+1} +\frac{\frac{1}{6}}{x-\frac{1}{2}}\quad .
\end{array}
\]


\textbf{Variant II.} 
We show the most straightforward technique for finding a partial fraction decomposition - the method of coefficient comparison. Although this technique is completely doable in practice by hand, it is often the most laborious for a human. We note that techniques such as the one given in the preceding solution Variant are faster on many (but not all) problems. The present technique is also arguably the easiest to implement on a computer. The computations below were indeed carried out by a computer program written for the purpose. 

After rearranging we get that the following polynomial must vanish. Here, by ``vanish'' we mean that the coefficients of the powers of $x$ must be equal to zero.
\[(A_{2} +2A_{1} -1)x +(A_{2} -A_{1} )\quad .
\]
In other words, we need to solve the following system.
\[
\begin{array}{llll} & 2A_{1} & +A_{2} & =1\\ & -A_{1} & +A_{2} & =0\\\end{array}
\] 

\begin{longtable}{cc} System status&Action \\\hline $\begin{array}{llll} & 2A_{1} & +A_{2} & =1\\ & -A_{1} & +A_{2} & =0\\\end{array}$ & Sel. pivot column 2. Eliminate non-pivot entries. \\\hline $\begin{array}{llll} & A_{1} & +\frac{A_{2} }{2} & =\frac{1}{2}\\ & & \frac{3}{2}A_{2} & =\frac{1}{2}\\\end{array}$& Sel. pivot column 3. Eliminate non-pivot entries. \\\hline $\begin{array}{llll} & A_{1} & & =\frac{1}{3}\\ & & A_{2} & =\frac{1}{3}\\\end{array}$& Final result.\\ \end{longtable}
Therefore, the final partial fraction decompocsition is: 
\[
\frac{\frac{x }{2}}{x^{2}+\frac{x }{2} -\frac{1}{2} } =\frac{ \frac{ 1}{3}}{(x +1)}+ \frac{\frac{1}{3}}{(2x -1)}\quad .
\]
}


\subsubsection{Complete algorithm}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-complete-1.tex
Evaluate the indefinite integral. Illustrate all steps of your solution. 
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle  \int \frac{x^3+4}{x^2+4}\diff x$

\answer{$\displaystyle \frac{x^2}{2} +2\arctan \left(\frac{x}{2}\right)-2\ln \left(x^2+4\right)+C$}
\item $\displaystyle\int \frac{4x^2 }{2x^2-1}\diff x$

\answer{$-\frac{1}{2}\sqrt{2} \ln{}\left(x+\frac{1}{2} \sqrt{2}\right) + \frac{1}{2}\sqrt{2} \ln{}\left(x- \frac{1}{2} \sqrt{2} \right)+2 x+C$}
\item $\displaystyle\int \frac{x^3}{x^2+2x-3}\diff x$

\answer{$\frac{1}{4} \ln{}|x-1|+\frac{27}{4} \ln{}|x+3|+\frac{1}{2} x^{2}-2 x$}
\item $\displaystyle\int \frac{x^3}{x^2+3x-4}\diff x$

\answer{$\frac{1}{2}x^2-3x+\frac{64}{5}\ln|x+4| + \frac{1}{5}\ln|x-1| + C$}
\item $\displaystyle\int \frac{x^3 }{2x^2+3x-5}\diff x$ 

\answer{$\frac{125}{56} \ln{}\left(x+\frac{5}{2}\right)+\frac{1}{7} \ln{}\left(x-1\right)+\frac{1}{4} x^{2}-\frac{3}{4} x+C$}
\item $\displaystyle \int \frac{x^2+1}{(x-3)(x-2)^2}\diff x$

\answer{$\displaystyle  10\ln |x-3|-9\ln |x-2|+\frac{5}{x-2}+C $}
\item $\displaystyle \int \frac{x^4 }{(x+1)^2(x+2) } \diff x$

\answer{$\displaystyle \frac{x^2}2 -4x -5\ln|x +1|+16\ln |x+2|-\frac{1}{x +1}+C$}
\item $\displaystyle\int \frac{15x^2-4x-81}{ (x-3)(x +4)(x-1)}\diff x$

\answer{$ 5 \ln{}\left|- x-4\right|+3 \ln{}\left|x-3 \right|+ 7 \ln{}\left|x-1\right|$}
\item $\displaystyle \int \frac {x^{4}+10x^{3}+ 18x^{2} +2x - 13}{x^{4} +4x^{3} +3x^{2}- 4x-4} \diff x$ 
\\~\\

Check first that $(x-1)(x+2)^2(x+1)= x^{4}+4x^{3}+3x^{2}-4x-4$. 

\answer{$3 (x+2)^{-1}+2 \ln{}\left|x+2\right| +\ln{}\left|x-1\right| +3 \ln{}\left|x+1\right|+x+C $}
\item $\displaystyle \int\frac{x^4 }{(x^2+2)(x+2) } \diff x$

\answer{$\displaystyle \frac{x^2}{2} -2x + \frac{8}{3}\ln|x +2|- \frac{1}{3}\ln \left(x^2+2\right)+\frac{2\sqrt{2}}{3} \Arctan \left(\frac{\sqrt{2}}{2}x\right)+C$ }
\item \label{problemintx^5/(x^3-1)dx} $\displaystyle \int \frac{x^5 }{x^3-1}\diff x$

\answer{$
\begin{array}{l}
\frac{1}{3} \ln{} \left| x^{2} + x + 1\right|+\frac{1}{3} \ln{} \left|x-1\right|+\frac{1}{3} x^{3}+C\\
=\frac{1}{3} \ln{} \left| x^3-1\right|+\frac{1}{3} x^{3}+C
\end{array}
$}
\item \label{problemIntegral x^4/((x^2+2)(x+1)^2)} $\displaystyle\int \frac{x^4}{(x^2+2)(x+1)^2} \diff x $

\answer{$\displaystyle x -\frac{1}{3} (x+1)^{-1}-\frac{10}{9} \ln{}\left|x+1\right| -\frac{4}{9} \ln\left|x^{2} +2\right| -\frac{ 2}{ 9} \sqrt{ 2} \Arctan{}\left(\frac{\sqrt{2}}{2} x\right)+C$}
\item \label{problemint(3x^2+2x-1)/((x-1)(x^2+1))dx} $\displaystyle\int \frac{3x^2 + 2x - 1}{(x-1)(x^2+1)} \diff x$

\answer{$2 \ln|x-1| + \frac{1}{2} \ln\left(x^2+1\right) + 3 \Arctan x+C$}
\item $\displaystyle \int \frac{x^2-1}{x(x^2+1)^2}\diff x$

\answer{$-\left(x^{2}+1\right)^{-1}+\frac{1}{2} \ln{}\left(x^{2}+1\right)- \ln{} |x|$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-complete-1-solutions.tex
\solution{ \ref{problemIntegral x^4/((x^2+2)(x+1)^2)}
We are trying to integrate a rational function; we aim to decompose into partial fractions the following function. 
\[
\frac{x^{4}}{x^{4}+2x^{3}+3x^{2}+4x +2}=\frac{x^{4}}{ \left(x +1\right)^2 \left(x^{2}+2\right)}
\]

Since the numerator of the function is of degree greater than or equal to the denominator, we start the partial fraction decomposition by polynomial division.
\renewcommand{\arraystretch}{1.2}\begin{longtable}{|cccccc|} \hline&\multicolumn{5}{|c|}{\textbf{Remainder}}\\\multicolumn{1}{|c|}{} & &$\color{red}{-2x^{3}}\color{black}$ & $\color{red}{-3x^{2}}\color{black}$ & $\color{red}{-4x }\color{black}$ & $\color{red}{-2}\color{black}$ \\\hline\textbf{Divisor(s)} &\multicolumn{5}{|c|}{\textbf{Quotient(s)}}\\$x^{4}+2x^{3}+3x^{2}+4x +2$& \multicolumn{5}{|l|}{$1$}\\\hline& \multicolumn{5}{|c|}{\textbf{Dividend}}\\\multicolumn{1}{|c|}{$\underline{~}$} &$x^{4}$ & &&&\\&$x^{4}$ & $+2x^{3}$ & $+3x^{2}$ & $+4x $ & $+2$ \\\cline{2-6}&&$\color{red}{-2x^{3}}\color{black}$ & $\color{red}{-3x^{2}}\color{black}$ & $\color{red}{-4x }\color{black}$ & $\color{red}{-2}\color{black}$ \\\hline\end{longtable}
Therefore we have
\[
\begin{array}{rcl}
\displaystyle \frac{x^{4}}{x^{4}+2x^{3}+3x^{2}+4x +2}&=&\displaystyle 1+ \frac{-2x^3-3x ^2-4x-2}{x^{4}+2x^{3} +3x^{2} +4x +2}\\
\displaystyle \frac{-2x^3-3x^2-4x-2}{x^{4}+2x^{3}+3x^{2}+4x +2} & =&\displaystyle  \frac{-2x^3-3x^2-4x-2 }{\left(x +1\right)^2\left(x^{2}+2\right)}\\
&=&\displaystyle  \frac{A_1}{(x+1)}+\frac{A_2}{(x+1)^2}+\frac{A_3+A_4x}{(x^2+2)}
\end{array}
\]
We seek to find $A_i$'s that turn the above expression into an identity. Just as in the solution of Problem \ref{problemIntegrate x/(2x^2+x-1)dx}, we will use the method of coefficient comparison (see the solution of Problem \ref{problemint(3x^2+2x-1)/((x-1)(x^2+1))dx} for a shortcut method).


After clearing denominators, we get the following equality. 

\noindent$\begin{array}{@{}rcl@{}}
-2x^{3}-3x^{2}-4x -2 &=& A_{1} (x +1)(x^{2}+2)+A_{2} (x^{2}+2)\\
&&+(A_{3} + A_{4} x)(x +1)^{2}\\
0&=&(A_{4} +A_{1} +2)x^{3}\\
&&+(2A_{4} +A_{3} +A_{2} +A_{1} +3)x^{2}\\
&&+(A_{4} +2A_{3} +2A_{1} +4)x \\
&&+(A_{3} +2A_{2} +2A_{1} +2)\quad .
\end{array}
$

\noindent In order to turn the above into an identity we need to select $A_i$'s such that the coefficients of all powers of $x$ become zero. In other words, we need to solve the following system. 
\[
\begin{array}{llllll} & A_{1} & & & +A_{4} & =-2\\ & A_{1} & +A_{2} & +A_{3} & +2A_{4} & =-3\\ & 2A_{1} & & +2A_{3} & +A_{4} & =-4\\ & 2A_{1} & +2A_{2} & +A_{3} & & =-2\quad .\\
\end{array}
\] 
This is a system of linear equations. There exists a standard method for solving system of linear equations called Gaussian Elimination (also known as Row-Echelon Form Reduction Method). This method is very well suited for computer implementation. We illustrate it on this particular example; for a description of the method in full generality we direct the reader to a standard course in Linear algebra. 

\begin{longtable}{cc} System status & Action \\\hline $\begin{array}{llllll} & A_{1} & & & +A_{4} & =-2\\ & A_{1} & +A_{2} & +A_{3} & +2A_{4} & =-3\\ & 2A_{1} & & +2A_{3} & +A_{4} & =-4\\ & 2A_{1} & +2A_{2} & +A_{3} & & =-2\\\end{array}$& Sel. pivot column 2. Eliminate non-pivot entries. \\\hline $\begin{array}{llllll} & A_{1} & & & +A_{4} & =-2\\ & & A_{2} & +A_{3} & +A_{4} & =-1\\ & & & 2A_{3} & -A_{4} & =0\\ & & 2A_{2} & +A_{3} & -2A_{4} & =2\\\end{array}$& Sel. pivot column 3. Eliminate non-pivot entries. \\\hline $\begin{array}{llllll} & A_{1} & & & +A_{4} & =-2\\ & & A_{2} & +A_{3} & +A_{4} & =-1\\ & & & 2A_{3} & -A_{4} & =0\\ & & & -A_{3} & -4A_{4} & =4\\\end{array}$& Sel. pivot column 4. Eliminate non-pivot entries. \\\hline $\begin{array}{llllll} & A_{1} & & & +A_{4} & =-2\\ & & A_{2} & & +\frac{3}{2}A_{4} & =-1\\ & & & A_{3} & -\frac{A_{4} }{2} & =0\\ & & & & -\frac{9}{2}A_{4} & =4\\\end{array}$& Sel. pivot column 5. Eliminate non-pivot entries. \\\hline $\begin{array}{llllll} & A_{1} & & & & =-\frac{10}{9}\\ & & A_{2} & & & =\frac{1}{3}\\ & & & A_{3} & & =-\frac{4}{9}\\ & & & & A_{4} & =-\frac{8}{9}\\\end{array}$& Final result.\\ \end{longtable}

Therefore, the final partial fraction decomposition is the following. 
\[\begin{array}{rcl}
\displaystyle \frac{x^{4}}{x^{4}+2x^{3}+3x^{2}+4x +2}&=&\displaystyle 1+ \frac{-2x^{3}- 3x^{2}-4x -2}{x^{4}+2x^{3}+3x^{2}+4x +2}\\
&=&\displaystyle 1+ \frac{-\frac{10}{9}}{(x +1)}+\frac{\frac{1}{3}}{(x +1)^{2}}+\frac{-\frac{8}{9}x -\frac{4}{9}}{(x^{2}+2)}
\end{array}
\]

Therefore we can integrate as follows.
\[
\begin{array}{rcl}
\displaystyle \int \frac{x^4}{(x^2+2)(x+1)^2} \diff x &=&\displaystyle \int \left( 1+ \frac{-\frac{10}{9}}{(x +1)}+\frac{\frac{1}{3}}{(x +1)^{2}}+\frac{-\frac{8}{9}x -\frac{4}{9}}{(x^{2}+2)}\right)\diff x\\
&=&\displaystyle \int \diff x-\frac{10}{9}\int \frac{1}{(x +1)}\diff x + \frac{ 1}{3}\int \frac{ 1}{(x +1)^{2}}\diff x \\
&&\displaystyle -\frac{8}{9} \int \frac{x}{x^{2}+2}\diff x-\frac{4}{9} \int \frac{ 1}{x^{2}+2}\diff x \\
&=&\displaystyle x -\frac{1}{3} (x+1)^{-1}-\frac{10}{9} \log{}\left(x+1\right)\\
&&\displaystyle -\frac{4}{9} \log{}\left(x^{2} +2\right) -\frac{ 2}{ 9} \sqrt{ 2} \arctan{}\left(\frac{\sqrt{2}}{2} x\right)+C
\end{array}
\]
}

\solution{\ref{problemint(3x^2+2x-1)/((x-1)(x^2+1))dx}. 
This is a concise solution written in a form suitable for exam taking. We set up the partial fraction decomposition as follows.
\[
\displaystyle \frac{3x^2 + 2x - 1}{(x-1)(x^2+1)} = \frac{A}{x-1} + \frac{Bx+C}{x^2+1}\quad .
\]
Therefore $3x^2 + 2x - 1 = A(x^2+1) + (Bx+C)(x-1)$. 
\begin{itemize}
\item We set $x = 1$ to get $4 = 2A$, so $A = 2$.
\item We set $x = 0$ to get $-1=A-C$, so $C=3$.
\item Finally, set $x = 2$ to get $15=5A+2B+C$, so $B=1$.
\end{itemize}
We can now compute the integral as follows.
\[
\displaystyle \int\left( \frac{2}{x-1} + \frac{x+3}{x^2+1} \right) \diff x = 2 \ln(|x-1|) + \frac{1}{2} \ln(x^2+1) + 3 \Arctan x+K\quad .
\]
}

\solution{\ref{problemintx^5/(x^3-1)dx}
This problem can be solved directly with a substitution shortcut, or by the standard method. 

\textbf{Variant I (standard method).}

\noindent$\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int \frac{x^5}{x^3-1}\diff x&=&\displaystyle \int\left( x^2+\frac{x^2}{x^3-1}\right)\diff x  &&\text{Polyn. long div. }\\
&=&\displaystyle\frac{x^3}{3}+\int \frac{x^2}{(x-1)(x^2+x+1)}\diff x&&\text{part. frac.}\\
&=&\displaystyle\frac{x^3}{3}+\int \left(\frac{\frac{1}{3}}{x -1}+\frac{\frac{2}{3}x +\frac{1}{3}}{x^{2}+x +1}\right)\diff x &&\text{complete square}\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3}\ln |x-1|+\frac{2}{3}\int \frac{x+\frac{1}{2}}{\left(x+\frac{1}{2}\right)^2+ \frac{3}{4}}\diff x &&\text{Set } \begin{array}{rcl} u&=&\left(x+\frac{1}{2}\right)^2+ \frac{3}{4}\\\frac{1}{2}\diff u&= &\left(x+\frac{1}{2}\right) \diff x\end{array}\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3}\ln |x-1|+\frac{1}{3} \int \frac{\diff u}{u}\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3}\ln |x-1|+\frac{1}{3}\ln |u|+C\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3}\ln |x-1|+\frac{1}{3}\ln |x^2+x+1|+C\\
\end{array}
$

\textbf{Variant II (shortcut method).}
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{x^5}{x^3-1}\diff x&=&\displaystyle \int \frac{x^5-x^2+x^2}{x^3-1}\diff x\\
&=&\displaystyle \int \frac{x^2(x^3-1)+x^2}{x^3-1}\diff x\\
&=&\displaystyle\int x^2\diff x+ \int \frac{x^2}{x^3-1}\diff x\\
&=&\displaystyle \frac{x^3}{3}+\int \frac{\diff \left(\frac{x^3}{3}\right)}{x^3-1}\\
&=& \displaystyle \frac{x^3}{3}+\frac{1}{3} \int \frac{\diff \left(x^3-1\right)}{x^3-1}&&\text{Set }u=x^3-1\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3}\int \frac{\diff u}{u}\\
&=&\displaystyle\frac{x^3}{3}+\frac{1}{3}\ln |u|+C\\
&=&\displaystyle \frac{x^3}{3}+\frac{1}{3} \ln \left|x^3-1\right|+C\quad .
\end{array}
\]
The answers obtained in the two solution variants are of course equal since 
\[
\ln |x-1|+\ln |x^2+x+1|= \ln \left|\left(x-1\right)\left(x^2+x+1\right)\right|=\ln \left|x^3-1\right|\quad .
\]
}



\subsubsection{A large example illustrating the complete algorithm}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-complete-large-example-1.tex
\label{problemint(x^6-x^5+9/2x^4-4x^3+13/2x^2-7/2x+11/4)/(x^5-x^4+3x^3-3x^2+9/4x-9/4)dx}
Integrate
\[
\int \frac{x^{6}-x^{5}+\frac{9}{2} x^{4}-4 x^{3}+\frac{13}{2} x^{2}-\frac{7}{2} x+\frac{11}{4}}{x^{5}-x^{4}+3 x^{3}-3 x^{2}+\frac{9}{4} x-\frac{9}{4}} \diff x\quad .
\]


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/partial-fractions/homework/integration-rational-functions-complete-large-example-1-solution.tex
\solution{
\ref{problemint(x^6-x^5+9/2x^4-4x^3+13/2x^2-7/2x+11/4)/(x^5-x^4+3x^3-3x^2+9/4x-9/4)dx}.

\noindent\textbf{Step 1.} The first step of our algorithm is to reduce the fraction so that numerator has smaller degree than the denominator. This is done using polynomial long division as follows.

Variable name(s): $x $1 division steps total.\renewcommand{\arraystretch}{1.2}\begin{longtable}{|cccccccc|} \hline&\multicolumn{7}{|c|}{\textbf{Remainder}}\\\multicolumn{1}{|c|}{} & &&$\color{red}{\frac{3}{2}x^{4}}\color{black}$ & $\color{red}{-x^{3}}\color{black}$ & $\color{red}{+\frac{17}{4}x^{2}}\color{black}$ & $\color{red}{-\frac{5}{4}x }\color{black}$ & $\color{red}{+\frac{11}{4}}\color{black}$ \\\hline\textbf{Divisor(s)} &\multicolumn{7}{|c|}{\textbf{Quotient(s)}}\\$x^{5}-x^{4}+3x^{3}-3x^{2}+\frac{9}{4}x -\frac{9}{4}$& \multicolumn{7}{|l|}{${\color{blue}{x}} $}\\\hline& \multicolumn{7}{|c|}{\textbf{Dividend}}\\\multicolumn{1}{|c|}{$\underline{~}$} &$x^{6}$ & $-x^{5}$ & $+\frac{9}{2}x^{4}$ & $-4x^{3}$ & $+\frac{13}{2}x^{2}$ & $-\frac{7}{2}x $ & $+\frac{11}{4}$ \\&$x^{6}$ & $-x^{5}$ & $+3x^{4}$ & $-3x^{3}$ & $+\frac{9}{4}x^{2}$ & $-\frac{9}{4}x $ & \\\cline{2-8}&&&$\color{red}{\frac{3}{2}x^{4}}\color{black}$ & $\color{red}{-x^{3}}\color{black}$ & $\color{red}{+\frac{17}{4}x^{2}}\color{black}$ & $\color{red}{-\frac{5}{4}x }\color{black}$ & $\color{red}{+\frac{11}{4}}\color{black}$ \\\hline\end{longtable}

In other words, 

\noindent$
\begin{array}{@{}r@{}c@{}l}
x^{6}-x^{5}+\frac{9}{2} x^{4}-4 x^{3}+\frac{13}{2} x^{2}-\frac{7}{2} x + \frac{11}{4}  &=& (x^{5}-x^{4}+3 x^{3}-3 x^{2} + \frac{9}{4} x-\frac{9}{4}) {\color{blue}{x}} \\&&+{\color{red}{\frac{3}{2} x^{4}-x^{3} +\frac{17}{4} x^{2}-\frac{5}{4} x +\frac{11}{4}}} \quad ,
\end{array}
$

\noindent and therefore

\noindent$
\begin{array}{@{}r@{}c@{}l@{}}
\displaystyle \frac{x^{6}-x^{5}+\frac{9}{2} x^{4}-4 x^{3}+\frac{13}{2} x^{2}-\frac{7}{2} x+\frac{11}{4}}{x^{5}-x^{4}+3 x^{3}-3 x^{2}+\frac{9}{4} x-\frac{9}{4}} &=&\displaystyle {\color{blue}{x}} +\frac{\color{red}{\frac{3}{2} x^{4}-x^{3} +\frac{17}{4} x^{2}-\frac{5}{4} x +\frac{11}{4}}}{x^{5}-x^{4}+3 x^{3}-3 x^{2}+\frac{9}{4} x-\frac{9}{4} }
\\ 
&=&\displaystyle  x+\frac{6 x^{4}-4 x^{3}+17 x^{2}-5 x+11}{4x^{5}-4 x^{4}+12 x^{3}-12 x^{2}+9 x-9}.
\end{array}
$

\noindent Set
\[
N(x)= 6 x^{4}-4 x^{3}+17 x^{2}-5 x+11
\]
and
\[
D(x)= 4x^{5}-4 x^{4}+12 x^{3}-12 x^{2}+9 x-9\quad .
\]

\noindent\textbf{Step 2.} (Split into partial fractions). Factor the denominator $D(x)=4x^{5}-4 x^{4}+12 x^{3}-12 x^{2}+9 x-9$. 

We recall from elementary algebra that there is a trick to find all rational roots of $D(x)$ on condition $D(x)$ has integer coefficients. It is well known that when $\frac{p}{q}$ is a rational number, then $\pm \frac{p}{q}$ may be a root of the integer coefficient polynomial $D(x)$ only if $p$ is a divisor of the constant term of $D(x)$, and $q$ is a divisor of the leading coefficient of $D(x)$. Since in our case the leading coefficient is 4 and the constant term is -9, the only possible rational roots of $D(x)$ are $\pm 1, \pm 3, \pm 9, \pm \frac{1}{2}, \pm \frac{3}{2}, \pm \frac{9}{2}, \pm \frac{1}{4}, \pm \frac{3}{4}, \pm \frac{9}{4}$. A rational number $r$ is a root of $D(x)$ if and only if substituting $x=r$ yields 0. Direct check shows that, for example,  $D(-1)=-50$. However, $D(1)=0$ and therefore using polynomial division we get that $D(x)=(x-1)(4x^{4}+12x^{2}+9)$. We recognize that the second multiplicand is an exact square and therefore $D(x)=(x-1)(2x^2+3)^2$.


So far we got
\[
\frac{N(x)}{D(x)}= \frac{6 x^{4}-4 x^{3}+17 x^{2}-5 x+11}{(x-1)(2x^2+3)^2}\quad .
\]
In order to split $\frac{N(x)}{D(x)}$ into partial fractions, we need to find numbers $A, B, C, D, E$ such that
\[
\frac{6 x^{4}-4 x^{3}+17 x^{2}-5 x+11}{(x-1)(2x^2+3)^2}= \frac{A}{(x-1)}+\frac{Bx+C}{(2x^2+3)}+\frac{Dx+E}{(2x^2+3)^2}\quad .
\]
After clearing denominators, we see that this amounts to finding $A, B, C, D, E$ such that
\[
6 x^{4}-4 x^{3}+17 x^{2}-5 x+11= A(2x^2+3)^2+ (Bx+C)(2x^2+3)(x-1) + (Dx+E)(x-1)\quad .
\]
Plugging in $x=1$ we see that $25=25A $ and so $A=1$. We may plug back $A=1$ and regroup to get
\[
2x^{4}-4x^{3}+5x^{2}-5x+2= (Bx+C)(2x^2+3)(x-1) + (Dx+E)(x-1)\quad .
\]
Dividing both sides by $(x-1)$ we get
\[
2x^{3}-2x^{2}+3x-2= (Bx+C)(2x^2+3)+Dx+E\quad .
\]
Regrouping we get
\[
x^{3}(2- 2B) + x^2(-2-2C)+x(3-3B-D)+(-2-3C-E)=0\quad.
\]
As $x$ is an indeterminate, the above expression may vanish only if all coefficients in the preceding expression vanish. Therefore we get the system
\[
\left| \begin{array}{rcl}
2-2B&=&0\\
-2-C&=&0\\
3-3B-D&=&0\\
-2-3C-E&=&0\quad .
\end{array}   \right.
\]
We may solve the above linear system using the standard algorithm for solving linear systems (the algorithm is called row reduction and is also known as Gaussian elimination). The latter algorithm is studied in any standard the Linear algebra course. Alternatively, we see from the first equations $B=1$, $C=-1$, and substituting in the remaining equations we see $D=0$, $E=1$. Finally, we check that
\[
\frac{x^{6}-x^{5}+\frac{9}{2} x^{4}-4 x^{3}+\frac{13}{2} x^{2}-\frac{7}{2} x+\frac{11}{4}}{x^{5}-x^{4}+3 x^{3}-3 x^{2}+\frac{9}{4} x-\frac{9}{4}}
=x+\frac{1}{(x-1)}+\frac{x-1}{(2x^2+3)}+\frac{1}{(2x^2+3)^2}\quad .
\]
\textbf{Step 3.} (Find the integral of each partial fraction).
\[
\begin{array}{rcl}
\displaystyle\int x \diff x &= &\displaystyle \frac{x ^2}2+C\\
\displaystyle\int \frac{1}{x-1} \diff x &=&\displaystyle  \ln|x-1|+C\\
\displaystyle\int \frac{x-1}{2x^2+3} \diff x &=& \displaystyle \int\frac{x}{2x^2+3}\diff x -\frac{1}{3}\int \frac{1}{\frac23x^2+1}\diff x\\
&=& \displaystyle  \int \frac{\diff\left(\frac{x^2}2\right) }{2x^2+3}\diff x-\frac{1}{3} \int \frac{1}{\left(\sqrt{\frac23}x\right)^2+1} \diff x\\
&=&\displaystyle  \frac{1}{4} \int \frac{\diff(2x^2+3)}{2x^2+3}\diff x- \frac{1}{3}\int \frac{\frac{\diff \left(\sqrt{\frac23}x\right)} {\sqrt{\frac23}}} {\left( \sqrt{\frac23}x\right)^2+1} \\
&=&\displaystyle   \frac{1}{4}\ln (2x^2+3)-\frac{\sqrt{6}}{6}\Arctan \left(\sqrt{\frac23}x\right)+C
\quad .
\end{array}
\]
The last integral is
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{1}{(2x^2+3)^2}\diff x&=&\displaystyle  \frac{1}{9} \int \frac{\frac{\diff\left(\sqrt{\frac{2}{3}}x\right)}{\sqrt{\frac23}}}{\left(\left(\sqrt{\frac23}x\right)^2+1\right)^2}\\
&=&\displaystyle  \frac{\sqrt{6}}{18}\int \frac{\diff\left(\sqrt{\frac23}x\right)}{\left(\left(\sqrt{\frac23}x\right)^2+1\right)^2} &&\text{Set }y=\sqrt{\frac23}x\\
&=&\displaystyle  \frac{\sqrt{6}}{18}\int \frac{\diff y}{(y^2+1)^2}\quad.
\end{array}
\]
The general form of the integral $\displaystyle\int \frac{\diff y}{(y^2+1)^2}$ \refBad{\ref{eqBuildingBlock3N}}{is solved in the theoretical discussion}{is solved in \eqref{eqBuildingBlock3N}} by integration by parts. As a review of the theory, we redo the computations directly.
\[
\begin{array}{rcl}
C+\arctan y &=&\displaystyle \int \frac{\diff y}{y^2+1}\\
&=&\displaystyle \frac{y}{y^2+1} +\int \frac{2y^2dy }{( y^2+ 1 )^2}= \frac{y}{y^2+1}+\int \frac{2(y^2+1-1)\diff y}{(y^2+1)^2}\\
&=&\displaystyle \frac{y}{y^2+1} + 2\int \frac{\diff y}{ ( y^2 +1)}- 2\int \frac{\diff y}{(y^2+1)^2}\quad.
\end{array}
\]
Transferring summands we get
\[
\int \frac{\diff y}{(y^2+1)^2}= \frac{1}{2} \left( \frac{ y }{y^2+1} +\arctan y\right) +C\quad .
\]
We recall that $y=\sqrt{\frac{2}{3}}x$ and therefore
\[
\int \frac{\diff x}{(2x^2+3)^2}=\frac{\sqrt{6}}{36}\left(\frac{\sqrt{\frac{2}{3}}x}{\left(\sqrt{\frac{2}{3}}x\right)^2+1}+\arctan \left( \sqrt{\frac{2}{3}}x\right)\right) +C
\]

To get the final answer we need to collect all terms, to get a final answer:
\[
\frac{1}{6}\left(\frac{x}{2x^2+3}\right) - \frac{5\sqrt{6}}{36} \arctan \left(\sqrt{\frac{2}{3}}x \right) +\frac{1}{4} \ln (2x^2+3) +\ln|x-1|+\frac{x ^2 } 2+ C\quad .
\]
}

\section{Trigonometric integrals}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/sinn-cosm-1.tex
Integrate. The answer key has not been proofread, use with caution.
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \int \sin (3 x) \cos (2x)\diff x$.

\answer{$ -\frac{1}{10}\cos (5x)-\frac{1}{2}\cos x+C$}
\item $\displaystyle \int \sin x \cos (5x)\diff x$.

\answer{$ -\frac{1}{12}\cos (6x) +\frac{1}{8}\cos (4x)+C$}
\item $\displaystyle \int \cos (3x) \sin (2x)\diff x$.

\answer{$ -\frac{1}{10}\cos (5x) +\frac{1}{2}\cos x+C$}
\item $\displaystyle \int \sin (5x) \sin (3x)\diff x$.

\answer{$ \frac{1}{4}\sin (2x) -\frac{1}{16}\sin (8x)+C$}
\item $\displaystyle \int \cos (x) \cos (3x)\diff x$.

\answer{$ \frac{1}{8}\sin (4x) +\frac{1}{4}\sin (2x)+C$}
\end{enumerate}


\end{problem}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/sin-cos-1.tex
Integrate.
\begin{enumerate}
\item $\displaystyle \int \sin^2 x \cos x\diff x$.

\answer{$ \frac{1}{3}\sin^3 x+C$}
\item $\displaystyle \int \sin^2 x\diff x$.

\answer{$ \frac{x}{2} -\frac{1}{4}\sin (2x) +C$}
\item $\displaystyle \int \cos^3 x\diff x$.

\answer{$ \sin x -\frac{1}{3}\sin^3 x+C$}
\end{enumerate}


\end{problem}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/tan-sec-1.tex
Integrate.
\begin{enumerate}[ref=\fcProblemRef]
\item \label{problemintsecxdx} $\displaystyle \int \sec x  \diff x$.

\answer{ $ \ln |\sec x +\tan x| = \ln \left|\frac{1+\tan \left( \frac{ x}{2}\right)}{1-\tan \left(\frac{x}{2}\right)} \right| +C$}
\item \label{problemintsec^3xdx} $\displaystyle \int \sec^3x  \diff x$.

\answer{$\frac{1}{2}\left( \sec x \tan x +\ln |\sec x +\tan x|\right)+C$}
\item $\displaystyle \int \tan^3x \diff x$.

\answer{$\frac{1}{2}\tan^2x-\ln |\sec x| +C$}
\item $\displaystyle \int \sec^2x\tan^2x \diff x$.

\answer{$\frac{\tan^3 x}{3} +C$}
\end{enumerate}

\end{problem}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/trig-integrals-collection-1.tex
Integrate.
\begin{enumerate}
\item $\displaystyle \int \sin (5 x) \sin (2x)\diff x$.

\answer{$\frac{1}{2}\left(\frac{\sin (3x)}{3}- \frac{\sin (7x)}{7} \right)+C $}
\item $\displaystyle \int \sin x \cos (2x)\diff x$.

\answer{$\frac{1}{2} \left(\cos x-\frac{\cos (3x)}{3} \right)+C$}
\item $\displaystyle \int \sec \theta  \diff \theta$.

\answer{ $\ln |\sec \theta +\tan \theta|+C$}
\item $\displaystyle \int \sec^3\theta \diff \theta$.

\answer{$\frac{1}{2}\left( \ln|\tan \theta+\sec \theta|+\sec x\tan x \right)+C$}

\item $\displaystyle \int \tan \theta \diff \theta$.
\answer{$\ln |\sec \theta| +C$}
\end{enumerate}


\end{problem}
\subsection{Trigonometric integrals solved via general method $x=2\arctan t$}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/rationalizing-substitution-1.tex
Integrate.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemInt1/(3+cos x)dx} $\displaystyle \int \frac{1}{3+\cos x}\diff x$.

\answer{$\displaystyle\frac{1}{\sqrt{2}} \Arctan \left( \frac{ 1}{ \sqrt{2}} \tan \left( \frac{x }{2} \right)\right)+C$}
\item $\displaystyle \int \frac{1}{4+\cos x}\diff x$.

\answer{$\displaystyle  \frac{2}{15}\sqrt{15} \Arctan{}\left(\frac{\sqrt{15}}{5}\tan\left(\frac{x}{2}\right)\right)+C$}
\item $\displaystyle \int \frac{1}{3+\sin x}\diff x$.

\answer{$\displaystyle \frac{1}{\sqrt{2}} \Arctan \left(\frac{3 \tan \left(\frac{x}{2} \right)+1 }{2\sqrt{2}}\right) +C$}
\item \label{problemInt1/(2+tan x)dx}$\displaystyle \int \frac{1}{2+\tan x}\diff x$.  (Hint: this integral can be done simply with the substitution $x=\Arctan t$.)

\answer{$\displaystyle \frac{1}{5} \ln \left(\sin x+2\cos x\right)+\frac{2}{5}x+C$}

\item \label{problemint1/(2sinx-cosx+5)dx} $\displaystyle \int \frac{ \diff x }{ 2\sin x - \cos x +5}$.


\answer{$\displaystyle \frac{ \sqrt{5}}{5}\Arctan \left( \frac{3}{ \sqrt{5}} \left({ \tan \left(\frac{\theta}{2} \right)}+\frac{1}{3} \right) \right)+C$}
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-integrals/homework/rationalizing-substitution-1-solutions.tex
\solution{\ref{problemInt1/(3+cos x)dx}
We to use the standard rationalizing substitution $x=2\Arctan t$, $t=\tan \left(\frac{x}{2}\right)$. We recall that from the double angle formulas it follows that 
\[
\cos (2\Arctan t)=\frac{\cos^2(\Arctan t)- \sin^2(2\Arctan t)}{\cos^{2}(\Arctan t)+\sin^2(\Arctan t)}=\frac{1-t^2}{1+t^2}\quad .
\]
Therefore we can solve the integral as follows.
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{1}{3+\cos x}\diff x&=&\displaystyle \int \frac{1}{3+\cos (2\Arctan t)}\diff \left(2\Arctan t\right) &&\text{Set } x=2\Arctan t\\
&=& \displaystyle \int \frac{1}{\left(3+\frac{1- t^2}{ 1+t^2}\right)} \frac{ 2}{\left(1+ t^2\right) } \diff t\\
&=&\displaystyle \int\frac{2}{4+2t^2}\diff t\\
&=&\displaystyle \int \frac{1}{2 +t^2}\diff t\\
&=&\displaystyle \frac{\sqrt{2}}{2} \Arctan\left(\frac{\sqrt{2 }}{2} t \right) +C\\
&=&\displaystyle \frac{\sqrt{2}}{2} \Arctan\left(\frac{\sqrt{2 }}{2} \tan\left(\frac{x}{2}\right) \right) +C\quad .
\end{array}
\]
}


\solution{\ref{problemInt1/(2+tan x)dx}
This integral is of none of the forms that can be integrated quickly. Therefore we can solve it using the standard rationalizing substitution $x=2\Arctan t$, $t=\tan \left(\frac{x}{2}\right)$. This results in somewhat long computations and we invite the reader to try it. 

However, as proposed in the hint, the substitution $x=\Arctan t$ works much faster:
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{1}{2+\tan x}\diff x&=&\displaystyle \int \frac{1}{2+\tan (\Arctan t)}\diff \left(\Arctan t\right) &&\text{Substitute } x=\Arctan t\\
&=& \displaystyle \int \frac{1}{\left(2+t\right)} \frac{ 1}{\left(1+ t^2\right) } \diff t && \text{part. fractions}\\
&=&\displaystyle \int \left( \frac{\frac{1}{5}}{(t +2)}+\frac{-\frac{t }{5}+\frac{2}{5}}{(t^{2}+1)}\right)\diff t
\\
&=&\displaystyle \frac{1}{5}\ln |t+2|-\frac{1}{10}\ln (t^2+1)+\frac{2}{5}\arctan t+C && t=\tan x \\
&=&\displaystyle \frac{1}{5}\ln \left|\tan x+ 2\right|-\frac{1}{10}\ln (\tan^2 x+1)+\frac{2}{5}x+C\\
&=&\displaystyle \frac{1}{5}\ln |\tan x+ 2|+\frac{1}{5}\ln \left|\cos x\right|+\frac{2}{5}x+C\\
&=&\displaystyle \frac{1}{5} \ln \left|(\tan x+2)\cos x\right|+\frac{2}{5}x+C\\
&=&\displaystyle \frac{1}{5} \ln \left|\sin x+2\cos x\right|+\frac{2}{5}x+C.\\
\end{array}
\]
}

\solution{\ref{problemint1/(2sinx-cosx+5)dx}.

Set $x=2\arctan t$. As studied\refBad{\ref{eqTrigIntegralsWeistrassSub}}{}{ in equation \ref{eqTrigIntegralsWeistrassSub}}, this substitution implies $\cos x= \frac{1-t^2}{1+t^2}$, $\sin x= \frac{2t}{1+t^2}$, $\diff x=\frac{2}{1+t^2}\diff t$. Therefore

\noindent$\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int \frac{\diff x}{2\sin x-\cos x +5}&=&\displaystyle \int \frac{2\diff t}{(1+t^2)\left(2\frac{2t}{t^2+1}- \frac{(-t^2+1) }{t^2+1}+5\right)} &&\text{Set }x=2\Arctan t\\
&=&\displaystyle \int \frac{\diff t}{3t^2+2t+2}\\
&=&\displaystyle \int  \frac{\diff t}{3\left(t^2+\frac{2}{3}t+ \frac{1}{9}-\frac{1}{9}+\frac{2}{3}\right)}\\
&=&\displaystyle \int  \frac{\diff t}{3 \left( \left(t + \frac{ 1}{ 3 } \right)^2+\frac{5}{9}\right)}\\
&=&\displaystyle \int  \frac{\diff t}{\frac{5}{3} \left( \left( \frac{3}{\sqrt{5}}\left(t + \frac{ 1}{ 3 }\right) \right)^2+1\right)} &&  
\begin{array}{r@{~}c@{~}l}&&\text{Set}\\ w&=& \frac{3}{\sqrt{5}}\left(t + \frac{ 1}{ 3 }\right) \\
&=& \frac{\sqrt{5}}{5}(3t+1)\\
\diff w &=& \frac{3}{\sqrt{5}} \diff t\\
\diff t &=&\frac{\sqrt{5}}{3}\diff w
\end{array}
\\
&=& \displaystyle \int \frac{\frac{\sqrt{5}}{3}dw}{ \frac{5}{3}(w^2+1)}\\
&=&\displaystyle \frac{\sqrt{5}}{5}\arctan w+C
\\
&=&\displaystyle \frac{\sqrt{5}}{5}\arctan\left( \frac{\sqrt{5}}{5}(3t+1) \right)+C\\
&=&\displaystyle \frac{\sqrt{5}}{5}\arctan \left(\frac{\sqrt{5}}{5}\left(3\tan \left(\frac{x}{2}\right)+1\right)\right)+C\quad .
\end{array}
$
}


\section{Trigonometric and Euler substitutions}
\subsection{Transforming radicals of quadratics to the forms $\sqrt{u^2+1}$, $\sqrt{1-u^2}$, $\sqrt{u^2-1}$}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/prepare-radical-of-quadratic-for-integration-complete-square.tex
Find a linear substitution (via completing the square) to transform the radical to a multiple of an expression of the form $\sqrt{u^2+1}$, $\sqrt{u^2-1}$ or $\sqrt{1-u^2}$.

\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemcompletesquaresqrt(x^2+x+1)} $\sqrt{x^2+x+1}$.
\item \label{problemcompletesquaresqrt(-2x^2+x+1)} $\sqrt{-2x^2+x+1}$.
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/prepare-radical-of-quadratic-for-integration-complete-square-solutions.tex
\solution{\ref{problemcompletesquaresqrt(x^2+x+1)}
\[
\begin{array}{rcl}
\displaystyle \sqrt{x^2+x+1}&=&\displaystyle \sqrt{ x^2+2\frac{1}{2}x +\frac{1}{4}-\frac{1}{4} +1} \\
&=&\displaystyle  \sqrt{ \left(x+\frac{1}{2} \right)^2+\frac{3}{4} }\\
&=&\displaystyle \sqrt{\frac{3}{4}\left( \frac{4}{3} \left(x+\frac{1}{2}\right)^2+1 \right)}\\
&=&\displaystyle \frac{\sqrt{3}}{2} \sqrt{\left( \frac{2}{ \sqrt{3}} \left( x+\frac{1}{2}\right)\right)^2+1}\\
&=&\displaystyle \frac{\sqrt{3}}{2} \sqrt{u^2+1},
\end{array}
\]
where $u=\frac{2}{\sqrt{3}}\left( x+\frac{1}{2}\right) = \frac{2 \sqrt{3}}{3}x+\frac{\sqrt{3}}{3}$.
}

\solution{\ref{problemcompletesquaresqrt(-2x^2+x+1)}
\[
\begin{array}{rcl}
\displaystyle \sqrt{-2x^2+x+1}&=&\displaystyle \sqrt{ -2\left( x^2-\frac{1}{2}x -\frac{1}{2}\right) } \\
&=&\displaystyle \sqrt{ -2\left(x^2-2\frac{1}{4}x +\frac{1}{16}-\frac{1}{16}-\frac{1}{2}\right) }\\
&=&\displaystyle \sqrt{-2\left( \left(x- \frac{1}{16} \right)^2 -\frac{9}{16} \right)}\\
&=&\displaystyle  \sqrt{\frac{9}{8}\left(- \frac{16}{9} \left( x-\frac{1}{16}\right)^2+1 \right)}\\
&=&\displaystyle  \frac{3}{\sqrt{8}} \sqrt{-\left( \frac{4}{3} \left(x-\frac{1}{16}\right)\right)^2+1 }\\
&=&\displaystyle \frac{ 3}{\sqrt{8}} \sqrt{-u^2+1}
\end{array}
\]
where $u=\frac{4}{3}\left(x-\frac{1}{16}\right) = \frac{4}{3}x - \frac{1}{12}$.
}


\subsection{Trig or Euler substitution, solutions use trig substitution}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-substitution-sin-cos-1.tex
Compute the integral using a trigonometric substitution.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemint(sqrt(9-x^2)/(x^2)dx)}
$ \displaystyle
\int \frac{\sqrt{9-x^2}}{x^2} \diff x\quad .
$

\answer{$-\frac{\sqrt{9-x^2}}{x} - \Arcsin \left( \frac{x}{3}\right) + C$}
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-substitution-sin-cos-1-solutions.tex
\solution{
\ref{problemint(sqrt(9-x^2)/(x^2)dx)}
\[
\begin{array}{rcll|l}
\displaystyle \int \frac{\sqrt{9-x^2}}{x^2}\diff x&=&\displaystyle  \int \frac{3 \sqrt{\cos^2\theta }}{ 9 \sin^2 \theta }(3\cos\theta)\diff \theta && \begin{array}{l}
\text{Set }x=3\sin \theta \\
\text{for }\theta\in  \left[\frac{\pi}{2},0\right)\cup  \left(0,\frac{\pi}{2}\right] \\
\diff x=3\cos \theta\diff \theta
\end{array}
\\
&=&\displaystyle  9 \int \frac{|\cos \theta|}{\sin^2\theta}\cos\theta \diff \theta &&\begin{array}{l}
\text{For } \theta\in \left[\frac{\pi}{2},0\right)\cup  \left(0,\frac{\pi}{2}\right] \\
\text{we have} |\cos \theta|=\cos \theta\\
\end{array}\\
&=&\displaystyle \int \cot^2 \theta \diff \theta\\
&=&\displaystyle \int (\csc^2\theta -1)\diff \theta\\
&=&\displaystyle -\cot \theta-\theta+C \\
&=&\displaystyle -\frac{\sqrt{9-x^2}}{x} - \Arcsin \left( \frac{x}{3}\right) + C,
\end{array}
\]
where we expressed $\cot \theta$ via $\sin\theta$ by considering the following triangle.
\psset{xunit=1.5cm, yunit=1.5cm}
\begin{pspicture}(-0.15,-0.4)(3.3,1.2)
\tiny
\psframe*[linecolor=white](-0.1,-0.4)(3.3,1.2)
\psline(0,0)(3, 0)(3,1)(0,0)
\psline(2.9,0)(2.9, 0.1)(3,0.1)
\parametricplot{0}{1 3 div arcsin}{t cos 0.4 mul t sin  0.4 mul}
\rput(0.5, 0.05){$\theta$}
\rput[l](3.1, 0.5){$x$}
\rput[br](1.5, 0.55){$3$}
\rput[t](1.5, -0.1){$\sqrt{9-x^2} $}
%bounding box for pdflatex compilation:
\psline[linecolor=red!1](-0.11, -0.4 )(-0.105, -0.4)
\psline[linecolor=red!1](3.3, 1.21)(3.3, 1.205)
\end{pspicture}
}


\subsection{Trig or Euler substitution, solutions use Euler substitution}
\subsection{Case 1: $\sqrt{x^2+1}$}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case1.tex
Integrate
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemIntegratesqrt(x^2+1)dx}
$\displaystyle
\int \sqrt{x^2+1}\diff x
$

\answer{$\frac{1}{2}x\sqrt{x^2+1}+\frac{1}{2}\ln\left( \sqrt{x^2+1}+x\right)+C $}
\item 
$\displaystyle
\int \sqrt{x^2+2}\diff x
$

\answer{$ \ln{}\left(\sqrt{\frac{1}{2} x^{2}+1}+\frac{\sqrt{2}}{2} x\right)+\frac{\sqrt{2}}{2} x \sqrt{\frac{1}{2} x^{2}+1}+C$}
\item 
$\displaystyle
\int \sqrt{x^2+x+1}\diff x
$

\answer{$\frac{3}{4} \left(\frac{1}{2} \ln{}\left(\sqrt{\frac{4}{3} (x+\frac{1}{2})^{2}+1}+\frac{2}{3}\sqrt{3} \left(x+\frac{1}{2}\right)\right)+\frac{\sqrt{3}}{3} \left(x+\frac{1}{2}\right) \sqrt{\frac{4}{3} (x+\frac{1}{2})^{2}+1}\right)  +C$}
\item \label{problemIntegrate sqrt(2x^2+2x+1)dx}
$\displaystyle
\int \sqrt{\left(2x^2+2x+1\right)}\diff x
$

\answer{$\frac{\sqrt{2}}{4} \left( \frac{1}{2} (2x+1)\sqrt{(2x+1)^2+1 }+ \frac{1}{2}\ln \left( \sqrt{(2x+1)^2+1 }+2x+1\right) \right)+C$}

\item \label{problemIntegrate sqrt(3x^2+2x+1)dx}
$\displaystyle
\int \sqrt{\left(3x^2+2x+1\right)}\diff x
$

\answer{$\frac{2}{9}\sqrt{3} \left(\frac{1}{2} \ln{}\left(\sqrt{\frac{9}{2} (x+\frac{1}{3})^{2}+1}+\frac{3}{2}\sqrt{2} \left(x+\frac{1}{3}\right)\right)+\frac{3}{4}\sqrt{2} \left(x+\frac{1}{3}\right) \sqrt{\frac{9}{2} (x+\frac{1}{3})^{2}+1}\right) +C $}

\item \label{problemintsqrt(x^2+1)/(x+1)dx}
$\displaystyle\int \frac{\sqrt{x^2+1}}{x+1}\diff x $

\answer{$ \begin{array}{l} -\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x+\sqrt{2}-1\right) \\
+\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x-\sqrt{2}-1\right)\\
+ \ln{} \left( \sqrt{x^{2}+1}- x\right)\\
+ \sqrt{x^{2}+1}
\end{array}
$}
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case1-solutions.tex
\solution{\ref{problemIntegratesqrt(x^2+1)dx}. 

This problem can be solved both via the Euler substitution and by transforming to a trigonometric integral and solving the trigonometric integral on its own. We present both variants. 


\ref{problemIntegratesqrt(x^2+1)dx}.\textbf{Variant I.}
We recall the Euler substitution for $ \sqrt{x^2+1 } $\refBad{\ref{eqEulerSub-case1-cot(2arctant)}}{}{  given in  \eqref{eqEulerSub-case1-cot(2arctant)}}:

$\begin{array}{rcl}
\displaystyle x&=&\displaystyle \frac{1}{2}\left(\frac{1}{t}-t\right)\\
\displaystyle \sqrt{x^2+1}&=&\displaystyle \frac{1}2\left(\frac 1 t +t\right)\\
\displaystyle \diff x&=&\displaystyle -\frac{1}{2} \left(\frac1{t^2} +1\right)\diff t\\
\displaystyle t&=&\displaystyle \sqrt{x^2+1}-x\quad .
\end{array}$

Therefore

\noindent$
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle\int \sqrt{(x^2+1)}\diff x&=&\displaystyle-\int  \frac14 \left(\frac1t +t\right)\left(\frac 1 {t^2} +1\right)\diff t\\
&=&\displaystyle -\frac 1 4\int \left( \frac{1}{t^3}+ 2\frac{1}t +t\right)\diff t\\
&=&\displaystyle -\frac{1}4 \left(- \frac{t^{-2}}{2}+ 2\ln|t|+ \frac{t^2}2 \right)+C\\
&=&\displaystyle\frac{1}{8}\left(t^{-2}-t^2\right) + \frac{1}{2}\ln |t|+C &&\begin{array}{l}a^2-b^2=\\(a-b)(a+b)\end{array}\\
&=&\displaystyle \frac{1}{2} \left( \underbrace {\frac{1}{2}\left(t^{-1}  -t \right) }_{=x} \right) \left(\underbrace{\frac{1}{2}\left(t^{-1}+t\right)}_{=\sqrt{x^2+1} } \right)+\frac{1}{2}\ln |t|+C\\
&=&\displaystyle \frac{1}{2} x\sqrt{x^2+1}-\frac{1}{2} \ln \left|\sqrt{x^2+1}-x\right|+C &&\text{See below}\\
&=&\displaystyle \frac{1}{2} x\sqrt{x^2+1}+\frac{1}{2} \ln \left(\sqrt{x^2+1}+x\right) +C\quad .
\end{array}
$

\noindent Our problem is solved.  

A few comments are in order. In the above expression we would have obtained a perfectly good answer to the problem if we plugged in $t=\sqrt{x^2+1}-x$ into the fourth line, however our answer would look much more complicated. Indeed, had we not used the formula $a^2-b^2=(a-b)(a+b)$ in the fourth line, the term $t^{-2}-t^{2}$ would be equal to $\frac{1}{(\sqrt{x^2+1}-x)^2}- (\sqrt{x^2+1}-x)^2$. In turn, the term $\frac{1}{(\sqrt{x^2+1}-x)^2}- (\sqrt{x^2+1}-x)^2$ can be simplified to $4x\sqrt{x^2+1}$ as follows. We note that the computations below are included here illustrate some of the algebraic issues arising when dealing with integrals of radicals.

\noindent$
\begin{array}{@{}r@{}c@{}l@{}}
\displaystyle t^{-2}-t^{2}&=&\displaystyle \frac{1}{(\sqrt{x^2+1}-x)^2}- (\sqrt{x^2+1}-x)^2\\
&=&\displaystyle
\frac{(\sqrt{x^2+1}+x)^2}{(\sqrt{x^2+1}-x)^2  (\sqrt{x^2+1}+x)^2 } \\
&&\displaystyle - (\sqrt{x^2+1}-x)^2 \\
&=&\displaystyle \frac{(\sqrt{x^2+1}+x)^2}{\underbrace{((\sqrt{x^2+1})^2-x^2)^2}_{=1} }- (\sqrt{x^2+1}-x)^2 \\
&=&\displaystyle 4x\sqrt{x^2+1}\quad .
\end{array}
$

Of course, the above computations are unnecessary if we use the formula $a^2-b^2=(a-b) (a+b)$ as done in the original solution. 

\noindent We note that in the last transformation we transformed $\ln \left| \sqrt{x^2+1}-x\right|$ to $\ln \left( \sqrt{ x^2+1}-x\right)$ because the quantity $\sqrt{x^2+1}-x$ is always positive. The proof of that fact we leave for the reader's exercise.

Finally, we note that as a last simplification to our solution, we used the transformation $\ln |t|= \ln \left( \sqrt{x^2+1} -x\right) = -\ln|\frac{1}{t}|= -\ln \left( \sqrt{x^2+1} +x \right)$. This is seen as follows.

\noindent $\begin{array}{rcll|l}
\displaystyle \ln |t|&=&\displaystyle  -\ln \left| \frac{1}{ t} \right| \\
&=&\displaystyle -\ln \left(\frac{1}{ \sqrt{x^2+1} - x} \right) && \text{rationalize}\\
&=&\displaystyle - \ln \left(\frac{ \left( \sqrt{x^2+1}+ x\right) }{\left( \sqrt{x^2+1} - x\right) \left(\sqrt{x^2+1 }+x\right) } \right)\\
&=& \displaystyle -\ln \left(\frac{\sqrt{x^2+1}+x}{x^2 +1 -x^2 }\right)\\
&=& \displaystyle  -\ln \left(\sqrt{x^2+1}+x\right)\quad .\\
\end{array}
$

\ref{problemIntegratesqrt(x^2+1)dx}. \textbf{Variant II.} In this variant we transform to a trigonometric integral and solve it using ad-hoc methods. We recall that if we decided to solve the trigonometric integral using the standard substitution $\theta=2\arctan t$, we would arrive at one of the Euler substitutions.

\noindent $
\begin{array}{@{}r@{~}c@{~}l@{}l@{}|l}
\displaystyle \int \sqrt{x^2+1}\diff x&=&\displaystyle \int \sqrt{\tan^2\theta+1}~\diff (\tan \theta) && \begin{array}{l} \text{Set }\\ x=\tan \theta \\ \theta\in \left(-\frac{\pi}{2}, \frac{\pi }{2}\right)\end{array}\\
&=&\displaystyle \int \sqrt{sec^2\theta}\sec^2\theta\diff \theta && \sec\theta>0\\
&=&\displaystyle \int \sec^3\theta\diff \theta&&\text{Problem } \refBad{\ref{problemintsec^3xdx}}{\text{solved already}}{\ref{problemintsec^3xdx}} \\
&=&\displaystyle \frac{1}{2}\left(\tan \theta \sec \theta+\ln|\sec\theta +\tan \theta | \right)+C&&
\begin{array}{@{}l}
\psset{xunit=0.3cm, yunit=0.3cm}
\begin{pspicture}(-0.8,-0.8)(4.6,3.2)
\tiny
\fcBoundingBox{-1}{-0.8}{4.6}{3.2}
\psline(0,0)(4, 0)(4,3)(0,0)
\psline(3.8,0)(3.8, 0.2)(4,0.2)
\fcAngle{0}{3 4 div ATAN}{0.8}{}
\rput[bl](1, 0.2){$\theta$}
\rput[l](4.2, 1.5){$x$}
\rput[t](2, -0.2){$1$}
\rput[br](2, 1.5){$\sqrt{x^2+1}$}
%bounding box for pdflatex compilation:
\psline[linecolor=red!1](-0.11, -0.3 )(-0.105, -0.3)
\psline[linecolor=red!1](2.3, 1.21)(2.3, 1.205)
\end{pspicture}\\
\sec\theta=\sqrt{x^2+1}\\
\tan \theta=x
\end{array}
\\
&=&\displaystyle \frac{1}{2}\left(x \sqrt{x^2+1} +\ln\left(\sqrt{x^2+1}+x \right) \right)+C
\end{array}
$

}

\solution{\ref{problemIntegrate sqrt(2x^2+2x+1)dx}
\[
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int \sqrt{\left(2x^2+2x+1\right)}\diff x &=&\displaystyle  \int \sqrt{2}\sqrt{\left(\left(x+\frac{1}{2}\right)^2+\frac{1}{4}\right)} \diff x &&\text{complete square}\\
&=&\displaystyle  \frac{\sqrt{2}}{2} \int \sqrt{\left( 4 \left( x + \frac{ 1}{2}\right)^2+1\right)}   \diff {}x\\
&=&\displaystyle  \frac{\sqrt{2}}{2}  \int \sqrt{\left( \left( 2x +1\right)^2+ 1\right)} \frac{1}{2}\diff {}\left(2x+1\right) &&\text{Set }u=2x+1 \\
&=&\displaystyle \frac{\sqrt{2}}{4} \int \sqrt{\left(u^2+1\right)}\diff {}u && \begin{array}{@{}l} \text{Euler subst.: } \\ u = \frac{1}{2}\left(\frac{1}{t}-t\right),\\ t> 0 \\~\\ \diff u = -\frac{1}{2}\left(\frac{1}{t^{2}}+1\right)\diff t \\~\\ \sqrt{u^2+1}= \frac{1}{2}\left(\frac{1}{t}+t\right)\\~\\ t= \sqrt{u^2+1}-u \end{array}\\
&=&\displaystyle - \frac{\sqrt{2} }{16} \int\left(\frac{1}{t}+t\right)\left(\frac{1}{t^2}+1 \right) \diff t\\
&=&\displaystyle - \frac{\sqrt{2} }{16} \int \left( t^{-3}+2t^{-1}+t\right)\diff t\\
&=&\displaystyle - \frac{\sqrt{2} }{16}  \left( -\frac{t^{-2}}{2} + 2\ln |t| + \frac{t^2}{2}\right)+C&& \begin{array}{@{}l}
\text{simplify as} \\
\text{in Problem \ref{problemIntegratesqrt(x^2+1)dx}}
\end{array}
\\
&=&\displaystyle \frac{\sqrt{2}}{8} \left( u\sqrt{u^2+1}+ \ln\left(\sqrt{u^2+1}+u \right) \right) +C \\
&=&\displaystyle \frac{\sqrt{2}}{8} \left( (2x+1)\sqrt{(2x+1)^2+1 }\right.\\
&&\displaystyle ~~~~~~ \left.+\ln \left( \sqrt{(2x+1)^2+1 }+2x+1\right) \right)+C.
\end{array}
\]
}

\solution{\ref{problemintsqrt(x^2+1)/(x+1)dx}

$\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int \frac{\sqrt{ x^2+1}}{x+1}\diff x&=& \displaystyle \int \frac{ \frac{1}{2}\left(\frac{1}{t}+t \right) }{ \frac{1}{2}\left(\frac{1}{t}-t \right)+1 }\diff \left(\frac{1}{2} \left(\frac{1}{t}-t \right) \right) &&\begin{array}{l}\text{Euler sub: }\\ \begin{array}{@{\!\!\!\!\!}r@{}c@{}l} x&=&\frac{1}{2}\left(\frac{1}{t}-t\right) \\
\sqrt{x^2+1}&=&\frac{1}{2}\left(\frac{1}{t}+t\right)
\end{array}\end{array}\\
&=&\displaystyle \int \left(\frac{1+t^2}{1-t^2+2t }\right)\frac{1}{2} \left(-t^{-2}-1 \right)\diff t\\
&=&\displaystyle \int \frac{1}{2} \frac{(1+t^2)\left(-t^{-2}-1 \right)}{1-t^2+2t } \diff t\\
&=&\displaystyle \frac{1}{2} \int \frac{ t^{4}+2 t^{2}+1}{ t^{4}-2 t^{3}-t^{2}} \diff t &&\text{pol. long div.}\\
&=&\displaystyle \frac{1}{2}\int \left(1+\frac{ 2t^{3}+ 3t^{2} +1}{ t^2\left(t^{2}-2 t-1\right)}\right) \diff t &&\text{part. fractions}\\
&=&\displaystyle \frac{1}{2}\int \left(1+ \frac{2\sqrt{2}}{t -\sqrt{2}-1}+\frac{-2\sqrt{2}}{t +\sqrt{2}-1}+\frac{2}{t }+\frac{-1}{t^{2}}\right)\diff t\\
&=&\displaystyle -\sqrt{2} \ln{}\left|t+\sqrt{2}-1\right|+\sqrt{2} \ln{}\left|t-\sqrt{2}-1\right|\\
&&\displaystyle+\frac{1}{2} t^{-1}+\ln{}\left|t\right|+\frac{1}{2} t +C&& t=\sqrt{x^2+1}-x\\
&=&\displaystyle -\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x+\sqrt{2}-1\right)\\
&&\displaystyle +\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x-\sqrt{2}-1\right)\\
&&\displaystyle + \ln{} \left( \sqrt{x^{2}+1}- x\right)\\
&&\displaystyle +\frac{1}{2} \left(\sqrt{x^{2}+1}- x\right)^{-1}+\frac{1}{2} \sqrt{x^{2}+1}-\frac{1}{2} x+C &&\begin{array}{l}\text{Last 3 terms}\\ \text{simplify}\end{array}\\
&=&\displaystyle -\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x+\sqrt{2}-1\right) \\
&&\displaystyle +\sqrt{2} \ln{}\left(\sqrt{x^{2}+1}- x-\sqrt{2}-1\right)\\
&&\displaystyle + \ln{} \left( \sqrt{x^{2}+1}- x\right)\\
&&+ \sqrt{x^{2}+1}+C\quad .

\end{array}
$

}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case1-integral-radical-quadratic.tex
\label{problemIntegrate sqrt(ax^2+bx+c)dx}
Let $b^2-4ac<0$ and $a>0$ be (real) numbers. Show that 

\noindent $
\int \sqrt{\left(ax^2+bx+c\right)}\diff x = \sqrt{a} D \left(\frac{1}{2} \ln{}\left( \frac{2\sqrt{D} a \sqrt{\left(\frac{2 x a+b}{2 \sqrt{D} a}\right)^{2}+1} +2 x a+b}{2 \sqrt{D} a}\right)+\frac{\frac{1}{2} \left(2 x a+b\right)}{2 \sqrt{D} a} \sqrt{\left(\frac{2 x a+b}{2 \sqrt{D} a}\right)^{2}+1}\right),
$

where 
$\displaystyle D=\frac{4ac-b^2}{4a^2}$.






\end{problem}
\subsection{Case 2: $\sqrt{1-x^2}$}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case2.tex
Integrate
\begin{enumerate}[ref={\fcProblemRef}]
\item  \label{problemintsqrt(1-x^2)dx}
$\displaystyle
\int \sqrt{1-x^2}\diff x$

\answer{$ $}
\item 
$\displaystyle
\int \sqrt{2-x^2}\diff x
$
\item 
$\displaystyle
\int \sqrt{-x^2+x+1}\diff x
$
\item 
$\displaystyle
\int \sqrt{2-x-x^2}\diff x
$

\item \label{problemintsqrt(1-x^2)/(1+x)dx}
$\displaystyle
\int \frac{\sqrt{1-x^2} }{1+x}\diff x
$
\item 
$\displaystyle
\int \frac{\sqrt{1-x^2} }{2+x}\diff x
$
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case2-solutions.tex
\solution{\ref{problemintsqrt(1-x^2)dx} 

\textbf{Variant I.} This integral is possibly fastest to solve directly using a trig substitution. In the next variant of the solution we show the Euler substitution.

\noindent $
\begin{array}{rcl@{}l@{}|l}
\displaystyle \int \sqrt{1-x^2}\diff x &=&\displaystyle  \int \sqrt{1-\cos^2\theta}\diff (\cos \theta) &&\text{Set }x=\cos \theta, \theta\in[0,\pi]\\
&=&\displaystyle \int \sqrt{\sin^2\theta } (-\sin \theta)\diff \theta &&\theta\in [0,\pi]\Rightarrow \sin \theta\geq 0\\
&=&\displaystyle -\int \sin^2\theta \diff \theta && \sin^2\theta= \frac{1-\cos (2\theta) }{2}\\
&=&\displaystyle-\int \frac{1-\cos (2\theta)}{2}\diff \theta\\
&=&\displaystyle - \frac{\theta}{2}+\frac{ \sin (2\theta)}{4}+C\\
&=&\displaystyle - \frac{\theta}{2}+\frac{ 2\sin \theta\cos \theta }{4}+C
&&
\begin{array}{@{}r@{}c@{}l}
x &=&\cos \theta\\
\theta &=&\Arccos x\\
\sin \theta&=&\sin \left(\Arccos x\right)\\
&=&\sqrt{1-x^2}
\end{array}
\\
&=&\displaystyle -\frac{\Arccos x}{2}+ \frac{x\sqrt{1-x^2} }{2} + C\\
&=&\displaystyle \frac{\Arcsin x}{2}+\frac{x\sqrt{1- x^2} }{2} + K\quad ,
\end{array}
$
where for the last equality we recall that the derivative of $\Arcsin x$ is minus the derivative of $\Arccos x$.



\textbf{Variant II.} We show how to do this integral via the Euler substitution $x=\cos (2\Arctan t)$.

$
\begin{array}{rcl@{}l@{}|l}
\displaystyle \int \sqrt{1-x^2}\diff x &=&\displaystyle  \int \sqrt{1-\cos^2\theta}\diff (\cos \theta) &&\begin{array}{@{}r@{}c@{}l} &&\text{Set }\\
x&=&\cos(2\Arctan t)\\
\frac{1}{2}\Arccos x&=&\Arctan t\\ 
x&=&\frac{1-t^2}{1+t^2}\\
&=& \frac{2}{1+t^2}-1\\
\sqrt{1-x^2}&=&\frac{2t}{1+t^2}\\
\end{array}\\
&=&\displaystyle \int \frac{2t}{1+t^2}\diff \left(\frac{1-t^2}{1+t^2} \right) \\
&=&\displaystyle \int \frac{2t}{1+t^2} \left(\frac{-4t}{\left(1+t^2\right)^2}\right)\diff t &&\begin{array}{l}
\text{Integral rational}\\
\text{function}\\
\text{we skip details}
\end{array} \\
&=&\displaystyle \frac{-t}{t^{2}+1}+\frac{2 t}{ \left(t^{2}+1\right)^{2}}\\
&&\displaystyle - \Arctan{}t+C \\
&=&\displaystyle -\frac{1}{2}\sqrt{1-x^2} +\frac{\sqrt{1-x^2}}{t^2+1} \\
&&- \Arctan t+C\\
&=&\displaystyle \frac{1}{2} \sqrt{1-x^2} \left(\frac{ 2}{ t^2 +1} -1\right)\\
&&-\Arctan t+C\\
&=&\displaystyle \frac{x\sqrt{1-x^2}}{2}-\frac{1}{2}\arccos x+C\\
&=&\displaystyle \frac{x\sqrt{1-x^2}}{2}+\frac{1}{2}\arcsin x+K,
\end{array}
$
where for the very last equality we used the fact that the derivatives of $\arcsin x$ and $\arccos x$ are negatives of one another.

\textbf{Variant III. } We show how to do this integral geometrically, provided already know the area of a sector of circle. Of course, here we assume we have already derived the formula for an area of a circle. We warn the reader that if we did use an integral to derive the formula for sector area, it is possible we are making a circular reasoning argument. The danger is of course not real we did the integral purely algebraically in the preceding solution variants. In this way, the present solution Variant is simply a geometric interpretation of the problem.

By the Fundamental Theorem of Calculus, the indefinite integral measures up to a constant the area locked under the graph of $\sqrt{1-x^2}$. This graph is a part of a circle. Therefore, up to a constant, $\int\sqrt{1-t^2}\diff t$ equals $\int_{0}^{x}\sqrt{1-t^2}\diff t$. In turn $\int_{0}^{x}\sqrt{1-t^2}\diff t$ is given by the area highlighted in the picture below.

\psset{xunit=2cm, yunit=2cm}
\begin{pspicture}
\tiny
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
\psplot[linecolor=\fcColorGraph]{0}{0.75}{1 x x mul sub sqrt}
\psline(! 0.75 1 0.75 0.75 mul sub sqrt)(0.75, 0)
\psline(0.75, 0)(0,0)
}
\fcAxesStandardNoFrame{-0.3}{-0.3}{1.2}{1.2}

\psplot[linecolor=\fcColorGraph, linewidth=1.5pt]{0}{0.75}{1 x x mul sub sqrt}
\psplot{0.75}{1}{1 x x mul sub sqrt}
\rput[t](0.75,-0.05){$P$}
\fcFullDot{0.75}{0}
\rput(0.375, -0.1){$x$}
\psline(0,0)(! 0.75 1 0.75 dup mul sub sqrt)(0.75, 0)
\rput[l](0.2, 0.5){$A$}
\rput[b](0.5, 0.2){$B$}
\rput[lb](0.45, 0.9){$\Arcsin x $}
\fcFullDot{0}{1}
\rput[r](-0.1, 1){$P$}
\rput[l](0.8, 0.3){$\sqrt{1-x^2}$} 
\rput[l](0.8, 0.65){$Q$}
\fcFullDot{0.75}{1 0.75 0.75 mul sub sqrt}
\rput[tr](-0.05, -0.05){$O$}
\end{pspicture}
\[
\begin{array}{rcll|l}
\text{Area}(A)&=&\displaystyle  \frac{\text{length }\left( \stackrel{\frown}{ PQ}
\right) }{2\pi } \pi= \frac{\text{length }\left(
\stackrel{\frown}{ PQ}
\right)}{2} = \frac{\Arcsin x}{2}\\
\text{Area}(B)&=&\displaystyle \text{Area}(\triangle OPQ)= \frac{x \sqrt{1-x^2} }{2}\\
\displaystyle \int_{0}^x\sqrt{1-t^2}\diff t&=&\displaystyle  \text{Area}(A)+\text{Area}(B)\\
&=&\displaystyle \frac{\Arcsin x}{2}+\frac{x\sqrt{1-x^2}}{2}\\
&\Rightarrow\\
\displaystyle\int\sqrt{1-x^2}\diff x&=&  \displaystyle \frac{\Arcsin x}{2} + \frac{x\sqrt{1-x^2}}{2}+C\quad .
\end{array}
\] 
}

\solution{\ref{problemintsqrt(1-x^2)/(1+x)dx} In this problem solution we use the standard Euler substitution $x=\cos (2\Arctan t)$. We recall \refBad{\ref{eqEulerSubx=cos(2arctant)}}{that}{from \eqref{eqEulerSubx=cos(2arctant)} that}

\noindent $\begin{array}{rcl}
\displaystyle x& =&\displaystyle \cos(2\Arctan t)= \frac{1-t^2}{1+t^2}\\
\Arccos (x)&=& 2 \Arctan t\\
\displaystyle \diff x &=&\displaystyle  -\frac{4t}{(1+t^2)^2}\diff t\\
\displaystyle \sqrt{1-x^2}&=&\displaystyle \sin (2\Arctan t)= \frac{2t}{1+t^2}\\
t&=&\displaystyle \frac{\sqrt{1-x^2}}{x+1}\quad .
\end{array}
$

\noindent $
\begin{array}{@{}r@{}c@{}l@{}l@{}|l}
\displaystyle \int  \frac{\sqrt{1-x^2}}{1+x}\diff x&=& \displaystyle \int t \left(-\frac{4t}{\left(1+t^2\right)^2} \right)\diff t&&\begin{array}{l} \text{Set }x=\frac{1-t^2}{1+t^2}\\
\text{Use f-las above}
\end{array}
\\
&=&\displaystyle -4\int\frac{t^2}{\left(1+t^2\right)^2}\diff t\\
&=&\displaystyle -4\int\frac{1+t^2-1}{\left(1+t^2\right)^2 }\diff t\\
&=&\displaystyle -4\int\left(\frac{1}{1+t^2} -\frac{1}{\left(1+t^2\right)^2}\right)\diff t\\
&=&\displaystyle -4\left(\Arctan t - \frac{1}{2}\left(\Arctan t+ \frac{t}{1+t^2} \right) \right)+C\\
&=&\displaystyle -2\left(\Arctan {}t - \frac{t}{1+t^2} \right) +C\\
&=&\displaystyle -2\left( \Arctan {}\left(\frac{\sqrt{1-x^2}}{1+x} \right) - \frac{1}{2}\sqrt{1-x^2} \right) +C\\
&=&\displaystyle -2 \Arctan {}t  +\sqrt{1-x^2} +C &&\text{Use f-las above}
\\
&=&\displaystyle -\Arccos x+ \sqrt{1-x^2}  +C\\
&=&\displaystyle \Arcsin x +\sqrt{1-x^2}+K\quad .
\end{array}
$

We have included the last equality to remind the student that derivatives of $\Arcsin(x)$ and $\Arccos x$ are negatives of one another.


}


\subsection{Case 3: $\sqrt{x^2-1}$}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case3.tex
Integrate
\begin{enumerate}[ref={\fcProblemRef}]
\item 
$\displaystyle
\int \sqrt{x^2-1}\diff x
$
\item 
$\displaystyle
\int \sqrt{x^2-2}\diff x
$
\item 
$\displaystyle
\int \sqrt{2x^2+x-1}\diff x
$
\item 
$\displaystyle
\int \sqrt{x^2+x-1}\diff x
$
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/integration-euler-substitution-case3-solutions.tex



\subsection{Theory through problems (Optional material)}
\subsection{Case 1: $\sqrt{x^2+1}$}
\subsubsection{$x=\cot \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=cott} Express $x, \diff x $ and $\sqrt{x^2+1 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\cot \theta $, $\theta\in \left(0,\pi\right)$.
\item \label{problemTheoreticalTrigSubx=cot(2arctant)} Express $x, \diff x $ and $\sqrt{x^2+1}$ via $t$ and $\diff t$ for the Euler substitution $x=\cot(2\arctan t)$, $t>0$. Express $t$ via $x$.
\end{enumerate}



\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=cott}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot-exposition-part-1.tex
The trigonometric substitution $x=\cot \theta$ is given by
\begin{equation*}
\begin{array}{rcll|l}
\displaystyle \sqrt{ x^2+1}&=&\displaystyle \sqrt{\cot^2 \theta+1}\\
&=&\displaystyle \sqrt{\frac{\cos^2\theta}{ \sin^2 \theta} + 1}\\
&=&\displaystyle \sqrt{ \frac{ \cos^2 \theta+\sin^2\theta}{ \sin^2 \theta}} \\
&=& \displaystyle  \sqrt{\frac{1}{\sin^2\theta}} && \begin{array}{l}\displaystyle \text{when }\theta\in \left(0 , \pi\right) \text{ we have }\\ ~ \sin \theta \geq 0\text{ and so } \sqrt{\sin^2 \theta}=\sin\theta  \end{array}\\
&=&\displaystyle  \frac{1}{\sin \theta}= \csc \theta\quad .
\end{array}
\end{equation*}
The differential $\diff x$ can be expressed via $\diff \theta$ from $x=\cot \theta$. The substitution $x=\cot \theta$ can be now summarized as:
\[
\begin{array}{rcl}
x&=&\displaystyle \cot \theta\\
\sqrt{x^2+1}&=&\displaystyle \frac{1}{\sin \theta}=\csc \theta\\
\diff x&=&\displaystyle  -\frac{\diff \theta}{\sin^2\theta} = - \csc^2 \theta \diff \theta\\
\theta& =& \Arccot x\quad .
\end{array}
\]


}
\solution{\ref{problemTheoreticalTrigSubx=cot(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cot-exposition-part-2.tex
We recall that the substitution $\theta=2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $\theta=2\arctan t$ after the substitution $x=\cot\theta$:
\[
\begin{array}{rcll|l}
x&=&\displaystyle \cot \theta &&\text{use } \theta=2\arctan t\\
&=& \displaystyle \cot \left(2\arctan t\right) &&\displaystyle  \text{use\refBad{\ref{eqSinCosViaTan}}{ }{ \eqref{eqSinCosViaTan}: }} \cot 2z=\frac{\cos (2z)}{\sin (2z)}=\frac{1-\tan^2z}{2\tan z } \\
&=&\displaystyle \frac{1-\tan^2 (\arctan t)}{2 \tan (\arctan t)} \\
&=&\displaystyle \frac{1-t^2}{2t}\\
&=&\displaystyle \frac{1}{2}\left(\frac{1}t -t\right)\quad .
\end{array}
\]
We can furthermore compute
\begin{equation} \label{eqsqrtx2plus1Euler2}
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2+1}&=& \displaystyle  \sqrt{ \frac{1}{4} \left(\frac{1}t -t \right)^2 +1}\\
&=&\displaystyle \frac{1}{2} \sqrt{\left( \frac{1}{t} +t \right)^2} & &\displaystyle \sqrt{\left(\frac{1}{t}+t\right)^2} = \frac{1}{t} +t \text{ because }t>0\\
&=&\displaystyle \frac{1}{2}\left(\frac{1}{t}+t\right)\quad .
\end{array}
\end{equation}
The differential $\diff x$ can via $\diff x $ as follows.
\[
\diff x=\diff \left(\frac{1}{2} \left( \frac{1}{t} - t\right)\right) = -\frac{1}{2} \left(\frac{1}{t^2}-1\right)\quad .
\]
Finally, we can subtract $\displaystyle x=\frac{1}{2} \left( \frac{1}{t} - t\right)$ from  $\displaystyle \sqrt{x^2+1}= \frac{1}{2} \left( \frac{1 }{ t} +t\right)$ to get that \[t=\sqrt{x^2+1}-x \quad .\]
The Euler substitution $x=\cot \theta= \cot (\arctan 2t)$ can be now summarized as:
\begin{equation}\label{eqEulerSub-case1-cot(2arctant)}
\begin{array}{rcl}
x&=&\displaystyle \frac12\left(\frac{1}{t}- t\right)\\
\displaystyle\sqrt{x^2+1}&=& \displaystyle \frac12 \left(\frac1t +t\right)\\
\displaystyle \diff x&=&\displaystyle -\frac12\left(\frac{1}{t^2}+1\right) \diff t\\
t &=&\sqrt{x^2+1}-x\quad .
\end{array}
\end{equation}

}



\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cot.tex
\label{problemEulerSub-case1-cot(2arctant)-alternative-exposition}
Let the variables $x$ and $t$ be related via $\sqrt{x^2+1}=x+t$.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemEulerSub-case1-cot(2arctant)-alternative-exposition-x-via-t} Express $x$ via $t$.
\item \label{problemEulerSub-case1-cot(2arctant)-alternative-exposition-radical-via-t} Express $\sqrt{x^2+1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}

\end{problem} 

%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cot-solution.tex
\solution{\ref{problemEulerSub-case1-cot(2arctant)-alternative-exposition-x-via-t}.
\[
\begin{array}{rcll|l}
\sqrt{x^2+1}&=& x+t &&\text{square both sides}  \\
x^2+1&=&x^2+2xt+t^2\\
-2xt&=&t^2-1\\
x&=&\displaystyle\frac{1}{2}\left(\frac{1}{t}-t \right) \quad .
\end{array}
\]
}

\solution{\ref{problemEulerSub-case1-cot(2arctant)-alternative-exposition-radical-via-t}. 

Use Problem \ref{problemEulerSub-case1-cot(2arctant)-alternative-exposition-x-via-t} to get:
\[
\sqrt{x^2+1}= x+t = \frac{1}{2}\left(\frac{1}{t}-t \right)+t=\frac{1}{2}\left(\frac{1}{t}+t \right)\quad.
\]

}




\subsubsection{$x=\tan \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=tant} Express $x, \diff x $ and $\sqrt{x^2+1 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\tan \theta $, $\theta\in \left(-\frac{\pi}{2},\frac{\pi}{2}\right)$.
\item \label{problemTheoreticalTrigSubx=tan(2arctant)} Express $x, \diff x $ and $\sqrt{x^2+1}$ via $t$ and $\diff t$ for the Euler substitution $x=\tan(2\Arctan t)$, $t\in(-1,1)$. Express $t$ via $x$.
\end{enumerate}



\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=tant}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan-exposition-part-1.tex
The trigonometric substitution $x=\tan \theta$ is given by
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{ x^2+1}&=&\displaystyle \sqrt{\tan^2 \theta+1}\\
&=&\displaystyle   \sqrt{ \frac{ \sin^2 \theta}{ \cos^2 \theta} +1}\\
&=&\displaystyle \sqrt{ \frac{ \sin^2\theta+\cos^2 \theta}{ \cos^2 \theta}} \\
&=& \displaystyle \sqrt{\frac{1}{\cos^2\theta}} && \begin{array}{l} \displaystyle \text{when }\theta\in \left(-\frac{\pi}{2}, \frac{\pi}{2}\right) \text{ we have }\\ ~ \cos \theta > 0\text{ and so } \sqrt{\cos^2 \theta}=\cos\theta \end{array}\\
&=&\displaystyle  \frac{1}{\cos \theta}= \sec \theta\quad .
\end{array}
\]
The differential $\diff x$ can be expressed via $\diff \theta$ from $x=\tan \theta$. The substitution $x=\tan \theta$ can be now summarized as:
\[
\begin{array}{rcl}
x&=&\displaystyle \tan \theta\\
\sqrt{x^2+1}& =& \displaystyle \frac{1}{\cos \theta}=\sec \theta\\
\diff x &=&\displaystyle \frac{\diff \theta}{\cos^2\theta}= \sec^2 \theta \diff \theta\\
\theta& =& \arctan x\quad .
\end{array}
\]


}
\solution{\ref{problemTheoreticalTrigSubx=tan(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-tan-exposition-part-2.tex
We recall that the substitution $\theta=2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $\theta=2\arctan t$ after the substitution $x=\tan\theta$:
\[
\begin{array}{rcll|l}
x&=&\displaystyle \tan \theta &&\text{use } \theta=2\arctan t \\
&=&\displaystyle \tan \left(2\arctan t\right)&&\displaystyle  \text{use\refBad{\ref{eqSinCosViaTan}}{}{ \eqref{eqSinCosViaTan}}: } \tan 2z=\frac{\sin (2z)}{\cos (2z)}=\frac{2\tan z}{1-\tan^2 z}\\
&=&\displaystyle \frac{2\tan (\arctan t)}{1-\tan^2 (\arctan t)}\\
&=&\displaystyle \frac{2t}{1-t^2}\quad .
\end{array}
\]
We can furthermore compute
\begin{equation}\label{eqsqrtx2plus1Euler1}
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2+1}&=&\displaystyle  \sqrt{ \left( \frac{ 2t}{1-t^2}\right)^2+1 }\\
&=&\displaystyle \sqrt{\frac{4t^2+(1-t^2)^2}{(1-t^2)^2} }\\
&=&\displaystyle \sqrt{\frac{(1+t^2)^2}{(1-t^2)^2}} && \sqrt{(1-t^2)^2 } = 1-t^2  \text{ because } |t|<1\\
&=&\displaystyle \frac{1+t^2}{1-t^2}\\
&=&\displaystyle \frac{2-(1-t^2)}{1-t^2}\\
&=&\displaystyle -1+ \frac{2 }{1-t^2 } \quad .
\end{array}
\end{equation}
From $\displaystyle \sqrt{x^2+1}=-1+\frac{2}{1-t^2}$ and $\displaystyle x=\frac{2t}{1-t^2}$ we can express $t$ via $x$:
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2+1}&=&\displaystyle -1+ \frac{2}{ 1 - t^2 }\\
&=&\displaystyle -1+\frac{1}{t}\left(\frac{2t}{1 -t^2} \right) &&\displaystyle \text{use } x= \frac{2t}{1-t^2}\\
&=&\displaystyle -1+\frac{x}{t}\\
\displaystyle 1+\sqrt{x^2+1}&=&\displaystyle \frac{x}{t}\\
\displaystyle t&=&\displaystyle \frac{x}{1+\sqrt{x^2+1}}\\ &=& \displaystyle \frac{x}{1+\sqrt{x^2+1}} \left(\frac{ 1-\sqrt{x^2+1} }{1 - \sqrt{ x^2+1}}\right)\\
&=& \displaystyle  \frac{x(1- \sqrt{x^2 +1 } ) }{ 1- x^2-1}\\
&=&\displaystyle \frac{\sqrt{x^2+1}-1}{x}\quad .
\end{array}
\]
The differential $\diff x$ can expressed via $\diff t$ from $\displaystyle x=1+ \frac{2 }{t^2 -1}$. The Euler substitution  $x=\tan \theta=\tan (2\arctan t)$ can now be summarized as follows.
\begin{equation}\label{eqEulerSub-case1-tan(2arctant)}
\begin{array}{rcl}
x&=&\displaystyle \frac{2t}{1-t^2}\\
\displaystyle\sqrt{x^2+1}&=& \displaystyle -1+ \frac{2 }{1-t^2} \\
\displaystyle \diff x&=&\displaystyle \frac{2(1+t^2)} {(1-t^2)^2} \diff t\\
t &=&\displaystyle \frac{\sqrt{x^2+1}-1}{x}\quad .
\end{array}
\end{equation}

}


\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-tan.tex
Let the variables $x$ and $t$ be related via $\sqrt{x^2+1}=\frac{x}{t}-1$.
\begin{enumerate}
\item Express $x$ via $t$.
\item Express $\sqrt{x^2+1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}

\end{problem} 

\subsection{Case 2: $\sqrt{1-x^2}$}
\subsubsection{$x=\cos \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-cos.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=cost} Express $x, \diff x $ and $\sqrt{1-x^2 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\cos \theta $, $\theta\in \left[0, \pi\right]$.
\item \label{problemTheoreticalTrigSubx=cos(2arctant)} Express $x, \diff x $ and $\sqrt{1-x^2}$ via $t$ and $\diff t$ for the Euler substitution $x=\cos(2\Arctan t)$, $t\geq 0$. Express $t$ via $x$.
\end{enumerate}



\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-cos-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=cost}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cos-exposition-part-1.tex
The trigonometric substitution $x=\cos \theta$ is given by
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{-x^2+1}&=&\displaystyle \sqrt{1-\cos^2\theta}\\
&=&\displaystyle \sqrt{\sin^2\theta} &&\begin{array}{l} \text{when }\theta\in\left[0,\pi \right] \text{we have}\\
\sin \theta\geq 0 \text{ and so } \sqrt{\sin^2\theta}=\sin \theta
\end{array} \\
&=&\displaystyle \sin \theta\quad .
\end{array}
\]
The differential $\diff x$ can be expressed via $\diff \theta$ from $x=\cos \theta$. The substitution $x=\cos \theta $ can be now summarized as:
\begin{equation*}
\begin{array}{rcl}
x&=&\cos \theta\\
\sqrt{-x^2+1}&=&\sin \theta\\
\diff x&=& -\sin \theta \diff \theta\\
\theta&=&\arccos x \quad .
\end{array}
\end{equation*}


}
\solution{\ref{problemTheoreticalTrigSubx=cos(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-cos-exposition-part-2.tex
We recall that the substitution $\theta = 2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $2\arctan t$ after the substitution $x=\cos \theta$:

\begin{equation*}
\begin{array}{rcll|l}
x&=&\displaystyle \cos \theta &&\text{use } \theta=2\arctan t\\
&=&\displaystyle \cos (2\arctan t) &&\text{use\refBad{\ref{eqSinCosViaTan}}{ }{\eqref{eqSinCosViaTan}: }}\displaystyle \cos (2z) = \frac{ 1-\tan^2 z }{1+ \tan^2 z}\\
&=&\displaystyle \frac{1-\tan^2(\arctan t)}{1+\tan^2( \arctan t)} \\
&=&\displaystyle \frac{1-t^2}{1+t^2} \quad .
\end{array}
\end{equation*}
We can furthermore compute
\begin{equation}\label{eqsqrt1minusxsquaredE2}
\begin{array}{rcll|l}
\sqrt{-x^2+1 }&=&\displaystyle \sqrt{1- \left(\frac{1-t^2}{1+t^2}\right)^2}\\
&=&\displaystyle \sqrt{\frac{(1+t^2)^2-(1-t^2)^2}{(1+t^2)^2} }\\
&=&\displaystyle \sqrt{\frac{4t^2}{(1+t^2)^2}} &&\displaystyle \sqrt{4t^2}=2t\text{ because } t\geq 0\\
&=&\displaystyle \frac{2t}{1+t^2}\quad .\\
\end{array}
\end{equation}
The differential $\diff x$ can be computed from $x=\frac{1-t^2}{1+t^2}$. Finally, we can express $t$ via $x$ with a little algebra:

\[
\begin{array}{rcll|l}
\displaystyle x&=&\displaystyle \frac{1-t^2}{1+t^2}\\
\displaystyle (1+t^2)x&=&\displaystyle 1-t^2\\
\displaystyle t^2(x+1)&=&\displaystyle 1-x\\
\displaystyle t^2&=&\displaystyle \frac{1-x}{1+x}\\
\displaystyle t&=&\displaystyle \sqrt{\frac{1-x}{1+x}}&& \text{here we use } t>0\\
\displaystyle t&=&\displaystyle \frac{\sqrt{1-x}}{\sqrt{ 1+x}} \frac{ \sqrt{1+x}}{\sqrt{1+x}} \\
\displaystyle t&=&\displaystyle \frac{\sqrt{-x^2+1}}{x+1}\quad .
\end{array}
\]
The Euler substitution $x= \cos (2\Arctan t)$ can be now summarized as:
\begin{equation}\label{eqEulerSubx=cos(2arctant)}
\begin{array}{rcl}
x&=&\displaystyle \frac{1-t^2}{1+t^2}\\
\sqrt{-x^2+1}&=&\displaystyle \frac{2t}{1+t^2}  \\
\diff x&=&\displaystyle  -\frac{4 t}{(t^{2}+1)^{2}} \diff t\\
t&=&\displaystyle \frac{\sqrt{-x^2+1}}{x+1} \quad .
\end{array}
\end{equation}

}



\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cos.tex
Let the variables $x$ and $t$ be related via $\sqrt{-x^2+1}= ( 1-x)t$.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemEulerSub-case1-cos(2arctant)-alternative-exposition-x-via-t} Express $x$ via $t$.
\item \label{problemEulerSub-case1-cos(2arctant)-alternative-exposition-radical-via-t} Express $\sqrt{-x^2+1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}


\end{problem} 

%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-cos-solution.tex
\solution{\ref{problemEulerSub-case1-cos(2arctant)-alternative-exposition-x-via-t}.
\[
\begin{array}{rcll|l}
\sqrt{-x^2+1}&=&(1-x)t&&\text{square both sides}\\
(1-x)(1+x)&=&(1-x)^2t^2&&\text{divide by } (1-x)\\
1+x&=&(1-x)t^2\\
x(1+t^2)&=&t^2-1\\
x&=&\displaystyle \frac{t^2-1}{t^2+1}= 1-\frac{2}{t^2+1}\quad .
\end{array}
\]

}

\solution{\ref{problemEulerSub-case1-cos(2arctant)-alternative-exposition-radical-via-t}.

Use Problem \ref{problemEulerSub-case1-cos(2arctant)-alternative-exposition-x-via-t} to get
\[
\sqrt{-x^2+1}=(1-x)t=\left(1-\left(1-\frac{2t}{t^2+1}\right)\right)t= \frac{ 2t}{ t^2+1}\quad .
\]

}






\subsubsection{$x=\sin \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sin.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=sint} Express $x, \diff x $ and $\sqrt{1-x^2 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\sin \theta $, $\theta\in \left[-\frac{\pi}{2}, \frac{\pi}{2}\right]$.
\item \label{problemTheoreticalTrigSubx=sin(2arctant)} Express $x, \diff x $ and $\sqrt{1-x^2}$ via $t$ and $\diff t$ for the Euler substitution $x=\sin(2\Arctan t)$, $t\in[-1,1]$. Express $t$ via $x$.
\end{enumerate}



\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sin-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=sint}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-sin-exposition-part-1.tex
The trigonometric substitution $x=\sin \theta$ is given by
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{-x^2+1}&=&\displaystyle \sqrt{1-\sin^2\theta}\\
&=&\displaystyle \sqrt{\cos^2\theta} &&\begin{array}{l} \text{when }\theta\in\left[-\frac{\pi}{2}, \frac{\pi}{2} \right] \text{we have}\\
\cos \theta\geq 0 \text{ and so } \sqrt{\cos^2\theta}=\cos \theta
\end{array} \\
&=&\displaystyle \cos \theta\quad .
\end{array}
\]
The differential $\diff x$ can be expressed via $\diff \theta$ from $x=\sin \theta$. The substitution $x=\sin \theta $ can be now summarized as:
\begin{equation*}
\begin{array}{rcl}
x&=&\sin \theta\\
\sqrt{-x^2+1}&=&\sin \theta\\
\diff x&=& \cos \theta \diff \theta\\
\theta&=&\arcsin x \quad .
\end{array}
\end{equation*}


}
\solution{\ref{problemTheoreticalTrigSubx=sin(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-sin-exposition-part-2.tex
We recall that the substitution $\theta = 2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $2\arctan t$ after the substitution $x=\sin \theta$:

\begin{equation*}
\begin{array}{rcll|l}
x&=&\displaystyle \sin \theta &&\text{use } \theta=2\arctan t\\
&=&\displaystyle \sin (2\arctan t) &&\text{use} \refBad{\ref{eqSinCosViaTan}}{~}{\eqref{eqSinCosViaTan}: } \displaystyle \sin (2z) = \frac{ 2 \tan z}{1+ \tan^2 z}\\
&=&\displaystyle \frac{2\tan(\arctan t)}{1+\tan^2( \arctan t)} \\
&=&\displaystyle \frac{2t}{1+t^2} \quad .
\end{array}
\end{equation*}
We can furthermore compute
\begin{equation}\label{eqsqrt1minusxsquaredE1}
\begin{array}{rcll|l}
\sqrt{-x^2+1 }&=&\displaystyle \sqrt{1- \left(\frac{2t}{1+t^2}\right)^2}\\
&=&\displaystyle \sqrt{\frac{(1+t^2)^2-4t^2}{(1+t^2)^2} }\\
&=&\displaystyle \sqrt{\frac{(1-t^2)^2}{(1+t^2)^2}} &&\displaystyle \sqrt{(1-t^2)^2}=1-t^2\text{ because } |t|\leq 1\\
&=&\displaystyle \frac{1-t^2}{1+t^2}\\
&=&\displaystyle \frac{2-(1+t^2) }{1+t^2}\\
&=&\displaystyle -1+\frac{2}{1+t^2}\quad .
\end{array}
\end{equation}
The differential $\diff x$ can be computed from $x=\frac{2t}{1+t^2}$. Finally, we can express $t$ via $x$ with a little algebra:

\[
\begin{array}{rcll|l}
\displaystyle \sqrt{-x^2+1}&=&\displaystyle -1 + \frac{2}{ 1+ t^2} \\
&=& \displaystyle  -1 +\frac{1 }{t} \left( \frac{2t}{1+t^2}\right) &&\text{use } x= \frac{2t}{1+t^2}\\
&=&\displaystyle -1 +\frac{x}{t} &&+1 \text{ to both sides}\\
\displaystyle \frac{x}{t}&=&1+\displaystyle \sqrt{-x^2+1}\\
t&=&\displaystyle \frac{x}{1+\sqrt{-x^2+1}}\\ &=&\displaystyle\frac{x}{(1+\sqrt{-x^2+1})} \frac{(1-\sqrt{- x^2+ 1})}{(1 - \sqrt{ -x^2+1})} \\
&=&\displaystyle \frac{ 1-\sqrt{-x^2+1}}{x} \quad .
\end{array}
\]

The Euler substitution $x= \sin (2\arctan t)$ can be now summarized as:

\[
\begin{array}{rcl}
x&=&\displaystyle \frac{2t}{1+t^2}\\
\sqrt{-x^2+1}&=&\displaystyle -1+\frac{2}{1+t^2}  \\
\diff x&=&\displaystyle  2\left(\frac{1-t^2 }{(1+ t^2)^2} \right) \diff t\\
t&=&\displaystyle \frac{ 1-\sqrt{-x^2+1}}{x} \quad .
\end{array}
\]

}



\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sin.tex
Let the variables $x$ and $t$ be related via $\sqrt{-x^2+1}=1-xt$.
\begin{enumerate}
\item \label{problemEulerSub-case1-sin(2arctant)-alternative-exposition-x-via-t}  Express $x$ via $t$.
\item \label{problemEulerSub-case1-sin(2arctant)-alternative-exposition-radical-via-t} Express $\sqrt{-x^2+1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}

\end{problem} 

\subsection{Case 3: $\sqrt{x^2-1}$}
\subsubsection{$x=\sec \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sec.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=sect} Express $x, \diff x $ and $\sqrt{x^2-1 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\csc \theta $, $\theta\in \left[0, \frac{\pi}{2}\right]\cup \left[\pi, \frac{3\pi}{2} \right) $.
\item \label{problemTheoreticalTrigSubx=sec(2arctant)} Express $x, \diff x $ and $\sqrt{1-x^2}$ via $t$ and $\diff t$ for the Euler substitution $x=\sec(2\Arctan t)$, $t\in (-\infty, -1)\cup[1,0)$. Express $t$ via $x$.
\end{enumerate}


\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-sec-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=sect}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-sec-exposition-part-1.tex
The trigonometric substitution $x=\sec \theta$ is given by
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2-1}&=&\displaystyle \sqrt{\sec^2\theta-1}=\sqrt{\frac{1}{\cos^2\theta}-1}\\
&=&\displaystyle \sqrt{\frac{\sin^2\theta}{\cos^2\theta}} =\sqrt{ \tan^2 \theta} &&\begin{array}{l} \text{when }\theta\in \theta \in \left[0, \frac{ \pi}{2 }\right)\cup \left[\pi, \frac{3\pi}{2}\right) \text{we have}\\
\tan \theta\geq 0 \text{ and so } \sqrt{\tan^2\theta}=\tan \theta
\end{array} \\
&=&\displaystyle \tan \theta\quad .
\end{array}
\]
The differential $\diff x$ can be expressed via $\diff \theta $ from $x=\sec \theta$. The substitution $x=\sec \theta $ can be now summarized as:
\begin{equation*}
\begin{array}{rcl}
\displaystyle x&=&\displaystyle \sec\theta= \frac{1}{\cos \theta}\\
\displaystyle \sqrt{x^2-1}& =&\displaystyle  \tan \theta\\
\displaystyle \diff x&=&\displaystyle \frac{\sin\theta}{ \cos^2\theta} \diff \theta= \sec\theta\tan\theta  \diff \theta\\
\displaystyle \theta&=&\Arcsec x \quad .
\end{array}
\end{equation*}


}
\solution{\ref{problemTheoreticalTrigSubx=sec(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-sec-exposition-part-2.tex
We recall that the substitution $\theta = 2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $2\arctan t$ after the substitution $x=\sec \theta$:

\begin{equation*}
\begin{array}{rcll|l}
x&=&\displaystyle \sec \theta=\frac{1}{\cos \theta} && \text{use } \theta =2 \arctan t\\
&=&\displaystyle \frac{1} {\cos(2\arctan t)} && \text{use\refBad{\ref{eqSinCosViaTan}}{ }{ \eqref{eqSinCosViaTan}: }} \displaystyle \cos (2z) = \frac{ 1- \tan^2 z}{1+ \tan^2 z}\\
&=& \displaystyle \frac{1+\tan^2(\arctan t)}{1-\tan^2( \arctan t)} \\
&=&\displaystyle \frac{1+t^2}{1-t^2}\\
&=&\displaystyle-1+\frac{2}{1-t^2} \quad .
\end{array}
\end{equation*}
We can furthermore compute
\begin{equation}\label{eqsqrtxsquareminus1E2}
\begin{array}{rcll|l}
\sqrt{x^2-1 }&=&\displaystyle \sqrt{ \left(\frac{1+t^2}{1-t^2}\right)^2-1}\\
&=& \displaystyle \sqrt{\frac{(1+t^2)^2-(1-t^2)^2}{(1-t^2)^2} }\\
&=& \displaystyle \sqrt{\frac{4t^2}{(1-t^2)^2}} && \begin{array}{l} \displaystyle t \text{ and }1-t^2\text{ have the same}\\ \text{sign for } t\in (-\infty, -1) \cup \left[0, 1 \right)\end{array} \\
&=&\displaystyle \frac{2t}{1-t^2}\quad .
\end{array}
\end{equation}
The differential $\diff x$ can be computed from $x=\frac{1+t^2}{1-t^2}$. Finally, we can express $t$ via $x$ with a little algebra:
\[
\begin{array}{rcll|l}
\displaystyle x&=&\displaystyle  \frac{1+t^2}{ 1- t^2} \\
\displaystyle (1- t^2)x&=&\displaystyle  1+t^2\\
\displaystyle (1+ x)t^2&=&\displaystyle  x-1\\
\displaystyle t^2&=&\displaystyle  \frac{x-1}{x+1}\\
\\
\displaystyle t&=&\displaystyle \doublebrace{ \sqrt{\frac{x-1}{x+1}}}{x>1}{-\sqrt{\frac{x-1}{x+1}}}{x<-1} &&\begin{array}{l} \text{because when } x<-1, \\ \text{ we have } t\in \left( -\infty , -1 \right]\end{array} \\
\displaystyle t&=&\displaystyle \doublebrace{ \frac{\sqrt{ x^2 -1}}{x+1}}{x>1}{-\frac{\sqrt{x^2-1}}{x+1}}{x<-1}  \quad .
\end{array}
\]
The Euler substitution $x= \sec (2\arctan t)$ can be now summarized as:

\[
\begin{array}{rcl}
x&=&\displaystyle \frac{1+t^2}{1-t^2}\\
\sqrt{x^2-1}&=&\displaystyle \frac{2t}{1-t^2}  \\
\diff x&=&\displaystyle  \frac{4 t}{(1- t^{2})^{2}} \diff t\\
t&=&\displaystyle \pm \frac{ \sqrt{x^2-1}}{x+1} \quad .
\end{array}
\]

}



\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sec.tex
Let the variables $x$ and $t$ be related via $\sqrt{x^2-1}=(x+1)t$.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemEulerSub-case1-sec(2arctant)-alternative-exposition-x-via-t}  Express $x$ via $t$.
\item \label{problemEulerSub-case1-sec(2arctant)-alternative-exposition-radical-via-t} Express $\sqrt{x^2-1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}


\end{problem} 

%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-sec-solution.tex
\solution{\ref{problemEulerSub-case1-sec(2arctant)-alternative-exposition-x-via-t}.

\[
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2-1}&=&\displaystyle (x+1)t&&\text{square both sides}\\
\displaystyle (x-1)(x+1)&=&\displaystyle (x+1)^2t^2&&\text{divide by } (x+1)\\
\displaystyle x-1&=&\displaystyle (x+1)t^2\\
\displaystyle x(1-t^2)&=&\displaystyle 1+t^2\\
\displaystyle x&=& \displaystyle \frac{1+t^2}{1-t^2}= -1+\frac{2}{1-t^2}
\end{array}
\]
}
\solution{\ref{problemEulerSub-case1-sec(2arctant)-alternative-exposition-radical-via-t}. 

We use Problem \ref{problemEulerSub-case1-sec(2arctant)-alternative-exposition-x-via-t} to get
\[
\sqrt{x^2-1}=(x+1)t=\left(-1+\frac{2}{1-t^2}+1\right)t=\frac{2t}{1-t^2}
\]
}



\subsubsection{$x=\csc \theta$}
\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-csc.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemTheoreticalTrigSubx=csct} Express $x, \diff x $ and $\sqrt{1-x^2 }$ via $\theta$ and $\diff \theta$ for the trigonometric substitution $x=\csc \theta $, $\theta\in \left[0, \frac{\pi}{2}\right]\cup \left[\pi, \frac{3\pi}{2}\right)$.
\item \label{problemTheoreticalTrigSubx=csc(2arctant)} Express $x, \diff x $ and $\sqrt{1-x^2}$ via $t$ and $\diff t$ for the Euler substitution $x=\csc(2\Arctan t)$, $t\in(-\infty, -1)\cup [0,1)$. Express $t$ via $x$.
\end{enumerate}


\end{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case2-csc-solution.tex
\solution{\ref{problemTheoreticalTrigSubx=csct}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-csc-exposition-part-1.tex
The trigonometric substitution $x=\csc \theta$ is given by
\[
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2-1}&=&\displaystyle \sqrt{\frac{1}{\sin^2\theta}-1}\\
&=&\displaystyle \sqrt{\frac{\cos^2\theta}{\sin^2\theta}}=\sqrt{\cot^2 \theta} &&\begin{array}{l} \text{when }\theta\in \theta \in \left[0, \frac{\pi}{2}\right)\cup \left[\pi, \frac{3\pi}{2}\right) \text{we have}\\
\cot \theta\geq 0 \text{ and so } \sqrt{\cot^2\theta}=\tan \theta
\end{array}  \\
&=&\displaystyle \cot \theta\quad .
\end{array}
\]
The differential $\diff x$ can be expressed via $\diff \theta$ from $x=\csc \theta$. The substitution $x=\csc \theta $ can be now summarized as:
\begin{equation*}
\begin{array}{rcl}
x&=&\displaystyle \csc \theta\\
\sqrt{x^2-1}&=&\displaystyle \cot \theta\\
\diff x&=&\displaystyle  -\frac{\cos \theta }{\sin^2 \theta} \diff \theta = -\csc\theta \cot\theta \diff \theta\\
\theta&=&\displaystyle \Arccsc x \quad .
\end{array}
\end{equation*}


}
\solution{\ref{problemTheoreticalTrigSubx=csc(2arctant)}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/trig-and-euler-substitution-theory-case1-csc-exposition-part-2.tex
We recall that the substitution $\theta = 2\arctan t$ transforms a trigonometric integral into an integral of a rational function. We now apply the substitution $2\arctan t$ after the substitution $x=\csc \theta$:
\begin{equation*}
\begin{array}{rcll|l}
x&=&\displaystyle \csc \theta =\frac{1}{\sin \theta} & & \text{use } \theta=2\arctan t\\
&=&\displaystyle \frac{1}{\sin (2\arctan t)} && \text{use\refBad{\ref{eqSinCosViaTan}}{ }{\eqref{eqSinCosViaTan}: }} \displaystyle \sin (2z) = \frac{ 2\tan z }{1+ \tan^2 z}\\
&=&\displaystyle \frac{1+\tan^2(\arctan t)}{2\tan( \arctan t)} \\
&=&\displaystyle \frac{1+t^2}{2t} \\
&=&\displaystyle \frac{1}{2}\left(\frac{1}t+t\right)\quad .
\end{array}
\end{equation*}
We can furthermore compute
\begin{equation}\label{eqsqrtxsquareminus1E1}
\begin{array}{rcll|l}
\sqrt{x^2-1 }&=&\displaystyle \sqrt{ \left( \frac{1+t^2}{ 2t } \right)^2 -1}\\
&=& \displaystyle \sqrt{\frac{(1+t^2)^2-4t^2 }{ 4t^2} }\\
&=&\displaystyle \sqrt{\frac{(1-t^2)^2}{4t^2}} &&\displaystyle \frac{1-t^2}{2t}>0\text{ when } t\in (-\infty, -1) \cup \left[0, 1 \right)  \\
&=&\displaystyle \frac{1-t^2}{2t}\\
&=&\displaystyle\frac{1}{2}\left(\frac{1}{t}-t\right)\quad .\\
\end{array}
\end{equation}
The differential $\diff x$ can be computed from $x=\frac{1}{2}\left(\frac{1}{t}-t\right)$. Finally, we can express $t$ via $x$ with a little algebra:

\[
\begin{array}{rcll|l}
\displaystyle \sqrt{x^2-1 }&=&\displaystyle \frac{1-t^2}{2t}\\
\displaystyle \sqrt{x^2-1 }&=&\displaystyle \frac{2-(1+t^2)}{2t} &&\displaystyle \text{use } x=\frac{1+t^2}{2t}\\
\displaystyle \sqrt{x^2-1}&=&\displaystyle \frac{1}{t}-x\\
\displaystyle \frac{1}{t}&=&\displaystyle \sqrt{x^2-1}+x\\
t&=& \displaystyle \frac{1}{\sqrt{x^2-1}+x}= \frac{1}{(\sqrt{x^2-1}+x)} \frac{ (-\sqrt{x^2-1}+x)} {(-\sqrt{x^2-1}+x)}\\
t&=&\displaystyle x-\sqrt{x^2-1}
\end{array}
\]
The Euler substitution $x= \cos (2\arctan t)$ can be now summarized as:
\[
\begin{array}{rcl}
x&=&\displaystyle \frac{1}{2}\left(\frac{1}{t}+t\right)\\
\sqrt{-x^2+1}&=&\displaystyle\frac12 \left(\frac{1}{t} - t \right) \\
\diff x&=&\displaystyle  -\frac{1}{2}\left(\frac{1}{t^2}+1\right) \diff t\\
t&=&\displaystyle x-\sqrt{x^2-1}\quad .
\end{array}
\]

}



\begin{problem} 
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/trig-substitution/homework/euler-substitution-theory-alternative-case1-csc.tex
Let the variables $x$ and $t$ be related via $\sqrt{x^2-1}=\frac{1}{t}-x$.
\begin{enumerate}[ref={\fcProblemRef}]
\item Express $x$ via $t$.
\item Express $\sqrt{x^2-1}$ via $t$ alone.
\item Express $\diff x$ via $t$ and $\diff t$.
\end{enumerate}

\end{problem} 
\section{L'Hospital's rule}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/lhospital/homework/lhospital-rule-coming-from-Maclaurin-series-1.tex
Compute the limits. The answer key has not been fully proofread, use with caution.
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\sin x  }{x}$. \answer{$1$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{x}{\ln (1+x)}$. \answer{$ 1$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{x^2}{x-\ln (1+x)}$. \answer{$2$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{x^2}{\sin x\ln (1+x)}$. \answer{$ 1$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\sin^2 x  }{\left(\ln (1+x)\right)^2}$.
\answer{$ 1$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\cos x- 1}{\sin x\ln (1+x)}$.
\answer{$- \frac{1}{2} $}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\arctan x -x}{x^3} $.
\answer{$ -\frac{1}{3} $}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\arcsin x -x}{x^3} $.
\answer{$ \frac{1}{6}$}
\item $\displaystyle \lim\limits_{x\to 1} \frac{x}{x-1}-\frac{1}{\ln x}$.
\answer{$ \frac{1}{2}$}
\item $\displaystyle \lim\limits_{x\to 0} \frac{\cos (nx) -\cos (mx)}{x^2 }$.
\answer{$\frac{m^2-n^2}2 $}
\item (Optional)  $\displaystyle \lim \limits_{x\to 0} \frac{\arcsin x-x-\frac{1}{6}x^3}{\sin^5 x} $. 
\answer{$\frac{3}{40}$}
\end{enumerate}
\end{multicols}

\end{problem}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/lhospital/homework/lhospital-rule-coming-from-Maclaurin-series-2.tex
Find the limit.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \lim\limits_{x\to 0} \frac{\sin x-x }{\arcsin x-x } $.

\answer{$ -1$}
\item \label{problemLHospital (sin (pi x) ln x )/ (cos pi x +1)}  $\displaystyle \lim\limits_{x\to 1} \frac{\sin \left(\pi x \right)\ln x }{\cos(\pi x)+1 } $.

\answer{$-\frac{2}{\pi}$}
\item \label{problemlim x to 0 (sin x - x)/(arctan x - x)} $\displaystyle \lim\limits_{x\to 0}\frac{\sin x- x}{\Arctan x -x}$.

\answer{$\frac{1}{2}$}
\item \label{problemlimxtoinftysin(2/x)}
$ {\displaystyle \lim_{x \to \infty} x \sin\left(\frac{2}{x}\right)}.$

\answer{$2$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/lhospital/homework/lhospital-rule-coming-from-Maclaurin-series-2-solutions.tex
\solution{\ref{problemLHospital (sin (pi x) ln x )/ (cos pi x +1)}
The limit is of the form ``$\frac{0}{0}$'' so we are allowed to use L'Hospital's rule.
\[
\begin{array}{rcll|l}
\displaystyle
\lim\limits_{x\to 1} \frac{\sin \left(\pi x\right)\ln x }{\cos(\pi x)+1 } &=&\displaystyle \lim\limits_{x\to 1}  \frac{\left(\sin \left(\pi x\right)\ln x\right)' }{\left(\cos(\pi x)+1\right)' }\\
&=&\displaystyle \lim\limits_{x\to 1}  \frac{\left(\pi \cos \left(\pi x\right)\ln x+ \sin\left(\pi x\right)\frac{1}{x}\right) }{\left(-\pi\sin(\pi x)\right) } &&\text{type ``$\frac{0}{0}$'',  L'Hospital's rule}\\
&=&\displaystyle \lim\limits_{x\to 1}  \frac{\left(\pi \cos \left(\pi x\right)\ln x+ \sin\left(\pi x\right)\frac{1}{x}\right)' }{\left(-\pi\sin(\pi x)\right)' } \\
&=&\displaystyle \lim\limits_{x\to 1}  \frac{- \pi^{2} \sin{}\left(\pi x\right) \ln{}\left(x\right)+2 \pi \cos{}\left(\pi x\right) x^{-1}- \sin{}\left(\pi x\right) x^{-2} }{\left(-\pi^2\cos(\pi x)\right) } \\
&=&\displaystyle  \frac{- \pi^{2} \sin{}\left(\pi \right) \ln(1)+2 \pi \cos{}\left(\pi \right) - \sin{}\left(\pi \right)  }{\left(-\pi^2\cos(\pi )\right) } \\
&=&\displaystyle -\frac{2}{\pi}\quad .
\end{array}
\]
}
\solution{
\ref{problemlim x to 0 (sin x - x)/(arctan x - x)}
\noindent \textbf{Solution I.} 
\[
\begin{array}{rcll|l}
\displaystyle \lim\limits_{x\to 0}\frac{\sin x- x}{\Arctan x -x}&=&\displaystyle \lim\limits_{x\to 0} \frac{\cos x -1 }{ \frac{1}{1+x^2}-1 } &&\text{L'Hospital rule}\\
&=&\displaystyle \lim\limits_{x\to 0}\frac{-\sin x }{\frac{ -2x}{(1+x^2)^2} }&& \text{L'Hospital rule again}\\
&=&\displaystyle \lim\limits_{x\to 0} \frac{(1+x^2)^2}{2}\frac{\sin x}{x}  \\
&=&\displaystyle \lim\limits_{x\to 0} \frac{(1+x^2)^2}{2}\lim\limits_{x\to 0}\frac{\sin x}{x} \\
&=&\displaystyle \frac{1}{2}\quad .
\end{array}
\] 
}

\noindent \textbf{Solution II.}
\[
\begin{array}{rcll|l}
\displaystyle \lim\limits_{x\to 0}\frac{\sin x- x}{\Arctan x -x}&=&\displaystyle \lim\limits_{x\to 0} \frac{\left( x-\frac{x^3}{3!}+\frac{x^5}{5!}-\dots\right) -x}{\left( x-\frac{x^3}{3}+\frac{x^5}{5}-\dots\right)-x} &&\text{use the Maclaurin series of }\sin, \Arctan \\
&=&\displaystyle \lim\limits_{x\to 0}\frac{- \frac{x^3 }{6} + x^5\left(\frac{1}{5!}-\dots\right) }{- \frac{ x^3}{3} + x^5 \left(\frac{1}{5}-\dots \right)  }&& \begin{array}{rcl}
\text{The expressions in parenthesis }\\
\text{are continous functions in x }
\end{array}\\
&=&\displaystyle \lim\limits_{x\to 0} \frac{-\frac{1}{6}+ x^2 \left(\frac{1}{5!}-\dots\right) }{- \frac{1}{3} +x^2 \left( \frac{1}{5}-\dots \right)  }\\
&=&\displaystyle \frac{-\frac{1}{6}+0}{\frac{1}{3}+0}\\
&=&\displaystyle \frac{1}{2}\quad .
\end{array}
\] 

\solution{\ref{problemlimxtoinftysin(2/x)}.
\[
\begin{array}{rcll|l}
\displaystyle \lim_{x\to\infty }x\sin\left( \frac{2}{x} \right)& =&\displaystyle \lim_{x \to \infty} \frac{\sin \left(\frac{2}{x}\right) }{ \frac{ 1}{x}}
 &&\begin{array}{l}
\text{indeterminate form }\\
\text{Use L'Hospital's rule}
\end{array}\\
&=&\displaystyle \lim_{x \to \infty} \frac{\cos\left(\frac{2}{x}\right) \left (-\frac{2}{x^2}\right)}{-\frac{1}{x^2}} \\ 
&=&\displaystyle \lim_{x \to \infty} 2 \cos\left(\frac{x}{2}\right) \\
&=&\displaystyle 2\quad .
\end{array}
\]
}




\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/lhospital/homework/lhospital-rule-collection-1.tex
Evaluate the limit, or show that it does not exist.

\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \lim\limits_{x\to 0}\frac{x^2}{1-\cos x} $
\answer{$2$}
\item $\displaystyle \lim\limits_{x\to\infty}x \tan \left(\frac{1}{x}\right) $
\answer{$1$}
\item $\displaystyle \lim \limits_{x\to 0^+}x^{\sqrt{x}}$
\answer{$1$}
\end{enumerate}
\end{multicols}

\end{problem}
\section{Improper Integrals}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-1.tex
Determine whether the integral is convergent or divergent. Motivate your answer. The answer key has not been proofread, use with caution.

\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \int\limits_{2}^{\infty}\frac{1}{(x-1)^{\frac32}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{-1}^{1}\frac{1}{\sqrt[5]{1+x}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{1}^{\infty }\frac{1}{\sqrt[5]{1+x}} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{-1}^{\infty }\frac{1}{\sqrt[5]{1+x}} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{-\infty }^{0}\frac{1}{2-3x} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{-\infty }^{0}\frac{1}{(2-3x)^{2}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{-\infty }^{0}\frac{1}{(2-3x)^{1.00000001}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{-2}^{-\frac{1}{2}}\frac{1}{2x-1} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{-5}^{\infty} e^{-3x} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{-\infty }^{5}  2^x \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{-\infty }^{\infty}x^3 \diff x$.
\answer{divergent}
\item  $\displaystyle \int\limits_{-\infty}^{\infty} x e^{-x^2} \diff x$.
\answer{convergent}
\item \label{problemConvergencesqrt(x)e^-sqrt(x)zerotoinfty} $\displaystyle \int\limits_{0}^{\infty} \sqrt{x} e^{-\sqrt{x}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{\infty}\sin^2 x \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{0}^{5}\frac{1}{x^2+x-2} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{0}^{\infty}\frac{1}{x^2+x+1} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{2}^{\infty}\frac{1}{x^2-x-1} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{\infty}\frac{1}{x^2-x-1} \diff x$.
\answer{divergent}
\item \label{problemConvergencex^2/(x^4+2)from-inftyto+infty}

$\displaystyle \int\limits_{-\infty}^{\infty} \frac{x^2}{x^4+2} \diff x$.
\answer{convergent}
\end{enumerate}
\end{multicols}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-1-solutions.tex
\solution{\ref{problemConvergencex^2/(x^4+2)from-inftyto+infty}
The integrand is a rational function and therefore we can solve this problem by finding the indefinite integral and then computing the limit. We would need to start by factoring $x^4+2$ into irreducible quadratic factors - that is already quite laborious:
\[
x^4+2= \left(x^2+\sqrt[4]{8}x+\sqrt{2} \right)\left(x^2-\sqrt[4]{8}x+\sqrt{2}\right)\quad.
\]
The problem asks us only to establish the convergence of the integral; it does not ask us to compute its actual numerical value. Therefore we can give a much simpler solution. The function is even and therefore it suffices to establish whether $\displaystyle \int\limits_0^\infty \frac{x^2}{x^4+2}\diff x$ is convergent.

We have that 
\[
\int\limits_{0}^\infty \frac{x^2}{x^4+2}\diff x= \int\limits_{0}^1 \frac{x^2}{ x^4 +2 }\diff x+\int\limits_{1}^\infty \frac{x^2}{x^4+2}\diff x\quad.
\]
The function $ \frac{x^2}{x^4+2}$ is continuous so $\int\limits_{0}^1 \frac{x^2}{x^4+2}\diff x$ integrates to a number, which does not affect the convergence of the above expression. Therefore the convergence of our integral is governed by the convergence of $\int\limits_{1}^\infty \frac{x^2}{x^4+2}\diff x$. To establish that that integral is convergent, we use the comparison theorem as follows.
\[
\begin{array}{rcll|l}
\displaystyle
\int\limits_{1}^\infty \frac{x^2}{x^4+2}\diff x&\leq & \displaystyle \int \limits_{ 1}^\infty \frac{x^2}{x^4}\diff x && \begin{array}{l} \text{we have that } x^4+2>x^4\\ \text{and therefore }\displaystyle \frac{x^2}{x^4+2}\leq \frac{x^2}{x^4}\end{array}\\
&=&\displaystyle \int_1^{\infty} x^{-2}\diff x\\
&=&\displaystyle \lim\limits_{t\to \infty} \left[ -\frac{1}{x}\right]_{1}^{t}\\
&=&\displaystyle  \lim\limits_{t\to\infty} 1- \frac{1}{t}\\
&=&\displaystyle  1\quad .
\end{array}
\]
In this way we showed $ \displaystyle\int_{1}^\infty \frac{x^2}{x^4+2} \diff x \leq 1$. Therefore, as $\displaystyle \frac{x^2 }{ x^4 + 2}\geq 0 $ is positive, we can apply the comparison theorem to get that $\displaystyle\int_{1}^\infty \frac{ x^2}{x^4+2} \diff x $ is convergent.
}

\solution{\ref{problemConvergencesqrt(x)e^-sqrt(x)zerotoinfty}
It is possible to show that this integral is convergent by using the comparison theorem. However, we shall use direct integration instead. First, we solve the indefinite integral:

\[
\begin{array}{rcll|l}
\displaystyle \int \sqrt{x} e^{-\sqrt{x}} \diff x&=& \displaystyle \int \sqrt{x} e^{-\sqrt{x}} \frac{2\sqrt{x} \diff x}{2\sqrt{x}} &&\text{use }  \diff \sqrt{x} = \frac{\diff x}{2\sqrt{x}} \\
&=& \displaystyle \int \sqrt{x} e^{-\sqrt{x}} \left(2 \sqrt{x} \diff \sqrt{x}\right) &&\text{Set } \sqrt{x}=u\\
&=& \displaystyle 2\int u^2 e^{-u}\diff u\\
&=& \displaystyle 2\left( -\int u^2 \diff \left( e^{-u} \right) \right) &&\text{integrate by parts} \\
&=& \displaystyle 2\left(- u^2e^{-u}+\int e^{-u}\diff \left(u^2\right) \right) \\
&=&\displaystyle 2\left(- u^2e^{-u}+\int 2 u e^{-u}\diff u \right)\\
&=&\displaystyle 2\left(- u^2e^{-u}-\int 2 u \diff e^{ -u} \right) &&\text{integrate by parts again}\\
&=&\displaystyle 2\left(- u^2e^{-u}- 2 u  e^{-u}+ \int 2e^{-u}\diff u \right) \\
&=&\displaystyle 2\left( - u^2e^{-u} -2ue^{-u} -2e^{ -u} \right)+C\\
&=&\displaystyle 2\left( - xe^{-\sqrt{x}} -2\sqrt{x } e^{ -\sqrt{x}} -2e^{-\sqrt{x}}\right)+C
\end{array}
\]
Therefore 
\[
\begin{array}{rcll|l}
\displaystyle \int \sqrt{x} e^{-\sqrt{x}} \diff x&=& \displaystyle \lim\limits_{t\to \infty} 2\left[ - xe^{- \sqrt{ x} } -2\sqrt{x}e^{-\sqrt{x}} -2e^{- \sqrt{x}} \right]_{ 0}^{\infty}\\
&=&\displaystyle 4+ \lim\limits_{t\to \infty} 4\left( -te^{ -\sqrt{t}} -\sqrt{t}e^{-\sqrt{t}}- e^{-\sqrt{t}} \right) && \text{Set }u=\sqrt{t}\\
&=&\displaystyle 4- 4\lim\limits_{u\to \infty} \left( u^2 e^{-u} + ue^{-u}+e^{-u}\right)\\
&=& \displaystyle 4- 4\lim\limits_{u\to \infty} \frac{ u^2 + u+1}{e^u} &&\text{use L'Hospital's rule for limit, see below}\\
&=& 4\quad ,
\end{array}
\]
and the integral converges to $4$. In the above computation we used the following limit computation
\[
\begin{array}{rcll|l}
\displaystyle \lim\limits_{u\to \infty}\frac{u^2+u+1}{e^u}&=&\displaystyle  \lim\limits_{u\to \infty} \frac{2u+1}{e^u}&&\text{Apply L'Hospital's rule}\\
&=&\displaystyle \lim\limits_{u\to \infty} \frac{2}{e^u}\\
&=&\displaystyle 0\quad .
\end{array}
\]

}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-2.tex
Determine whether the integral is convergent or divergent. Motivate your answer. The answer key has not been proofread, use with caution.

\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \int\limits_{100}^{\infty} \frac{1}{x\ln x} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{100}^{\infty} \frac{1}{x(\ln x)^2} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{1}\ln x \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{1}\frac{\ln x}{\sqrt{x}} \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{2}x^3\ln x \diff x$.
\answer{convergent}
\item $\displaystyle \int\limits_{0}^{1} \frac{e^{\frac{1}{x}}}{x^2} \diff x$.
\answer{divergent}
\item $\displaystyle \int\limits_{-1}^{0} \frac{e^{\frac{1}{x}}}{x^2} \diff x$.
\answer{convergent}
\item $\displaystyle \int \limits_{0}^{\infty}\sin x^2\diff x$ (This problem is more difficult and may require knowledge of sequences to solve).
\answer{convergent}
\end{enumerate}
\end{multicols}


\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-3.tex
Determine if the integral is convergent or divergent. If convergent, compute its value.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \int\limits_{1}^{2} \frac{x}{\sqrt{x^2-1}}\diff x$ 
\answer{$\sqrt{3}$}

\item $\displaystyle \int\limits_{0}^{1} x^2\ln x\diff x$ \label{problemImproperIntegral x^2ln x dx}
\answer{$- \frac{1}{9} $}

\item \label{problemImproperIntegral e^(-sqrt x)/sqrt(x)dx}
$\displaystyle \int\limits_{0}^{\infty} \frac{e^{-\sqrt{x}}}{ \sqrt{x}} \diff x $
\answer{ $2 $} 

\item \label{problemImproperIntegral1/(x ln x)dx} $\displaystyle \int\limits_{100}^{\infty} \frac{1}{x\ln x}\diff x $
\answer{$\infty$- the integral is divergent} 

\item $\displaystyle \int\limits_{0}^{1} \frac{1}{x\ln x}\diff x $
\answer{$-\infty$- the integral is divergent} 

\item \label{problemImproperIntegral(1+e^(-x))/(xlnx)dx}
$\displaystyle \int\limits_{100}^{\infty} \frac{1+e^{-x}}{x\ln x }\diff x $ 
\answer{$\infty$-the integral is divergent}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-3-solutions.tex
\solution{\ref{problemImproperIntegral x^2ln x dx}
\[
\begin{array}{rcll|l}
\displaystyle \int \limits_{0}^1 x^2\ln x \diff x&=& \displaystyle \int \limits_{0}^1 \ln x \diff \left( \frac{ x^3}{ 3} \right) &&\text{Integrate by parts}\\ 
&=&\displaystyle \left[\frac{x^3}{3}\ln x\right]_{0}^1-\int \frac{x^3 }{3} \diff (\ln x)\\
&=&\displaystyle  \left[\frac{x^3}{3}\ln x\right]_{0}^1- \int \limits_{0 }^1 \frac{x^2}{3} \diff x\\
&=&\displaystyle \left[\frac{x^3}{3}\ln x- \frac{ x^3}{9} \right]_{0}^1\\
&=&\displaystyle  \frac{1}{3} \ln 1 - \frac{1}{9}- \left(\lim\limits_{ x \to 0} \frac{x^3\ln x}{3}-0 \right)\\
&=&\displaystyle -\frac{1}{9} -\lim \limits_{x\to 0} \frac{x^3\ln x}{3}\\
&=&\displaystyle -\frac{1}{9} -\lim \limits_{x\to 0} \frac{\ln x}{ \frac{3 }{ x^3}} &&\text {Use L'Hospital's rule} \\
&=&\displaystyle -\frac{1}{9} - \lim \limits_{x\to 0} \frac{ \frac{1 }{x}}{- \frac{9 }{ x^4}} = -\frac{1}{9} -\lim \limits_{x\to 0}\frac{x^3}{-9}\\
&=&\displaystyle -\frac{1}{9}\quad .
\end{array}
\]

}



\solution{\ref{problemImproperIntegral e^(-sqrt x)/sqrt(x)dx}
\[
\begin{array}{rcl}
\displaystyle \int\limits_{0}^{\infty} \frac{e^{-\sqrt{x}}}{\sqrt{x}} \diff x &=& \displaystyle  2\int\limits_{x=0}^{\infty} e^{-\sqrt{x}}\diff \sqrt{x}\\
&=&\displaystyle \left[-2e^{-\sqrt{x}}\right]_{x=0}^{\infty}\\
&=&\displaystyle \lim\limits_{t\to \infty} -2e^{-\sqrt{x}}- \left(-2e^{-\sqrt{0}}\right)\\
&=& 2\quad .
\end{array}
\]

}

\solution{\ref{problemImproperIntegral1/(x ln x)dx}
\[
\begin{array}{rcl}
\displaystyle \int\limits_{100}^{\infty} \frac{1}{x \ln x}\diff x&=&\displaystyle  \int\limits_{x=100}^{\infty} \frac{1}{\ln x}\diff (\ln x)\\
&=&\displaystyle \int\limits_{x=100}^{\infty} \diff \left(\ln (\ln x)\right)\\~\\
&=&\displaystyle \left[ \ln (\ln x)\right]^{\infty}_{100}\\~\\
&=&\displaystyle \lim\limits_{t\to \infty} \ln (\ln t)- \ln (\ln 100)\\~\\
&=&\displaystyle \infty\quad .
\end{array}
\]
The integral diverges to $\infty$.
}
\solution{\ref{problemImproperIntegral(1+e^(-x))/(xlnx)dx}
\[
\int\limits_{100}^\infty \frac{1+e^{-x}}{x\ln x}\diff x >\int \limits_{100}^{\infty}\frac{1}{x\ln x}\diff x \stackrel{\text{Problem }\ref{problemImproperIntegral1/(x ln x)dx}}{=} \infty\quad .
\]
Therefore by the comparison test, our integral diverges to $\infty$.
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/improper-integrals/homework/improper-integral-convergent-or-divergent-4.tex
Determine if the integral is convergent or divergent. If it is convergent, compute the value of the integral.

\begin{enumerate}
\item $\displaystyle \int\limits_{1}^\infty \frac{x^2}{x^3+1}\diff x$
\answer{$\infty$- the integral diverges.}
\item $\displaystyle \int \limits_{1}^{\infty} \frac{1 }{ x^2+1}\diff x$
\answer{$\frac{\pi }{4}$}
\item  $\displaystyle\int\limits_{6}^8\frac{4}{(x-6)^3}\diff x$
\answer{$\infty$- the integral diverges.}
\end{enumerate}

\end{problem}

\section{Sequences}
\subsection{Understanding sequence notation}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/sequences/homework/guess-sequence-formula-1.tex
Give a simple sequence formula that matches the pattern below. 

\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \left(1, \frac{1}{3}, \frac{1}{5}, \frac{1}{7},\frac{1}{9},\dots \right)$.

\answer{$a_n=\frac{1}{2n-1}$}
\item $\displaystyle \left(-1, \frac{1}{5}, -\frac{1}{25}, \frac{1}{125},-\frac{1}{625}, \frac{1}{3125}\dots \right)$

\answer{$a_n=-\left(-\frac{1}{5}\right)^{n-1}$}
\item $\displaystyle \left(-5, 2, -\frac{4}{5}, \frac{8}{25}, -\frac{16}{125}, \frac{32}{625},\dots \right)$

\answer{$a_n=-5\left(-\frac{2}{5}\right)^{n-1}$}

\item $\displaystyle \left(4, 7, 10, 13, 16, 19,\dots\right)$

\answer{$a_n=3 {{n}}+1 $}

\item $\left(-2, \frac{3}{4}, -\frac{4}{9}, \frac{5}{16}, -\frac{6}{25}, \frac{7}{36}, \dots \right)$

\answer{$a_n=(-1)^{n}\left(\frac{n +1}{n^{2}}\right)$}

\item $\left(0,-1, 0, 1,0,-1, 0, 1,0,-1, 0, 1,\dots \right)$

\answer{$a_n=\cos\left(n\frac{\pi}{2}\right)$}
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/sequences/homework/sequence-list-sequence-recursive-terms-1.tex
List the first 5 elements of the sequence. 
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle a_{n+1}=\frac{1}{2}\left(a_n+ \frac{3}{a_n}\right)$, $a_1=1$.
\item $\displaystyle a_n=a_{n-1}+a_{n-2}$, $a_1=1$, $a_2=1$.
\item $\displaystyle a_n= \frac{\left(\frac{1}{2}-n\right)}{n} a_{n-1} $, $a_0=1$.
\item $\displaystyle a_n= a_{n-1}+2n+1$, $a_0=1$.
\item $\displaystyle a_n:=\frac{1}{n} a_{n-1}$, $a_1=1$.
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/sequences/homework/sequence-list-sequence-terms-1.tex
List the first 4 elements of the sequence. 
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle a_n= \frac{(-1)^n}{n}$.

\answer{$(a_1, a_2, a_3, a_4, a_5)=\left(-1, \frac12, -\frac13, \frac14\right)$ }
\item $\displaystyle a_n=\frac{1}{n!}$.

\answer{$(a_1, a_2, a_3, a_4, a_5)=\left(1, \frac{1}{2}, \frac{1}{6}, \frac{1}{24}\right)$ }
\item $\displaystyle a_n=\cos (\pi n)$.

\answer{$(a_1, a_2, a_3, a_4, a_5)=(-1, 1, -1, 1)$ }
\item $\displaystyle a_n=\frac{(-1)^n}{2n+1}$.

\answer{$(a_1, a_2, a_3, a_4, a_5)=\left(-\frac{1}{3}, \frac{1}{5}, -\frac{1}{7}, \frac{1}{9}\right)$ }
\item $\displaystyle a_n=\frac{\sqrt{5}}{5}\left( \left(\frac{1+\sqrt{5 }}{2} \right)^n- \left(\frac{1-\sqrt{5}}{2}\right)^n\right) $

\answer{$(a_1, a_2, a_3, a_4, a_5)=(1, 1, 2, 3)$ }
\end{enumerate}
\end{multicols}

\end{problem}

\subsection{Convergence}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/sequences/homework/convergent-or-divergent-sequence-1.tex
Determine if the sequence is convergent or divergent. If convergent, find the limit of the sequence.
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle a_n=n$.
\answer{divergent}
\item $\displaystyle a_n=2^n$.
\answer{divergent}
\item $\displaystyle a_n=1.0001^n$.
\answer{divergent}
\item $\displaystyle a_n=0.999999^n$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\item $\displaystyle a_n=n-\sqrt{n+1}\sqrt{n+2}$
\answer{convergent, $\lim_{n\to \infty} a_n=-\frac{3}{2}$}
\item $\displaystyle a_n=\frac{\ln n}{n}$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\item $\displaystyle a_n=\frac{\ln n}{\sqrt[10]{n}}$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\item $\displaystyle a_n=\frac{1}{n}$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\item $\displaystyle a_n=\frac{1}{n!}$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\item $\displaystyle a_n=\frac{n^n}{n!}$.
\answer{divergent}
\item $\displaystyle a_n=\cos n$.
\answer{divergent}
\item $\displaystyle a_n=\cos\left(\frac{1}{n}\right)$
\answer{convergent, $\lim_{n\to \infty} a_n=1$}

\item $\displaystyle a_n= \left(\frac{n+1}{n}\right)^{n}$.
\answer{convergent, $\lim_{n\to \infty} a_n=e$}
\item $\displaystyle a_n= \left(\frac{2n+1}{n}\right)^{n}$.
\answer{divergent}

\item $\displaystyle a_n= \left(\frac{n+1}{n}\right)^{2n}$.
\answer{convergent, $\lim_{n\to \infty} a_n=e^2$}

\item $\displaystyle a_n= \left(\frac{n+1}{2n}\right)^{n}$.
\answer{convergent, $\lim_{n\to \infty} a_n=0$}
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/sequences/homework/convergent-or-divergent-sequence-2.tex
Find the limit of the sequence or prove that the sequence is divergent.
\begin{enumerate}
\item $\displaystyle a_n=\left(\frac{n}{n-1}\right)^{2n}$.
\answer{convergent, $\lim\limits_{n\to \infty} a_n = e^2$}
\item $\displaystyle a_n=\frac{n!}{n^n}$.
\answer{convergent, $\lim\limits_{n\to \infty} a_n=0$}
\end{enumerate}


\end{problem}
\section{Series}
\subsection{Some explicit series summations}
\subsubsection{Geometric series}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/express-infinite-decimal-as-rational-1.tex
Express the infinite decimal number as a rational number.
\begin{multicols}{2}
\begin{enumerate}
\item $1.\overline{6}=1.6666\dots$

\answer{ $\frac{5}{3} $}
\item $1.\overline{3}=1.3333\dots$

\answer{ $\frac{4}{3} $}
\item $2.\overline{16}=2.16161616\dots$

\answer{$\frac{214}{99}$ }
\item $2014.\overline{2014}=2014.2014201420142014\dots$

\answer{$\frac{20140000}{9999}$}
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/express-infinite-decimal-as-rational-2.tex
Express the infinite decimal number as a rational number.
\begin{multicols}{2}
\begin{enumerate}
\item $1.\overline{19}=1.191919\dots$.
\answer{$\frac{118}{99}$}
\item $0.\overline{09}=0.0909090909\dots $.
\answer{$\frac{1}{11}$}
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/geometric-series-sum-1.tex
Express the sum of the series as a rational number.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item 
\label{problemSum(2^n+3^n)/(5^n)}
\[
\sum\limits_{n=1}^{\infty} \frac{2^n+3^n}{5^n}
\]

\answer{$\frac{13}{6}$}

\item \label{problemsumn=0^infty(2^n+5^n)/10^n}
$\displaystyle\sum_{n=0}^{\infty} \frac{2^n+5^n}{10^n}$

\answer{$\frac{13}{4}$}
\item \label{problemSum(3^n+5^n)/(7^n)}
\[
\sum\limits_{n=1}^{\infty} \frac{5^n-3^n}{7^n}
\]

\answer{$\frac{7}{4}$}
\item \label{sum_n=1^infty(3^(n+1)+7^(n-1))/21^n}
\[
\sum_{n=1}^\infty \frac{3^{n+1}+7^{n-1}}{21^n}
\]
\answer{$ \frac{4}{7}$}


\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/geometric-series-sum-1-solutions.tex
\solution{\ref{problemSum(2^n+3^n)/(5^n)}

\[
\begin{array}{rcll|l}
\displaystyle \sum\limits_{n=1}^{\infty} \frac{2^n+3^n}{5^n}&=&\displaystyle \sum\limits_{n=1}^{\infty} \left(\frac{2}{5}\right)^n
+\sum\limits_{n=1}^{\infty} \left(\frac{3}{5}\right)^n\\
&=&\displaystyle  \frac{2}{5}\sum\limits_{n=0}^{\infty} \left(\frac{2}{5} \right)^n+\frac{3}{5}\sum\limits_{n=0}^{\infty}\left(\frac{3}{5}\right)^n&&
\begin{array}{l}
\text{Use geometric series sum f-la: }\\
\sum\limits_{n=0}^{\infty}r^n=\frac{1}{1-r},\\
\text{provided } |r|<1
\end{array}\\
&=&\displaystyle  \frac{2}{5}\frac{1}{\left(1-\frac{2}{5}\right)} +\frac{3}{5}\frac{1}{\left(1-\frac{3}{5}\right)}\\
&=&\displaystyle \frac{13}{6}\quad .
\end{array}
\]
}

\solution{\ref{problemsumn=0^infty(2^n+5^n)/10^n}
\[
\begin{array}{rcll|l}
\displaystyle \sum\limits_{n=0}^{\infty}\frac{2^n+5^n}{10^n}&=&\displaystyle  \sum \limits_{ n=0}^{\infty}\left(\frac{1}{5^n}+\frac{1}{2^n}\right)&&\text{use } \sum_{ n= 0}^{\infty} r^n=\frac{1}{1-r}, \text{ for } |r|<1\\
&=&\displaystyle \frac{1}{1-\frac{1}{2}} +\frac{1}{1-\frac{1}{5}}\\
&=&\displaystyle \frac{13}{4}\quad .
\end{array}
\]
}

\solution{\ref{sum_n=1^infty(3^(n+1)+7^(n-1))/21^n}
\[
\begin{array}{rcll|l}
\displaystyle \sum\limits_{n=1}^{\infty} \frac{3^{n+1}+ 7^{ n-1}}{21^n} &=& \displaystyle \sum \limits_{n=1}^{\infty}\left(3\frac{3^{n}}{21^n}+ \frac{ 1 }{7} \frac{ 7^n }{21^n}\right)\\
&=&\displaystyle 3\sum_{n =1}^{\infty} \left(\frac{1}{7} \right)^n + \frac{1 }{7} \sum_{n=1}^{\infty}  \left(\frac{1}{3} \right)^n\\
&=&\displaystyle \frac{3}{7}\sum_{n=0}^{\infty}\left(\frac{1}{7 } \right)^n +\frac{1 }{21} \sum_{ n=0}^{\infty}\left(\frac{1}{3 } \right) ^n &&\text{use }\sum_{n= 0 }^\infty r^n=\frac{1}{1-r}, |r|<1\\
&=&\displaystyle \frac{3}{7} \frac{1}{ \left(1 -\frac{ 1}{7} \right)}+ \frac{ 1}{21} \frac{1 }{ \left(1-\frac{1 }{ 3} \right)}\\
&=&\displaystyle \frac{4}{7}\quad .
\end{array}
\]
}

\subsubsection{Telescoping series}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/telescoping-series-2.tex
Use partial fractions to split the summand of each sum into two. Sum the telescoping series (a sum is ``telescoping'' if it can be broken into summands so that consecutive terms cancel). The answer key has not been proofread, use with caution.
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \sum\limits_{n=0}^{\infty} \frac{-6}{9 n^{2}+3 n-2}$\quad.
\answer{$ 2$}
\item \label{probelmSum_n=3^infty 3/(n^2-3n+2) }  $\displaystyle \sum \limits_{n=3}^{\infty} \frac{3}{n^{2}-3 n+2} $\quad.
\answer{$3$}

\item \label{problemsumn=2^inftyln(1-1/n^2)} $\displaystyle\sum_{n=2}^{\infty} \ln \left(1-\frac{1}{n^2}\right).$ (Hint: Use the properties of the logarithm to aim for a telescoping series).

\answer{$-\ln 2$}

\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/telescoping-series-2-solutions.tex
\solution{
\ref{probelmSum_n=3^infty 3/(n^2-3n+2) } 
\[
\begin{array}{rcll|l}
\displaystyle \sum_{n=3}^{\infty} \frac{3}{n^2-3n+2} &=&\displaystyle  \sum_{n=3}^{\infty}\left( \frac{3}{n-2} - \frac{3}{n-1} \right)  &&\text{use partial fractions, see below}\\
&=&\displaystyle  3\sum_{n=3}^{\infty} \left( \frac{1}{n-2} - \frac{1}{n-1} \right)\\
&=&\displaystyle 3\left( \underset{n=3}{\left(1-\frac{1}{2}\right)} + \underset{n=4}{\left(\frac{1}{2}-\frac{1}{3}\right)} + \underset{n=5}{\left(\frac{1}{3}-\frac{1}{4}\right)} + \dots\right)\\~\\
&=&\displaystyle 3\lim\limits_{n\rightarrow\infty} \left( 1 - \frac{1}{n-1} \right) = 3\quad .
\end{array}
\]

In the above we used the partial fraction decomposition of $\displaystyle \frac{3}{n^2-3n+2}$. This decomposition is computed as follows. 

\[\frac{3}{n^{2}-3n +2}=\frac{3}{ \left(n -1\right)\left(n -2\right)}\]We need to find $A_i$'s so that we have the following equality of rational functions. After clearing denominators, we get the following equality. \[3 = A_{1} (n -2)+A_{2} (n -1)\]After rearranging we get that the following polynomial must vanish. Here, by ``vanish'' we mean that the coefficients of the powers of $x$ must be equal to zero.\[(A_{2} +A_{1} )n +(-A_{2} -2A_{1} -3)\]In other words, we need to solve the following system. \[\begin{array}{llll} & -2A_{1} & -A_{2} & =3\\ & A_{1} & +A_{2} & =0\\\end{array}\] \begin{longtable}{cc} System status&Action \\\hline $\begin{array}{llll} & -2A_{1} & -A_{2} & =3\\ & A_{1} & +A_{2} & =0\\\end{array}$& Selected pivot column 2. Eliminated the non-zero entries in the pivot column. \\\hline $\begin{array}{llll} & A_{1} & +\frac{A_{2} }{2} & =-\frac{3}{2}\\ & & \frac{A_{2} }{2} & =\frac{3}{2}\\\end{array}$& Selected pivot column 3. Eliminated the non-zero entries in the pivot column. \\\hline $\begin{array}{llll} & A_{1} & & =-3\\ & & A_{2} & =3\\\end{array}$& Final result.\\ \end{longtable}

Therefore, the final partial fraction decomposition is the following. 
\[
\frac{3}{n^{2}-3n +2}=\frac{-3}{(n -1)}+\frac{3}{(n -2)}.
\]
}

\solution{\ref{problemsumn=2^inftyln(1-1/n^2)}.
\[
\begin{array}{rcl}
\displaystyle \sum_{n=2}^\infty \ln \left(1-\frac{1}{n^2}\right)&=&\displaystyle \sum_{n=2}^\infty\left( \ln \left(1-\frac{1}{n}\right)+\ln \left(1+\frac{1}{n}\right)\right)\\
&=&\displaystyle \sum_{n=2}^\infty\left( \ln \left(\frac{n-1}{n}\right)+\ln \left(\frac{n+1}{n}\right)\right)\\
&=&\displaystyle\sum_{n=2}^\infty \left( \ln (n-1)-2\ln (n)+\ln (n+1)\right)\\
&=&\displaystyle \left(\ln 1 -2\ln 2+\cancel{ \ln 3}\right) +\left(\ln 2\cancel{-2\ln 3}+\cancel{\ln 4} \right)\\
&&\displaystyle +\left(\cancel{\ln 3}\cancel{-2\ln 4}+\cancel{\ln 5} \right)+\cancel{\dots}\dots \\
&=&\displaystyle\lim_{n\to \infty} \left(-\ln 2 -\ln n+\ln(n+1)\right)\\
&=&\displaystyle\lim_{n\to \infty} \left(-\ln 2 +\ln\left( \frac{ n+1}{ n } \right) \right)\\
&=&-\ln 2\quad .
\end{array}
\]
}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/telescoping-series-1.tex
Use partial fractions to sum the telescoping series (a sum is ``telescoping'' if it can be broken into summands so that consecutive terms cancel).
\begin{multicols}{2}
\begin{enumerate}
\item $\displaystyle \sum\limits_{x=1}^\infty \frac{1}{x^{2}+x}$

\answer{$1$}
\item $\displaystyle \sum\limits_{x=2}^\infty\frac{2 x+1}{x^{4}+2 x^{3}- x^{2}-2 x}$

\answer{$\frac{1}{3}$}

\item $\displaystyle \sum\limits_{x=1}^\infty \frac{2 x}{x^{4}-3 x^{2}+1}$

\answer{$-1$}

\item $\displaystyle \sum\limits_{x=1}^\infty \frac{x^{2}+x+2}{ x^{4}- 5  x^{2}+4}$
\answer{$-\frac{1}{2}$}

\end{enumerate}
\end{multicols}

\end{problem}

\subsection{Series convergence tests}
\subsubsection{Basic tests}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-basic-tests-1.tex
Find whether the series is convergent or divergent using an
appropriate test.  
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemConvergencesumn=1^infty(-1)^nlnn} $\displaystyle\sum_{n=1}^{\infty} (-1)^n\ln n  . $
\item \label{problemConvergencesumn=2^infty(-1)^n/lnn} $\displaystyle\sum_{n=2}^{\infty} \frac{(-1)^n }{\ln n}  .$
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-basic-tests-1-solutions.tex
\solution{\ref{problemConvergencesumn=1^infty(-1)^nlnn}. $\lim\limits_{n\to\infty }(-1)^n \ln n$ does not exist and therefore the sum is not convergent.
}

\noindent \solution{\ref{problemConvergencesumn=2^infty(-1)^n/lnn}. For $n>2$, we have that $\ln n$ is a positive increasing function and therefore $\frac{1}{\ln n}$ is a decreasing positive function. Furthermore $\displaystyle \lim_{n\to \infty}\frac{1}{\ln n} =0 $. Therefore the series is convergent by the alternating series test.
}



\subsubsection{Integral test}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-integral-or-comparison-test-3.tex
\label{problemConvergenceint_10^inftyx/(xlnx)dx}
Determine whether the following improper integral is convergent or divergent, and evaluate it if convergent
\[
\int_{10}^{\infty}\frac{1}{x\ln x}\diff x.
\]
Is the series $\displaystyle \sum_{10}^\infty \frac{1}{n \ln n}$ convergent?

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-integral-or-comparison-test-3-solutions.tex
\solution{\ref{problemConvergenceint_10^inftyx/(xlnx)dx}.
\[
\begin{array}{rcl}
\displaystyle \int_{10}^{\infty}\frac{1}{x\ln x}\diff x&=&\displaystyle \lim_{t\to\infty} \int_{10}^{t}\frac{1}{x\ln x}\diff x\\
&=&\displaystyle \lim_{t\to\infty} \int_{10}^{t}\frac{1}{\ln x}\diff(\ln x)\\
&=&\displaystyle \lim_{t\to\infty} \int_{10}^{t}\diff(\ln(\ln x))\\
&=&\displaystyle \lim_{t\to \infty}\left[ \ln(\ln x)\right]_{x=10}^{x=t}\\
&=&\displaystyle \lim_{t\to \infty}\left(\ln(\ln t)-\ln (\ln 10)\right)\\
&=&\displaystyle \infty,
\end{array}
\]
therefore the integral is divergent (and diverges to $+\infty$).

The function $\frac{1}{x\ln x}$ is decreasing, as for $x>10$, it is the quotient of $1$ by increasing positive functions. $\frac{ 1}{ x\ln x}$ tends to $0$ as $x\to \infty$, and therefore the integral criterion implies that $\sum\limits_{10}^{ \infty} \frac{1 }{n \ln n}$ is divergent.
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-integral-or-comparison-test-1.tex
Use integral test, the comparison test or the limit comparison test to determine whether the series is convergent or divergent. Justify your answer.
\begin{multicols}{2}
\begin{enumerate}
\item 
$\displaystyle \sum\limits_{n=1}^{\infty} \frac{1}{2n+1}$.

\answer{divergent}
\item 
$\displaystyle \sum\limits_{n=1}^{\infty} \frac{1}{2n^2+n^3}$.

\answer{convergent}
\item 
$\displaystyle \sum\limits_{n=2}^{\infty} \frac{1}{(2n+1)\ln (n)}$.

\answer{divergent}
\item 
$\displaystyle \sum\limits_{n=2}^{\infty} \frac{1}{(2n+1)(\ln (n))^2}$.

\answer{convergent}
\item 
Determine all values of $p$, $q$ $r$ for which the series 
\[
\displaystyle \sum_{n=30}^{\infty} \frac{1}{n^p(\ln n)^q(\ln (\ln n))^r}
\]
is convergent.
\end{enumerate}
\end{multicols}



\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-integral-or-comparison-test-2.tex
Use integral test, the comparison test or the limit comparison test to determine whether the series is convergent or divergent. Justify your answer. The answer key has not been proofread, use with caution.
\begin{enumerate}
\item $\displaystyle \sum\limits_{n=2}^{\infty}\frac{1}{n(\ln n)^2}$
\answer{convergent, can use integral test}
\item $\displaystyle \sum\limits_{n=2}^{\infty}\frac{1}{n\ln n}$
\answer{divergent, can use integral test}
\item $\displaystyle \sum\limits_{n=1}^{\infty}\frac{n^2+3}{3n^5+n}$
\answer{convergent, can use limit comparison test}
\end{enumerate}

\end{problem}

\subsubsection{Root, ratio tests}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-ratio-and-or-root-test-1.tex
Determine the interval of convergence for the series. You may use either the ratio test or the root test, or any other method that works.

\begin{multicols}{2}
\begin{enumerate}
\item 
$\displaystyle \sum\limits_{n=0}^{\infty} \frac{x^n}{n!}$

\answer{converges for all $x$}
\item 
$\displaystyle \sum\limits_{n=0}^{\infty} (n+1)x^n $

\answer{converges for $|x|<1$}
\item 
$\displaystyle \sum\limits_{n=1}^{\infty} \frac{x^n}{n}$
\answer{converges for $|x|\in[-1,1)$.}
\item 
$\displaystyle\sum\limits_{n=1}^{\infty} (-1)^n\frac{x^{2n+1}}{2n+1}$

\answer{converges for $|x|\in (-1, 1]$}.
\item 
$\displaystyle \sum\limits_{n=1}^{\infty} \binom{\frac{1}{2}}{n}x^{n}$, where we recall that the binomial coefficient $\displaystyle \binom{q}{n}$ stands for $\displaystyle\frac{q (q-1)\dots (q-n+1)}{n!}$.

\answer{converges for $x\in (-1,1]$. } 
\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-ratio-and-or-root-test-2.tex
Establish whether the series is convergent or divergent. Use the ratio or root tests. Show all your work. The answer key has not been proofread, use with caution.
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemConvergenceSum n=0 ^ infty (-1)^n n^2 3^(-n)}
$\displaystyle \sum_{n=0}^\infty (-1)^n n^2 3^{-n}$
\answer{convergent, straightforward with ratio test}
\item $\displaystyle \sum \limits_{n=1}^{\infty} \left( \frac{ n+1 }{4n}\right)^n$
\answer{convergent, straightforward with root test}
\item $\displaystyle \sum\limits_{n=1}^{\infty}\left(\frac{4n+1 }{n}\right)^n$
\answer{divergent, straightforward with root test}
\item $\displaystyle \sum\limits_{n=1}^{\infty} \frac{n^n }{4^n n!}$
\answer{convergent, use ratio test}
\item \label{problemConvergenceSum_n=1^infty(4n)^n/nfactorial} $\displaystyle \sum\limits_{n=1}^{\infty} \frac{(4n)^n }{ n!}$
\answer{divergent, use ratio test}
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-ratio-and-or-root-test-2-solutions.tex
\solution{\ref{problemConvergenceSum n=0 ^ infty (-1)^n n^2 3^(-n)}
We proceed with the ratio test; the alternating series test works too, however that approach is a lot less straightforward and we leave it to the reader.

Let the $n^{th}$ term of the series be $a_n= (-1)^n n^2 3^{-n}$. The ratio test states that if the limit $\lim_{n\to \infty} \left|\frac{ a_{n+1}}{ a_n} \right|$ exists and is less than $1$, then the series is convergent, and if the limit exists and is greater than $1$, then then the series is divergent. 
\[
\begin{array}{rcl}
\displaystyle \lim\limits_{n\to \infty} \left|\frac{a_{n+1}}{a_n}\right|&=&\displaystyle \lim\limits_{n\to \infty} \left|\frac{(-1)^{n+1} 3^{-n-1} (n+1)^2}{(-1)^n 3^{-n}n^2}\right|\\
&=&\displaystyle \lim\limits_{n\to \infty} \left|\frac{ 1}{3 } \left(1+\frac{1}{n} \right)^2\right|\\
&=&\frac{1}{3} <1\quad .
\end{array}
\]
Therefore the series is convergent by the ratio test.
}

\solution{\ref{problemConvergenceSum_n=1^infty(4n)^n/nfactorial} 
The series can quickly be shown to be divergent by showing that $\lim\limits_{n\to \infty}\frac{( 4n)^n}{n!}=\infty $. Nonetheless we will use the ratio test, as it provides insight to what happens when we replace the constant $4$ with another constant. In order to establish the divergence of 
\[ 
\sum_{n=1}^{\infty }\frac{(4n)^{n}}{n!}\quad ,
\]
we shall use the ratio test. We recall that the ratio test states that if $\displaystyle \lim\limits_{n\to \infty} \frac{a_{n+1}}{a_{n}} $ exists and is equal to $L$, then if $L>1$ the series is divergent and if $L<1$ the series is convergent (if $L=1$ the test is inconclusive). 

We compute:
\[
\begin{array}{rcl}
\displaystyle\lim\limits_{n\to \infty} \frac{a_{n+1}}{a_{n}}&=&\displaystyle \lim \limits_{ n \to\infty} \left|\frac{(4n+4)^{n+1}n !}{ (n+ 1)! ( 4n )^{ n}} \right|\\
&=&\displaystyle
\lim\limits_{n\to\infty} \left| \frac{ (4n+4)(4n+4 )^{n}}{(n+1)(4n)^{n}}\right|\\
&=&\displaystyle \left(\lim\limits_{n\to\infty} \frac{4n+4}{n+1} \right) \left(\lim\limits_{n\to \infty} \left( \frac{n+1}{n}\right)^{n}\right)=4e> 1\quad,
\end{array}
\]
and therefore the series is divergent.
}




\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/convergence-x-to-the-nth-n-factorial-div-n-to-the-n-th.tex
Except for $x=\pm e$, use the ratio test to determine all real values of $x$ for which 
\[
\sum_{n=0}^{\infty}x^n\frac{n!}{n^n}
\]
is convergent. You are expected to use in your solution the fact that 
\[
\lim_{x\to 0}\left(1+\frac{x}{n}\right)^n=e^x\quad .
\]

\end{problem}
\subsection{Problems collection, all techniques}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/series/homework/series-convergent-or-divergent-all-techniques-1.tex
Determine if the series converges or diverges. Present a detailed motivation for your answer. 

\begin{enumerate}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{(2n+1)^n}{n^{2n}}  $
\answer{converges, root test}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{1}{n\sqrt{n^2+1}}  $
\answer{converges, comparison test}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{(-1)^n \sqrt{n}}{n+5}  $
\answer{converges, alternating series test}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{3n^2+4}{10n^2+1} $
\answer{diverges, summands do not tend to $0$}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{(n!)^2}{(n+1)!} $
\answer{diverges, ratio test, alternatively, summands tend to $\infty$}
\item $\displaystyle\sum\limits_{n=1}^\infty \frac{1}{e^{n^2}} $
\answer{converges, comparison test}

\end{enumerate}

\end{problem}

\section{Power series, Taylor and Maclaurin series}
\subsection{Interval of convergence}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/interval-of-convergence-1.tex
Determine the interval of convergence for the following power series. 
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemIntervalConvergence_sum(x-2)^n/(3sqrt(n+1))} $\displaystyle \sum_{n=1}^{\infty} \frac{(x-2)^n}{3\sqrt{n+1}}.$
\answer{$x\in [1, 3)$}
\item $\displaystyle \sum \limits_{n= 1}^{\infty} \frac{ 10^nx^n}{n^3}$.
\answer{$x\in \left[-\frac{1}{10}, \frac{1}{10} \right] $}
\item $\displaystyle \sum\limits_{n=0}^{\infty}(-1)^n \frac{(x- 3)^n }{ 2n+1} $.
\answer{$x\in (2, 4]$}
\end{enumerate}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/interval-of-convergence-1-solutions.tex
\solution{\ref{problemIntervalConvergence_sum(x-2)^n/(3sqrt(n+1))}.
We apply the Ratio Test to get that $\lim\limits_{n\to \infty }\left| \frac{ a_{n+1} }{a_n }\right| = |x-2|$. Therefore the power series converges at least on the interval $(1, 3)$. When $x = 3$, the series becomes $\sum\limits_{n=1}^{\infty} \frac{1}{3\sqrt{n+1}}$, which diverges - this can be seen, for example, by comparing to the $p$-series $\frac{1}{\sqrt{n}}$. When $x = 1$, the series becomes $\sum\limits_{n=1}^{\infty} \frac{(-1)^n}{3\sqrt{n+1}}$, which converges by the Alternating Series Test. Our final answer $x\in [1, 3)$.
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/interval-of-convergence-2.tex
Determine the interval of convergence for the following power series. The answer key has not been proofread, use with caution.
\begin{enumerate}
\item $\displaystyle \sum \limits_{n= 1}^{\infty} \frac{ 10^n(x-1)^n}{n^3}$
\answer{$x\in [0.9, 1.1]$}
\item $\displaystyle \sum\limits_{n=0}^{\infty}(-1)^n \frac{(x+1)^n }{ 2n+1} $
\answer{$x\in (-2, 0]$}
\end{enumerate}

\end{problem}
\subsection{Taylor, Maclaurin series}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-1.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item Find the Maclaurin series for $xe^{x^3}$.

\answer{$\displaystyle \sum\limits_{n=0}^{\infty} \frac{ x^{3n+1}}{ n!}$ }
\item Use your series to find the Maclaurin series of $\displaystyle\int x e^{x^3}\diff x$.

\answer{\begin{tabular}{l}
$\displaystyle C+\sum\limits_{n=0}^{\infty} \frac{ x^{3n+2}}{ (3n+2) n!}$\\
note the integral \\
can't be integrated with elementary\\
functions.
\end{tabular}
}
\end{enumerate}


\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-2.tex
Find the Maclaurin series of the function. The answer key has not been proofread, use with caution.
\begin{enumerate}
\item $\frac{1}{2x+3}$.

\answer{ $ \frac{1}{3}\left(1- \frac{2x}{3} +\left(\frac{2 x}{ 3} \right)^2 -\left(\frac{2x}{3}\right)^3+\dots\right) = \sum\limits_{0}^{ \infty} \frac{(-1)^n}{3}\left(\frac{2}{3}\right)^n x^n  $}
\item $\frac{1}{(1-x)^2}$.

\answer{ $1+2x+3x^2+4x^3+\dots=\sum\limits_{n=0}^{\infty} (n+1) x^n $}
\item $\frac{1}{(1-x)^3}$.

\answer{ $\frac{1}{2}\left( 2+6x+12x+\dots+n(n-1)x^{n-2}+\dots \right) =\sum\limits_{n=0}^{\infty} \frac{(n+1)(n+2)}{2} x^n$}
\item $x e^{-2x}$.

\answer{ $\sum\limits_{n=0}^{\infty} (-1)^n 2^{n} x^{n+1}= \sum\limits_{n=1}^{\infty} (-1)^{n-1} 2^{n-1} x^{n}$}
\end{enumerate}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-4.tex
Compute the Maclaurin series of the function. Please post on piazza if you discover errors in the answer key.
\begin{multicols}{2}
\begin{enumerate}
\item $e^x$.

\answer{ $\displaystyle  \sum\limits_{n=0}^\infty \frac{x^n}{n!} $  }
\item $e^{2x}$.

\answer{ $\displaystyle  e^{2x}=\sum\limits_{n=0}^\infty \frac{2^nx^n}{n!} $  }

\item $e^{x^2}$.

\answer{ $\displaystyle e^{x^2}= \sum\limits_{n=0}^\infty \frac{x^{2n}}{n!} $  }
\item $e^{-3x^2}$.

\answer{ $\displaystyle  e^{-3x^2}=\sum\limits_{n=0}^\infty \frac{(-1)^n 3^nx^{2n}}{n!} $  }
\item $x^2e^{2x}$.

\answer{ $\displaystyle  e^{2x}=\sum\limits_{n=0}^\infty \frac{ 2^n x^{n+2}}{n!} $  }
\item $\sin x$.

\answer{ $\displaystyle  \sin x=\sum\limits_{n=0}^\infty (-1)^n \frac{x^{2n+1}}{(2n+1)!} $  }
\item $\cos x$.

\answer{ $\displaystyle  \cos x=\sum\limits_{n=0}^\infty (-1)^n \frac{x^{2n}}{(2n)!} $  }
\item $\sin (2x)$.

\answer{ $\displaystyle  \sin (2x)=\sum\limits_{n=0}^\infty (-1)^n \frac{2^{2n+1} x^{2n+1}}{(2n+1)!} $  }
\item $\cos (2x)$.

\answer{ $\displaystyle  \cos (2x) =\sum\limits_{n=0}^\infty (-1)^n 2^{2n} \frac{x^{2n}}{(2n)!} $  }
\item $\cos^2 (x)$.

\answer{ $\displaystyle  \cos^2 x= \frac{1}{2} + \sum\limits_{ n=0}^\infty (-1)^n 2^{2n-1} \frac{x^{2n}}{(2n)!} $  }

\item $x\sin x$.

\answer{ $\displaystyle  x\sin x=\sum\limits_{n=0}^\infty (-1)^n \frac{x^{2n+2}}{(2n+1)!} $  }

\end{enumerate}
\end{multicols}

\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-5.tex
Compute the Maclaurin series of the function. Please post on piazza if you see errors in the answer key.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle \frac{1}{3-x}$.

\answer{$\displaystyle \sum\limits_{n=0}^{\infty} \frac{x^n}{3^{n+1}}$}
\item $\displaystyle \frac{1}{3-2x}$.

\answer{$\displaystyle \sum\limits_{n=0}^{\infty} \frac{ 2^n}{3^{n+1}}x^n $}

\item $\displaystyle \frac{1}{1+x^2}$.

\answer{$ \displaystyle \sum\limits_{n=0}^{\infty } (-1)^nx^{2n} $ }

\item $\displaystyle \frac{1}{1-2x^2}$.

\answer{ $ \displaystyle \sum\limits_{n=0}^{\infty } 2^n x^{2n} $ }
\item $\displaystyle \frac{1}{x^2-1}$. \label{problemMaclaurin(1/(x^2-1))}

\answer{$\displaystyle - \sum\limits_{n=0}^\infty x^{2n}$}
\item $\displaystyle\frac{\frac12}{x-1}-\frac{\frac12}{x+1}$.

\answer{same as \ref{problemMaclaurin(1/(x^2-1))}}
\item $\displaystyle \frac{1}{(1-x)^2}$.

\answer{$\displaystyle \sum\limits_{n=0}^\infty (n+1)x^{n} $}
\item $\displaystyle \frac{1}{(1-x)^3}$.

\answer{$\displaystyle \frac{1}{2}\sum\limits_{n=0}^\infty (n+1) (n+2)x^{n} = \sum\limits_{n=0}^{\infty} \binom{n+2}{2} x^n$}
\item $\displaystyle\ln (1+x)$.

\answer{ $\displaystyle \sum\limits_{n=1}^\infty (-1)^{n+1} \frac{x^n}{n} $}
\item $\ln (1-x)$.

\answer{ $\displaystyle -\sum\limits_{n=1}^\infty \frac{x^n}{n} $}
\item $\ln (1-3x)$.

\answer{ $\displaystyle -\sum\limits_{n=0}^\infty \frac{3^n x^n}{n} $}
\item $\ln (1-3x^2)$.

\answer{ $\displaystyle -\sum\limits_{n=1}^\infty \frac{3^nx^{2n }}{n} $}

\item \label{problemMaclaurin(ln(3-2x^2))} $\ln (3-2x^2)$.

\answer{ $\displaystyle \ln 3-\sum\limits_{n=1}^\infty \left(\frac{2}{3}\right)^n \frac{x^{2n }}{n} $}

\item $x\ln (3-2x^2)$.

\answer{ $\displaystyle x\ln 3-\sum\limits_{n=1}^\infty \left(\frac{2}{3}\right)^n \frac{x^{2n+1 }}{n} $}

\item $\displaystyle\arctan x$.

\answer{$\displaystyle \sum\limits_{n=0}^\infty \frac{(-1)^n x^{2 n+1 }}{2n+1}$ }
\item $\displaystyle\arctan (2x)$.

\answer{$\displaystyle \sum\limits_{n=0}^\infty \frac{(-1)^n 2^{2n +1} x^{2n+1}}{2n+1}$ }
\item $\displaystyle\arctan \left(2x^2\right)$.

\answer{$\displaystyle \sum\limits_{n=0}^\infty \frac{(-1)^n 2^{2n+1} x^{4n+2}}{2n+1}$ }

\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-5-solutions.tex
\solution{\ref{problemMaclaurin(ln(3-2x^2))}. 
We solve this problem by using algebraic manipulations and substitutions to reduce it to the already studied power series expansion of $\ln (1-y)=-\sum\limits_{n=1}^\infty \frac{y^n}{n}$.
\[
\begin{array}{rcll|l}
\ln \left(3-2x^2\right)&=& \displaystyle \ln \left(3 \left(1 -\frac{2}{3} x^2\right)\right)\\
&=&\displaystyle \ln 3+ \ln  \left(1 -\frac{2}{3} x^2\right)&&\text{Set } y=\frac{2}{3}x^2\\
&=&\displaystyle \ln 3+\ln (1-y)\\
&=&\displaystyle \ln 3-\sum\limits_{n=1}^\infty \frac{y^n}{n}&&\text{Substitute back } y=\frac{2}{3}x^2\\
&=&\displaystyle \ln 3-\sum\limits_{n=1}^\infty \left(\frac{2}{3}\right)^n\frac{x^{2n}}{n}\quad .
\end{array}
\]
}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/newton-binomial-integer-generalized.tex
\label{problemMaclaurin 1/(1-x)^k}
Compute the Maclaurin series of 
\[
\left(\frac{1}{(1-x)^k}\right)\quad ,
\]
where $n\geq 1$ is an integer. 

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/newton-binomial-integer-generalized-solution.tex
\solution{
\ref{problemMaclaurin 1/(1-x)^k}
We have that
\[
\begin{array}{r@{~}c@{~}lcl}
\displaystyle \frac{\diff }{\diff x}\left(\frac{1}{1-x}\right)&=&\displaystyle  \frac{ (1-x)'}{(1-x)^2} &=&\displaystyle  \frac{1}{(1-x)^2}\\
\displaystyle \frac{\diff^2 }{\diff x^2}\left(\frac{1}{1-x}\right)&=&\displaystyle \frac{\diff }{\diff x}\left(\frac{1}{ (1-x)^2}\right)=-2 \frac{(1-x)'}{(1-x)^3} &=&\displaystyle  \frac{2}{(1-x)^3}\\
\displaystyle \frac{\diff^3 }{\diff x^3}\left(\frac{1}{1-x}\right)&=&\displaystyle  \frac{\diff }{\diff x}\left( \frac{2}{ (1-x)^3}\right)=2(-3) \frac{(1-x)'}{(1-x)^4}&=&\displaystyle  \frac{2\cdot 3}{(1-x)^4}\\
\vdots \\
\displaystyle \frac{\diff^{k-2} }{\diff x^{k-2}}\left(\frac{1}{1-x}\right)&&&=& \displaystyle   \frac{(k-2)!}{(1-x)^{k-1}}\\
\displaystyle \frac{\diff^{k-2} }{\diff x^{k-2}}\left(\frac{1}{1-x}\right)&=&\displaystyle \displaystyle \frac{\diff }{\diff x} \left(\frac{(k-2)!}{(1-x)^{k-1}}\right) &=&\displaystyle   \frac{(k-1)!}{(1-x)^{k}}\\
\vdots 
\end{array}
\]
We can now compute Maclaurin series as follows:
\[
\begin{array}{r@{~}c@{~}ll|l}
\displaystyle
\maclaurin\left(\frac{1}{(1-x)^{k}}\right)&=& \displaystyle \maclaurin\left(\frac{1}{(k-1)!}  \frac{\diff^{k-1}}{\diff x^{k-1}}\left( \frac{1}{(1-x)}\right)\right)\\
&=&\displaystyle \frac{1}{(k-1)!}  \frac{\diff^{k-1}}{\diff x^{k-1}} \left(\maclaurin\left(\frac{1}{1-x}\right)\right)\\
&=&\displaystyle \frac{1}{(k-1)!}  \frac{\diff^{k-1}}{\diff x^{k-1}}\left(\sum\limits_{n=0}^{\infty} x^n\right)\\
&=&\displaystyle \frac{1}{(k-1)!}  \left(\sum\limits_{n=0}^{\infty} n(n-1)\dots (n-k+2) x^{n-k+1}\right)&&\text{Recall }\binom{n}{k}= \frac{n(n-1)\dots (n-k+1)}{k!} \\
&=&\displaystyle  \sum\limits_{n=0}^{\infty} \binom{n}{k-1} x^{n-k+1}&& 
\text{Set } n-k+1=m\\
&=&\displaystyle \sum\limits_{m=-k+1}^{\infty} \binom{m+k-1}{k-1} x^{m} &&
\text{first }k-2 \text{ summands are zero}
\\
&=&\displaystyle  \sum\limits_{m=0}^{\infty} \binom{m+k-1}{k-1} x^{m} 
\end{array} 
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/newton-binomial-generalized.tex
\label{problemMaclaurin(1+x)^q}
Compute the Maclaurin series of 
\[
(1+x)^q\quad ,
\]
where $q\in \mathbb R$ is an arbitrary real number. 



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/newton-binomial-generalized-solution.tex
\solution{\ref{problemMaclaurin(1+x)^q}
Since $q$ does not have to be an integer, we cannot directly relate its power series to the power series of $\frac{1}{1+x}$ or its derivatives. We therefore compute the Maclaurin series directly using \refBad{\ref{eqMacLaurinDef}}{their definition}{their definition (Definition \ref{eqMacLaurinDef})}.
\[
\begin{array}{rcl}
\frac{\diff}{\diff x}\left( (1+x)^q\right)&=& q (1+x)^{q-1}\\
\frac{\diff^{2}}{\diff x^2}\left( (1+x)^q\right)&=& q(q-1) (1+x)^{q-2}\\
\vdots \\
\frac{\diff^{n}}{\diff x^n}\left( (1+x)^q\right)&=& q(q-1)(q-2)\dots (q-n+1) (1 +x )^{ q-n}\quad .
\end{array}
\]
Therefore $\frac{\diff^{n}}{\diff x^n}\left( (1+x)^q\right)_{|x=0}=q( q-1) (q-2) \dots (q-n+1) (1+0)^{q-n}= q(q-1)(q-2)\dots (q-n+1)  $. Therefore
\begin{equation}\label{eqNewtonBinomialGeneralized}
\begin{array}{rcl}
\displaystyle \maclaurin \left( (1+x)^q\right) &=& \displaystyle\sum_{ n=0}^{ \infty} \frac{ 1}{n!}\frac{\diff^n }{\diff x^n} \left( (1+x)^q \right)_{ |x=0 } x^n  \\ &=& \displaystyle \sum_{n=0}^{\infty}  \frac{q( q-1) (q-2)\dots (q-n+1) }{n!}x^n= \sum_{ n=0 }^{\infty} \binom{q}{n}x^n\quad .
\end{array}
\end{equation}
For the last equality we recall the definition of binomial coefficient $\binom{ q }{n} = \frac{q(q-1)\dots (q-n+1)}{n!}$ and that it allows for $q$ to be an arbitrary complex number \refBad{\ref{eqBinomialCoeffDefinition}}{}{(see \eqref{eqBinomialCoeffDefinition})}. The above formula is a generalization of the Newton binomial formula\refBad{\ref{eqNewtonBinomialFormula}}{}{, \eqref{eqNewtonBinomialFormula}}. \index{binomial!generalized formula}
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-6.tex
Compute the Maclaurin series of the function.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemMaclaurinsqrt(1+x)} $\displaystyle \sqrt{1+x}$.

\answer{$ \sum\limits_{n=0}^\infty \binom{\frac{1}{2}}{n} x^n$}
\item \label{problemMaclaurin(1+x)^(-1/2)} $\displaystyle \frac{1}{\sqrt{1+x}}$.

\answer{$ \sum\limits_{n=0}^\infty \binom{-\frac{1}{2}}{n} x^n$}
\item \label{problemMaclaurin(1-x^2)^(-1/2)} $\displaystyle \frac{1}{ \sqrt{ 1- x^2 }}$.

\answer{$ \sum\limits_{n=0}^\infty (-1)^n\binom{- \frac{1}{2}}{n} x^{2n}$}
\item \label{problemMaclaurin(arcsin x)} $\displaystyle \arcsin x$.

\answer{$ \sum\limits_{n=0}^\infty (-1)^n\binom{- \frac{1}{2}}{n} \frac{x^{2n+1 } } { 2n + 1}$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-maclaurin-series-6-solutions.tex
\solution{\ref{problemMaclaurinsqrt(1+x)}
This problem follows directly from the formula $(1+x)^q=\sum\limits_{n=0}^\infty \binom{q}{n} x^n$. 
\[
\maclaurin \left(\sqrt{1+x}\right)=\maclaurin \left((1+x)^{\frac{1}{2}}\right)= \sum\limits_{n=0}^\infty \binom{\frac{1}{2}}{n} x^n\quad .
\]
}

\solution{\ref{problemMaclaurin(1+x)^(-1/2)}
This problem can be solved by computing the derivative of the preceding problem. However, it is easier to simply apply the generalized Newton Binomial formula.
\[
\maclaurin \left((1+x)^{-\frac{1}{2}}\right)= \sum\limits_{n=0}^\infty \binom{- \frac{1}{2 }}{ n} x^n\quad .
\]
}

\solution{\ref{problemMaclaurin(1-x^2)^(-1/2)}
This problem is solved by replacing $ x$ with $-x^2$ in Problem \ref{problemMaclaurin(1+x)^(-1/2)}. To avoid the possible confusion, we carry out the substitution by introducing an intermediate variable $y$.
\[
\begin{array}{rcll|l}
\displaystyle \maclaurin \left(\left(1-x^2\right)^{-\frac{1}{2}} \right)&=& \displaystyle   \maclaurin \left(\left(1+y\right)^{-\frac{1}{2}} \right) && \text{Set }y= -x^2 \\
&=&\displaystyle  \sum\limits_{n=0}^\infty \binom{- \frac{1}{2 }}{ n} y^n &&\text{Substitute back } y=-x^2\\
&=& \displaystyle  \sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} x^{2n}\quad .
\end{array}
\]
}

\solution{\ref{problemMaclaurin(arcsin x)} 
We have that $\frac{\diff }{\diff x}\left(\Arcsin x\right)=\frac{1}{ \sqrt{1- x^2}}$, and the Maclaurin series of $\frac{1}{ \sqrt{1- x^2}}$ were computed in Problem \ref{problemMaclaurin(1-x^2)^(-1/2)}. The power series of $\Arcsin x$ are therefore obtained via integration. 
\[
\begin{array}{rcll|l}
\displaystyle \frac{\diff }{\diff x}\maclaurin (\Arcsin x)&=&\displaystyle  \maclaurin \left(\frac{\diff}{\diff x} \left(\Arcsin x\right) \right)\\
&=&\displaystyle \maclaurin \left(\frac{1}{\sqrt{1-x^2}}\right) && \text{use Problem }\ref{problemMaclaurin(1-x^2)^(-1/2)} \\
&=&\displaystyle \sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} x^{2n}\\
\maclaurin \left(\Arcsin x\right)&=&\displaystyle \int \left(\sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} x^{2n}\right)\diff x\\
&=&\displaystyle C+\sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} \int x^{2n}\diff x\\
&=&\displaystyle C+\sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} \frac{ x^{2n+1}}{2n+1}&&C=0 \text{ since }\Arcsin 0=0\\
&=&\displaystyle \sum\limits_{ n=0 }^\infty (-1)^n \binom{- \frac{1}{2 }}{ n} \frac{ x^{2n+1}}{2n+1}\quad .
\end{array}
\]
}



\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-taylor-series-1.tex
Find the Taylor series of the function at the indicated point.
\begin{enumerate}[ref={\fcProblemRef}]
\item  $\frac{1}{x^2}$ at $a=-1$.

\answer{$\displaystyle 1+ 2(x+1)+3(x+1)^2+\dots = \sum\limits_{n=0}^\infty(n+1)(x+1)^n$ } 

\item \label{problemTaylorSeries a=1 ln(sqrt(x^2-2x+2))}
$\ln \left( \sqrt{x^2-2x+2} \right)$ at $a=1$.

\answer{$\displaystyle \sum_{n=1}^{\infty} (-1)^{n+1} \frac{(x-1)^{2n}}{2n}  $}

\item \label{problemTaylorlnxarounda=2}
Write the Taylor series of the function $\ln x$ around $a=2$.

\answer{$ \displaystyle \ln 2 +\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{2^n} (x-2)^n$}
\end{enumerate}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-taylor-series-1-solutions.tex
\solution{\ref{problemTaylorSeries a=1 ln(sqrt(x^2-2x+2))}
\[
\begin{array}{rcll|l}
\displaystyle \ln \left( \sqrt{x^2-2x+2} \right) &=&\displaystyle  \frac{ 1}{2} \ln \left( (x-1)^2+1\right)&&\text{use } \ln(1+y) =  \sum \limits_{n=1 }^ \infty (-1)^{n+1} \frac{y^n}{n}, |y|< 1 \\
&=&\displaystyle \frac{1}{2}\sum\limits_{n=1}^{\infty} (-1)^{n+1}\frac{\left((x-1)^2\right)^{n}}{n}\\
&=&\displaystyle \sum \limits_{n=1}^{\infty} (-1)^{n+1} \frac{( x-1)^{2n}}{2n}\quad .
\end{array}
\]

Although the problem does not ask us to do this, we will determine the interval of convergence of the series for exercise. If we use the fact that $\ln(1+y) =  \sum \limits_{n=1 }^ \infty (-1)^{n+1} \frac{y^n}{n}$ holds for $ -1<y\leq 1$, it follows immediately that the above equality holds for $ 0<(x-1)^2\leq 1$, which holds for $x\in[0,2]$. Let us however compute the interval of convergence without using the aforementioned fact.

Let $a_n$ be the $n^{th}$ term of our series, i.e., let 
\[
a_n= (-1)^{n+1} \frac{( x-1)^{2n}}{2n}\quad .
\]
We use the ratio test:
\[
\begin{array}{rcl}
\displaystyle \lim \limits_{ n\to \infty}\left| \frac{a_{n + 1} }{a_n }\right|&=&\displaystyle \lim \limits_{ n\to \infty }\left| \frac{(-1)^{n+2}(x-1)^{2n+2} }{ (2n+2)} \frac{ 2 n}{ (-1)^{n+1} ( x-1)^{2n} } \right|\\
&=&\displaystyle \lim_{n\to \infty} (x-1)^2 \frac{n}{n+1}\\
&=&\displaystyle (x-1)^2\quad .
\end{array}
\] 
By the ratio test, the series is divergent for $ (x-1)^2>1$, i.e., for $|x-1|>1$, and convergent for $(x-1)^2<1$, i.e., for $|x-1|<1$. The ratio test is inconclusive at only two points: $x-1=1$, i.e., $x=2$ and $x-1=-1$, i.e., $x=0$. At both points the series becomes $\displaystyle \sum\limits_{n=1}^{\infty} (-1)^{n+1} \frac{ 2^{ 2n}}{2n}$ and the series is convergent at both points by the alternating series test.
}

\solution{\ref{problemTaylorlnxarounda=2}
This solution is similar to the solution of \ref{problemTaylorSeries a=1 ln(sqrt(x^2-2x+2))}, but we have written it in a concise fashion suitable for test taking. 

Denote Taylor series at $a$ by $\taylor_a$ and recall that the Maclaurin series of are just $\taylor_0$, the Taylor series at $0$.
\[
\begin{array}{rcll|l}
\displaystyle \taylor_2(\ln x)&=& \displaystyle \taylor_2 (\ln \left((x-2)+2\right))\\
&=&\displaystyle \taylor_2\left(\ln \left(2\left(\frac{x-2}{2}+1\right) \right)\right)\\
&=&\displaystyle \taylor_2\left(\ln 2+ \ln \left(1+\frac{x-2}{2} \right) \right)&& T_0(\ln (1+y))=\sum\limits_{n=1}^\infty \frac{(-1)^{n+1}y^n}{n}\\
&=&\displaystyle \ln 2 + \sum_{n=1}^{\infty }\frac{(-1)^{n+1} \left(\frac{x-2}{2}\right)}{n}\\
&=&\displaystyle \ln 2 +\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{2^n} (x-2)^n\quad .
\end{array}
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/find-taylor-series-2.tex
Find the Taylor series around the indicated point. The answer key has not been proofread, use with caution.
\begin{enumerate}
\item  $\frac{1}{x}$ at $a=1$.
\answer{$\displaystyle 1- (x-1)+(x-1)^2-(x-1)^3+\dots = \sum\limits_{n=0}^\infty(-1)^n(x-1)^n$ } 
\item  $\frac{1}{x^2}$ at $a=1$.
\answer{$\displaystyle 1- 2(x-1)+3(x-1)^2-4(x-1)^3+\dots = \sum\limits_{n=0}^\infty(n+1)(-1)^n(x-1)^n$ } 
\end{enumerate}


\end{problem}
\subsection{Example of differentiable function not equal to its Maclaurin series}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/power-series/homework/example-non-zero-function-with-zero-maclaurin-series.tex
Let $f(x)$ be defined as 
\[
f(x):=\doublebrace{e^{-\frac{1}{x^2}}}{\mathrm{if~} x>0}{0}{\mathrm{otherwise.}}
\]
\begin{enumerate}[ref={\fcProblemRef}]
\item Prove that if $R(x)$ is an arbitrary rational function, 
\[
\lim\limits_{\substack{x\to 0\\ x>0}} R(x)e^{-\frac{1}{x^2}}=0
\]
\item Prove that $f(x)$ is differentiable at $0$ and $f'(0)=0$.
\item Prove that the Maclaurin series of $f(x)$ are 0 (but $f(x)$ is clearly a non-zero function).
\end{enumerate}

\end{problem}

\section{Complex numbers}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/complex-number-arithmetics-1.tex
\label{probComplexNumbersBasicOperations}
Carry out the operations. For some of the problems you may want to review the Newton Binomial formula\refBad{\ref{eqNewtonBinomialFormula}}{}{ \eqref{eqNewtonBinomialFormula}}.
\begin{multicols}{3}
\begin{enumerate}[ref={\fcProblemRef}]
\item $\displaystyle(5+3i)^2$.

\answer{$30 i+16 $}
\item $\displaystyle\frac{5+3i}{2-3i}$.

\answer{$ \frac{21}{13} i+\frac{1}{13} $}
\item $(5+3i)^{-2}$.

\answer{$-\frac{15}{578} i+\frac{4}{289} $}
\item $(1+i)^3$.

\answer{$2 i-2  $}
\item $(1+i)^4$.

\answer{$-4 $}
\item \label{eq(1+i)^5} $(1+i)^5$.

\answer{$ -4 i-4 $}
\item \label{eq(1+i)^-5} $(1+i)^{-5}$.

\answer{$\frac{1}{8} i-\frac{1}{8} $}
\end{enumerate}
\end{multicols}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/complex-number-arithmetics-1-solutions.tex
\solution{\ref{eq(1+i)^5}.
By the Newton Binomial formula\refBad{\ref{eqNewtonBinomialFormula}}{}{ \eqref{eqNewtonBinomialFormula}}, we have that 
\[
(1+i)^5= 1 + 5i + 10 i^2+ 10i^3+5i^4+i^5= 1-10+5 +i(5-10+1)=-4-4i.
\]
}

\solution{
\ref{eq(1+i)^-5}. Using the preceding example, we have that \[
(1+i)^{-5}=\frac{1}{(1+i)^5}=\frac{1}{ -4-4i}=\frac{-4+4i}{(-4-4i)(-4+4i)}=\frac{-4+4i}{32}=-\frac{1}{8}+\frac{1}{8}i\quad .
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/plot-complex-number-find-principal-argument-1.tex

Plot the number $z$ on the complex plane (you may use one drawing only for all the numbers). Find all real numbers $\varphi$ and $\rho$ for which $z=e^{\rho+i\varphi}$. Your answer may contain expressions of the form $\arcsin x$, $\arccos x$, $\arctan x$, $\ln x$, only if $x$ is a real number.
\begin{multicols}{2}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{prob1plussqrt3} $z=1+i\sqrt{3}$.

\answer{$z= e^{\ln 2 + i\left(\frac{\pi}3 +2k\pi\right)}$, $k\in \mathbb Z$}
\item \label{prob2plus3i} $z=-2-3i$.

\answer{$z= e^{\frac{1}{2}\ln (13) + i\left(\Arctan\left(\frac{3}{2}\right)+2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=1-i\sqrt{3}$.

\answer{$z= e^{\ln 2 + i\left(-\frac{\pi}3 +2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=1+i$.

\answer{$z= e^{\frac{1}{2}\ln 2 + i\left(\frac{\pi}4 +2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=-1-i$.

\answer{$z= e^{\frac{1}{2}\ln 2 + i\left(\frac{5\pi}{4} +2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=\frac{\sqrt{3}+i}{4}$.

\answer{$z= e^{-\ln 2 + i\left(\frac{\pi}{6} +2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=-i$.

\answer{$z= e^{ i\left(-\frac{\pi}{2} +2k\pi\right)}$, $k\in \mathbb Z$}
\item $z=3+4i$.

\answer{$z= e^{\ln 5 + i\left( \Arctan\left(\frac{4}{3} \right)+ 2k\pi\right)}$, $k\in \mathbb Z$}
\end{enumerate}
\end{multicols}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/plot-complex-number-find-principal-argument-1-solutions.tex
\solution{\ref{prob1plussqrt3}.

\noindent Solution I. We have that
\[
|z|=\sqrt{z\bar z}= \sqrt{\left(1+i\sqrt{3}\right)\left(1-i\sqrt{3}\right)}=\sqrt{1^2+\sqrt{3}^2}=\sqrt{4}=2\quad .
\]
Recall \refBad{\ref{eqEulerExp}}{that}{from \eqref{eqEulerExp} that} $e^{\rho +i \varphi}= e^{\rho}(\cos\varphi+i\sin \varphi) $ and therefore
\[
\begin{array}{rcl}
\cos \varphi &=&\displaystyle \frac{|z|\cos \varphi}{|z|}= \frac{\Re z}{|z|} =  \frac{1}{2}\\
\sin \varphi &=&\displaystyle \frac{|z|\sin \varphi}{|z|}= \frac{\Im z}{|z|} =  \frac{\sqrt{3}}2\\
\tan \varphi &=&\displaystyle \frac{\sin \varphi}{\cos \varphi}=  \frac{\sqrt{3}}3\quad .
\end{array}
\]
Therefore $\varphi$ is of the form $\varphi =  \arctan \left(\frac{\sqrt{3}}3\right)= \frac{\pi}3+k\pi$. However $\varphi$ cannot be of the form $ \frac{\pi}3+(2k+1)\pi$ because $\cos \left(\frac{\pi}3+(2k+1)\pi\right)=-\frac 12$. On the other hand, $\sin \left(\frac{\pi}{3}+2k\pi\right) = \frac{\sqrt{3}}2$ and $\cos \left(\frac{\pi}{3}+2k\pi\right) = \frac {1}{2})$. Therefore
\[
\varphi =\frac{\pi}{3}+2k\pi, \quad \quad \mathrm{for~all~} k\in \mathbb Z
\]
(Recall that $\mathbb Z$ denotes the integers).

As studied in class $e^{\rho}=|z|=2$, and therefore $\rho = \ln (e^\rho)= \ln |z|=\ln 2 $. Therefore we get the answer
\[
1+i\sqrt{3} = e^{\ln 2 +i \left(\frac{\pi}3+2k\pi  \right) }
\]
for all $k\in \mathbb Z$. To finish the task we need to plot the number $z$.

\optionalDisplay{
\psset{xunit=1cm,yunit=1cm}
\begin{pspicture*}(-3,-4)(4,4)
\psline[linecolor=gray](-1.5,0)(2.5,0) % x-axis
\psline[linecolor=gray](0,-1.5)(0,2.5) % y-axis
\rput[l](2.5,0){$\Re z$}
\rput[b](0,2.5){$\Im z$}
\rput[bl](0.03,1.03){$i$}
\rput[bl](1,-0.1){$1$}
\rput[c](0,1){$\bullet$}
\rput[c](1,0){$\bullet$}
\psplot{-1}{0.5}{1 x x mul sub sqrt}

\psplot[linecolor=red]{0.5}{1}{1 x x mul sub sqrt}

\psplot{-1}{1}{1 x x mul sub sqrt -1 mul}

\psline(0,0)(0.5,0.866)
\rput[c](0.5,0.866){$\bullet$}
\rput[l](0.47,1){$\frac{z}{|z|}$}
\psline[linestyle=dotted](0.5,0.866)(1,1.74)
\rput[l](1.1,1.81){$z=1+i\sqrt{3} $}
\rput[c](1,1.74){$\bullet$}

\rput[t](-2,-3){$-2-3i$}
\psline[linestyle=dotted](0,0)(-2,-3)
\rput[c](-2,-3){$\bullet$}

\rput[l](0.84,0.65){$\varphi= \frac\pi 3 $}
\end{pspicture*}
} %optionalDisplay

\noindent Solution II. We draw the number $z$ as above. We compute that $\sin \varphi = \frac{\Im z}{|z|}= \frac{ \sqrt{3} }{2}$, $\cos \varphi= \frac{\Re z}{|z| } = \frac{1 }{2}$. Therefore we have that
\[
1+i\sqrt{3}= e^{\ln|1+i\sqrt{3}| + i\left(\frac{\pi}3 +2 k \pi \right)}=  e^{\ln 2 + i\left(\frac{\pi}3 +2k \pi \right) }\quad .
\]
}

\solution{\ref{prob2plus3i}. 

We draw the number as indicated on the figure. We compute that $\sin \varphi =-\frac{3}{\sqrt{13}}$, $\cos \varphi = - \frac{ 2}{\sqrt{13}}$, $\tan \varphi = \frac{3}{2}$. By the convention of our course, $\arctan \varphi\in \left(- \frac{ \pi}{2}, \frac{\pi}{2}\right)$. Therefore $\varphi= \left( \Arctan \left( \frac{3}{2}\right) +\pi\right)+2k\pi $ for all $k\in \mathbb Z$. Finally, we get
\[
\begin{array}{rcl}
-2-3i&=& e^{\ln|-2-3i| + i \left(\left(\Arctan \left( \frac{ 3}{2} \right) +\pi\right) +2k\pi\right)}= e^{\ln \sqrt{13}  + i\left(\left(\Arctan\left(\frac{3}{2}\right) + \pi \right) +2k\pi\right)} \\&=&  e^{\frac{1}2\ln 13  + i \left( \left( \Arctan\left(\frac{3}{2}\right) +\pi\right) +2k \pi \right) } \quad .
\end{array}
\]
}



\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/find-nth-root-1.tex
Find all complex solutions of the equation. The answer key has not been proofread. Use with caution.

\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemz^3=i} $z^{3}=i$.

\answer{\begin{pspicture} (-1.2,-1.2)(1.2,1.2)
\tiny
\psaxes[labels=none, ticks=none]{<->}(0,0)(-1.4,-1.4)(1.4,1.4)
\rput[t](1.4,-0.1){$Re$}
\rput[r](-0.1,1.4){$Im$}
\parametricplot[linecolor=gray]{0}{360}{t cos t sin }
\psline[linecolor=blue](0,0)(!150 cos 150 sin )
\fcFullDot{ 150 cos}{150 sin }
\rput[rt](! 150 cos  150 sin ){$-\frac{ \sqrt{3 }}{ 2} +\frac{i}{2}~$}
\psline[linecolor=blue](0,0)(!30 cos 30 sin)
\fcFullDot{30 cos}{30 sin}
\rput[lt](! 30 cos 30 sin ){$~\frac{ \sqrt{3 }}{ 2} +\frac{i}{2}$}
\psline[linecolor=blue](0,0)(!-90 cos -90 sin )
\fcFullDot{!-90 cos}{-90 sin}
\rput[lt](0, -1.1){$-i$}
\end{pspicture}
\raisebox{1.2cm}{
$
\begin{array}{c|c}
\text{polar form }&\text{ value}\\\hline 
\cos \left(\frac{5\pi}{6}\right) +i\sin \left( \frac{ 5\pi }{6}\right)&  -\frac{\sqrt{3}}{2}+\frac{i}{2} \\
\cos \left(\frac{\pi}{6}\right) +i\sin \left( \frac{ \pi}{6} \right) &  \frac{ \sqrt{3 }}{ 2} +\frac{i}{2} \\
\cos \left(-\frac{\pi}{2}\right) +i\sin \left(-\frac{ \pi } {2} \right)& -i
\end{array}
$
}}
\item \label{problemz^3=-i/8} $\displaystyle z^3 = -\frac{i}{8}$.
\answer{\begin{pspicture} (-1.2,-1.2)(1.2,1.2)
\tiny
\fcAxesStandard{-1.2}{-1.2}{1.2}{1.2}
\fcLabels[$\Re$][$\Im$]{1.2}{1.2}
\parametricplot[linecolor=gray]{0}{360}{t cos 0.5 mul t sin 0.5 mul}
\psline[linecolor=blue](0,0)(!-150 cos 0.5 mul -150 sin 0.5 mul)
\fcFullDot{-150 cos 0.5 mul}{-150 sin 0.5 mul}
\rput[rt](! -150 cos 0.5 mul -150 sin 0.5 mul){$\frac{ \sqrt{3 }}{ 4} -\frac{i}{4}~$}
\psline[linecolor=blue](0,0)(!-30 cos 0.5 mul -30 sin 0.5 mul)
\fcFullDot{-30 cos 0.5 mul}{-30 sin 0.5 mul}
\rput[lt](! -30 cos 0.5 mul -30 sin 0.5 mul){$~-\frac{ \sqrt{3 }}{ 4} -\frac{i}{4}$}
\psline[linecolor=blue](0,0)(!90 cos 0.5 mul 90 sin 0.5 mul)
\fcFullDot{90 cos 0.5 mul}{90 sin 0.5 mul}
\rput[lb](0, 0.5){$~\frac{i}{2}$}
\end{pspicture}
\raisebox{1.2cm}{
$
\begin{array}{c|c}
\text{polar form }&\text{ value}\\\hline 
\frac{1}{2}\left(\cos \left(-\frac{5\pi}{6}\right) +i\sin \left(- \frac{ 5\pi }{6}\right) \right)&  -\frac{\sqrt{3}}{4}-\frac{i}{4} \\
\frac{1}{2}\left(\cos \left(-\frac{\pi}{6}\right) +i\sin \left( -\frac{ \pi}{6} \right) \right)&  \frac{ \sqrt{3 }}{ 4} -\frac{i}{4} \\
\frac{1}{2}\left(\cos \left(\frac{\pi}{2}\right) +i\sin \left(\frac{ \pi } {2} \right) \right)& \frac{i}{2} 
\end{array}
$
}}
\item $z^4=-16$.

\answer{$\pm \sqrt{2}\pm \sqrt{2}i$ (in all four combinations).}

\item $z^3=-27$.

\answer{$\frac{3}{2} +\frac{3\sqrt{3}}{2}i, \frac{3}{2} - \frac{3 \sqrt{3}}{2}i, -3$.}

\item $z^8=1$.

\answer{$\pm\frac{\sqrt{2 }}{2}\pm\frac{\sqrt{2}}{2}i $ (all four combinations), $\pm i$, $\pm 1$ (total 8 values).}


\end{enumerate}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/find-nth-root-1-solutions.tex
\noindent \solution{\ref{problemz^3=i}. Let $z=|z|(\cos \theta+i\sin \theta)$ be the polar form of $|z|$ for which $\theta\in(-\pi, \pi]$. We have  $|z|^3=\left| i \right| = 1$. Therefore $|z|=1$.


We can write $\displaystyle i$ in polar form as $\displaystyle i = \cos\left(\frac{ \pi}{2} \right) + i\sin\left(\frac{\pi}{2}\right)$. Therefore 
\[
\begin{array}{rcll|l}
z^3&=& i&&\text{use de Moivre's formula} \\
|z|^3 \left(\cos (3\theta)+i\sin (3\theta)\right)&=& \cos\left(\frac{ \pi}{2} \right) + i\sin\left(\frac{\pi}{2}\right) &&\text{use }|z|=1\\
\cos (3\theta)+i\sin (3\theta) &=&\cos\left(\frac{ \pi}{2} \right) + i\sin\left(\frac{\pi}{2}\right) &&\begin{array}{l}\text{when sines and cosines} \\
\text{coincide the angles differ}\\
\text{by even multiple of }\pi\end{array}
\\
3\theta&=&\frac{\pi}{2}+2k\pi, &&k-\text{integer}\\
\theta&=&\frac{\pi}{6}+k\frac{2\pi}{3}&&\theta\in(-\pi,\pi] \Rightarrow k=-1, 0, \text{ or }1  \\
\theta&=&-\frac{\pi}{2}, \frac{\pi}{6}, \text{ or } \frac{5\pi}{6}\quad .
\end{array}
\]


To find out the values of $z$ in non-polar form, we simply plot the numbers $z=(\cos \theta +i\sin \theta)$. The three complex solutions lie on a circle of radius $1$; the numbers form an equilateral triangle, as shown on the picture. To find the actual values for these complex numbers, we use known values of the trigonometric functions. Our final answer is as follows.

\begin{pspicture} (-1.2,-1.2)(1.2,1.2)
\tiny
\psaxes[labels=none, ticks=none]{<->}(0,0)(-1.4,-1.4)(1.4,1.4)
\rput[t](1.4,-0.1){$Re$}
\rput[r](-0.1,1.4){$Im$}
\parametricplot[linecolor=gray]{0}{360}{t cos t sin }
\psline[linecolor=blue](0,0)(!150 cos 150 sin )
\psdot*(! 150 cos 150 sin )
\rput[rt](! 150 cos  150 sin ){$-\frac{ \sqrt{3 }}{ 2} +\frac{i}{2}~$}
\psline[linecolor=blue](0,0)(!30 cos 30 sin)
\psdot*(!30 cos  30 sin )
\rput[lt](! 30 cos 30 sin ){$~\frac{ \sqrt{3 }}{ 2} +\frac{i}{2}$}
\psline[linecolor=blue](0,0)(!-90 cos -90 sin )
\psdot*(!-90 cos -90 sin )
\rput[lt](0, -1.1){$-i$}
\end{pspicture}
\raisebox{1.2cm}{
$
\begin{array}{c|c}
\text{polar form }&\text{ value}\\\hline 
\cos \left(\frac{5\pi}{6}\right) +i\sin \left( \frac{ 5\pi }{6}\right)&  -\frac{\sqrt{3}}{2}+\frac{i}{2} \\
\cos \left(\frac{\pi}{6}\right) +i\sin \left( \frac{ \pi}{6} \right) &  \frac{ \sqrt{3 }}{ 2} +\frac{i}{2} \\
\cos \left(-\frac{\pi}{2}\right) +i\sin \left(-\frac{ \pi } {2} \right)& -i
\end{array}
$
}
}

\noindent \solution{
\ref{problemz^3=-i/8}

Let $z=|z|(\cos \theta+i\sin \theta)$ be the polar form of $|z|$ for which $\theta\in(-\pi, \pi]$. We have  $|z|^3=\left| \frac{i}{8 } \right| = \frac{1}{8}$. Since $|z|$ is a positive real number it follows that $\displaystyle |z|=\sqrt[3]{\frac{1}{8}}=\frac{1}{2}$.

We can write $\displaystyle-\frac{i}{8}$ in polar form as $\displaystyle - \frac{ i}{8} = \frac{1 }{8}\left( \cos\left(- \frac{ \pi}{2} \right) + i\sin\left(-\frac{\pi}{2}\right)  \right)$. Therefore 
\[
\begin{array}{rcll|l}
z^3&=& \frac{-i}{8}&&\text{use de Moivre's formula} \\
|z|^3\left(\cos (3\theta)+i\sin (3\theta)\right)&=&\frac{1 }{8}\left( \cos\left(- \frac{ \pi}{2} \right) + i\sin\left(-\frac{\pi}{2}\right)  \right) &&\text{use }|z|=\frac{1}{2}\\
\cos (3\theta)+i\sin (3\theta)&=&\cos\left(- \frac{ \pi}{2} \right) + i\sin\left(-\frac{\pi}{2}\right) &&\begin{array}{l} \text{when sines and cosines} \\
\text{coincide the angles differ}\\
\text{by even multiple of }\pi\end{array}
\\
3\theta&=&-\frac{\pi}{2}+2k\pi, &&k-\text{integer}\\
\theta&=&-\frac{\pi}{6}+k\frac{2\pi}{3}&&\theta\in(-\pi,\pi] \Rightarrow k=-1, 0, \text{ or }1  \\
\theta&=&-\frac{5\pi}{6}, -\frac{\pi}{6}, \text{ or } \frac{\pi}{2}\quad .
\end{array}
\]
To find out the values of $z$ in non-polar form, we simply plot the numbers $z=\frac{1}{2}(\cos \theta +i\sin \theta)$. The three complex solutions lie on a circle of radius $\frac{1}{2}$; the numbers form an equilateral triangle, as shown on the picture. To find the actual values for these complex numbers, we use known values of the trigonometric functions. Our final answer is as follows.

\begin{pspicture} (-1.2,-1.2)(1.2,1.2)
\tiny
\fcAxesStandard{-1.2}{-1.2}{1.2}{1.2}
\fcLabels[$\Re$][$\Im$]{1.2}{1.2}
\parametricplot[linecolor=gray]{0}{360}{t cos 0.5 mul t sin 0.5 mul}

\psline[linecolor=blue](0,0)(!-150 cos 0.5 mul -150 sin 0.5 mul)
\fcFullDot{-150 cos 0.5 mul}{-150 sin 0.5 mul}
\rput[rt](! -150 cos 0.5 mul -150 sin 0.5 mul){$\frac{ \sqrt{3 }}{ 4} -\frac{i}{4}~$}

\psline[linecolor=blue](0,0)(!-30 cos 0.5 mul -30 sin 0.5 mul)
\fcFullDot{-30 cos 0.5 mul}{-30 sin 0.5 mul}
\rput[lt](! -30 cos 0.5 mul -30 sin 0.5 mul){$~-\frac{ \sqrt{3 }}{ 4} -\frac{i}{4}$}

\psline[linecolor=blue](0,0)(!90 cos 0.5 mul 90 sin 0.5 mul)
\fcFullDot{90 cos 0.5 mul}{90 sin 0.5 mul}
\rput[lb](0, 0.5){$~\frac{i}{2}$}

\end{pspicture}
\raisebox{1.2cm}{
$
\begin{array}{c|c}
\text{polar form }&\text{ value}\\\hline 
\frac{1}{2}\left(\cos \left(-\frac{5\pi}{6}\right) +i\sin \left(- \frac{ 5\pi }{6}\right) \right)&  -\frac{\sqrt{3}}{4}-\frac{i}{4} \\
\frac{1}{2}\left(\cos \left(-\frac{\pi}{6}\right) +i\sin \left( -\frac{ \pi}{6} \right) \right)&  \frac{ \sqrt{3 }}{ 4} -\frac{i}{4} \\
\frac{1}{2}\left(\cos \left(\frac{\pi}{2}\right) +i\sin \left(\frac{ \pi } {2} \right) \right)& \frac{i}{2} 
\end{array}
$
}
}

\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/polar-form-complex-numbers-1.tex
Express the number in polar form and compute the indicated power. The answer key has not been proofread, use with caution.

\begin{enumerate}
\item $z=\sqrt{3}+i$, find $z^3$.

\answer{$z=\sqrt{3}+i= 2\left(\cos\left( \frac{\pi}{6} \right) +i\sin\left( \frac{\pi}{6}\right) \right)$, $z^3= 8\left( \cos\left( \frac{\pi}{2} \right)+ i\sin\left( \frac{ \pi }{2} \right) \right)=8i.$}

\item $z=\sqrt{3}i-1$, find $z^{10}$.

\answer{$z=2\left(\cos\left(\frac{2\pi}{3} \right)+i\sin \left( \frac{2\pi}{3} \right) \right)$, $z^{10}= 2^{10} \left(- \frac{1}{2} +\frac{\sqrt{3 }}{2} i\right) = -512 +512 \sqrt{3}i .$ }

\item $z= -1-i$, find $z^{21}$.

\answer{$z=\sqrt{2} \left(\cos\left(\frac{5}{4}\pi\right) + \sin \left( \frac{5}{4} \pi\right) \right)$, $z^{21}= 1024+ 1024 i $.}
\end{enumerate}  



\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/complex-numbers/homework/trig-identities-via-Euler-formula-1.tex
The de Moivre follows directly from Euler's formula and states that $(\cos (n\alpha) +i\sin (n\alpha) )= (\cos \alpha +i\sin\alpha)^n$. Expand the indicated expression and use it to express $\cos (n\alpha)$ and $\sin (n\alpha)$ via $\cos \alpha$ and $\sin \alpha$.

You may want to use the Newton binomial formulas (derived, say, via Pascal's triangle). The formulas you may want to use are:
\[
\begin{array}{rcl}
(a+b)^2&=&a^2+2ab+b^2\\
(a+b)^3&=&a^3+3a^2b+3ab^2+b^3\\
(a+b)^4&=&a^4+4a^3b+6a^2b^2+4ab^3+b^4\quad .\\
\end{array}
\]

\begin{enumerate}
\item Expand $(\cos \alpha +i\sin \alpha)^2$. Express $\cos (2\alpha)$ and $\sin(2\alpha) $ via $\cos \alpha$ and $\sin \alpha$.

\answer{ $\begin{array}{rcl}
\cos (2\alpha)&=&\cos^2\alpha-\sin^2\alpha \\
\sin (2\alpha)&=&2\sin\alpha\cos\alpha.
\end{array}
$
}
\item Expand $(\cos \alpha +i\sin \alpha)^3$. Express $\cos (3\alpha)$ and  $\sin(3\alpha) $ via $\cos \alpha$ and $\sin \alpha$.

\answer{$
\begin{array}{rcl}
\cos (3\alpha)&=&\cos^3\alpha-3\cos\alpha \sin^2 \alpha \\ \sin (3\alpha)&=&-\sin^3\alpha+ 3\sin\alpha \cos^2\alpha.
\end{array}
$}
\item Expand $(\cos \alpha +i\sin \alpha)^4$. Express $\cos (4\alpha)$ and  $\sin(4\alpha) $ via $\cos \alpha$ and $\sin \alpha$.

\answer{$
\begin{array}{rcl}
\cos (4\alpha)&=&\cos^4\alpha-6\cos^2\alpha \sin^2 \alpha-\sin^4\alpha \\
\sin (4\alpha)&=& 4\sin\alpha \cos^3 \alpha - 4\sin^3\alpha \cos\alpha.
\end{array}
$}

\end{enumerate}

\end{problem}
\section{Curves}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/match-x-t-and-y-t-graph-to-x-y-graph-1.tex
Match the graphs of the parametric equations $x=f(t)$, $y=g(t)$ with the graph of the parametric curve $ \gamma \left| \begin{array}{rcl}x&=&f(t)\\y&=&g(t) \end{array}\right.$
\psset{xunit=0.5cm, yunit=0.5cm, algebraic=true}
\begin{multicols}{2}
\begin{enumerate}
\item
\begin{pspicture}(-0.2, -1.2)(2.2,1.2)
\tiny
\fcAxesStandard{-0.5}{-1.2}{2.2}{1.2}
\fcXTickWithLabel{1}{$1$}
\parametricplot[linecolor=\fcColorGraph, plotpoints=500]{-3.14159}{3.14159}{sin(t)+1|sin(2*t)}
\end{pspicture}
\answer{matches to \ref{itemMatchx=1+sin(t),y=sin(2t)}}

\item
\begin{pspicture}(-1.5, -1.5)(1.5,1.5)
\tiny
\fcAxesStandard{-1.4}{-1.4}{1.4}{1.4}
\fcXTickWithLabel{1}{$1$}
\parametricplot[linecolor=\fcColorGraph, plotpoints=500]{-3.14159}{3.14159}{sin(2*t)|sin(3*t)}
\end{pspicture}
\answer{matches to \ref{itemMatchx=sin2t,y=sin3t}}

\item
\begin{pspicture}(-2.7, -2.7)(2.7,2.7)
\tiny
\fcAxesStandard{-2.5}{-0.5}{2.5}{2.5}
\fcXTickWithLabel{1}{$1$}
\parametricplot[linecolor=\fcColorGraph,  plotpoints=500]{-2}{2}{t*(t-1.75)*(t+1.75)|sqrt(4-t*t) }
\end{pspicture}
\answer{matches to \ref{itemMatchx=cubic,y=sqrt}}
\end{enumerate}

\columnbreak
\begin{enumerate}
\item \label{itemMatchx=sin2t,y=sin3t}
\begin{pspicture}(-3.3, -1.2)(3.3,1.2)
\tiny
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-3.2, -1.1)(3.2, 1.1)
\fcLabels[$t$][$x$]{3.2}{1.1}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-3.14159}{3.14159}{sin(2*x)}
\end{pspicture}
\begin{pspicture}(-3.3, -1.2)(3.3,1.2)
\tiny
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-3.2, -1.1)(3.2, 1.1)
\fcLabels[$t$][$y$]{3.2}{1.1}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-3.14159}{3.14159}{sin(3*x)}
\end{pspicture}
\item \label{itemMatchx=cubic,y=sqrt}
\begin{pspicture}(-2.7, -2.7)(2.7,2.7)
\tiny
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-2.5, -2.5)(2.5, 2.5)
\fcLabels[$t$][$x$]{2.5}{2.5}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-2}{2}{x*(x-1.75)*(x+1.75)}
\end{pspicture}
\begin{pspicture}(-2.3, -0.5)(2.3,2,3)
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-2.2, -0.5)(2.2, 2.2)
\fcLabels[$t$][$y$]{2.2}{2.2}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-2}{2}{sqrt(4-x*x)}
\end{pspicture}

\item \label{itemMatchx=1+sin(t),y=sin(2t)}
\begin{pspicture}(-3.3, -0.5)(3.3,2.2)
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-3.2, -0.5)(3.2, 2.5)
\fcLabels[$t$][$x$]{3.2}{2.5}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-3.14159}{3.14159}{sin(x)+1}
\end{pspicture}
\begin{pspicture}(-3.3, -1.2)(3.3,1.2)
\psaxes[ticks=none, labels=none, arrows=<->](0,0)(-3.2, -1.1)(3.2, 1.1)
\fcLabels[$t$][$y$]{3.2}{1.1}
\fcXTickWithLabel{1}{$1$}
\psplot[linecolor=blue, plotpoints=500]{-3.14159}{3.14159}{sin(2*x)}
\end{pspicture}


\end{enumerate}
\end{multicols}


\end{problem}
\subsection{Curves in polar coordinates}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/match-polar-curve-graph-to-formula.tex
Match the graph of the curve to its graph in polar coordinates and to its polar parametric equations.

\psset{xunit=0.5cm, yunit=0.5cm}
\begin{multicols}{3}
\begin{enumerate}
\item \begin{pspicture}(-2.323256, -3.101443)(3.400000,3.201443)
\tiny
\fcAxesStandard{-2.073256}{-2.851443}{3.150000}{2.851443}
%Calculator command: drawPolarExtended{}(\cos{}(3 t)+2, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{2.0000000 t 3.0000000 mul 57.29578 mul cos add t 57.29578 mul cos mul 2.0000000 t 3.0000000 mul 57.29578 mul cos add t 57.29578 mul sin mul }
\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=2+cos(3*t)}, \ref{itemMatchPolarFormula,r=2+cos(3*t)}}
\item
\begin{pspicture}(-3.269100, -2.893230)(3.268991,3.499862)
\tiny
\fcAxesStandard{-3.019100}{-2.643230}{3.018991}{3.149862}
%Calculator command: drawPolarExtended{}(\sin{}(5 t)+2, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{2.0000000 t 5.0000000 mul 57.29578 mul sin add t 57.29578 mul cos mul 2.0000000 t 5.0000000 mul 57.29578 mul sin add t 57.29578 mul sin mul }
\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=2+sin(5t)}, \ref{itemMatchPolarFormula,r=2+sin(5t)}}
\item
\begin{pspicture}(-3.515530, -0.900000)(3.541593,2.319691)
\tiny
\fcAxesStandard{-3.265530}{-0.650000}{3.291593}{1.969691}
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{-3.14159}{3.14159}{t t 57.29578 mul cos mul t t 57.29578 mul sin mul }
\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=t}, \ref{itemMatchPolarFormula,r=t} }
\item
\begin{pspicture}(-0.962477, -1.280083)(1.400000,1.380083)

\tiny
\fcAxesStandard{-0.712477}{-1.030083}{1.150000}{1.030083}
%Calculator command: drawPolarExtended{}(\cos{}(3 t), 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{t 3.0000000 mul 57.29578 mul cos t 57.29578 mul cos mul t 3.0000000 mul 57.29578 mul cos t 57.29578 mul sin mul }

\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=cos(3t)}, \ref{itemMatchPolarFormula,r=cos(3t)}}

\item
\begin{pspicture}(-1.122338, -1.122308)(2.550479,2.650486)
\tiny
\fcAxesStandard{-0.872338}{-0.872308}{2.300479}{2.300486}
%Calculator command: drawPolarExtended{}(\sin{}t+\cos{}t+1, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{1.0000000 t 57.29578 mul cos add t 57.29578 mul sin add t 57.29578 mul cos mul 1.0000000 t 57.29578 mul cos add t 57.29578 mul sin add t 57.29578 mul sin mul }
\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=1+sin(t)+cos(t)}, \ref{itemMatchPolarFormula,r=1+sin(t)+cos(t)}}

\item
\begin{pspicture}(-1.729462, -1.765832)(1.787465,1.792057)
\tiny
\fcAxesStandard{-1.479462}{-1.515832}{1.537465}{1.442057}
%Calculator command: drawPolarExtended{}(1/4 \sqrt{t}, 0, 10 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{31.4159}{t sqrt 0.2500000 mul t 57.29578 mul cos mul t sqrt 0.2500000 mul t 57.29578 mul sin mul }
\end{pspicture}
\answer{matches \ref{itemMatchPolarGraph,r=sqrt(t)}, \ref{itemMatchPolarFormula,r=1/4sqrt(t)}}

\end{enumerate}

\columnbreak
\begin{enumerate}

\item \label{itemMatchPolarGraph,r=sqrt(t)}
\begin{pspicture}(-0.900000, -0.900000)(5.9,1.898448)
\tiny
\fcAxesStandard{-0.650000}{-0.650000}{5.565927}{1.548448}
\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false]{0}{5.9}{t t sqrt 0.2500000 mul }
\end{pspicture}

\item \label{itemMatchPolarGraph,r=2+cos(3*t)}
\begin{pspicture}(-0.900000, -0.900000)(6.683185,3.500000)
\tiny
\fcAxesStandard{-0.650000}{-0.650000}{6.433185}{3.150000}
\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false]{0}{6.28319}{t 2.0000000 t 3.0000000 mul 57.29578 mul cos add }
\end{pspicture}

\item \label{itemMatchPolarGraph,r=2+sin(5t)}
\begin{pspicture}(-0.900000, -0.900000)(6.683185,3.499995)
\tiny
\fcAxesStandard{-0.650000}{-0.650000}{6.433185}{3.149995}
\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false]{0}{6.28319}{t 2.0000000 t 5.0000000 mul 57.29578 mul sin add }
\end{pspicture}

\item \label{itemMatchPolarGraph,r=1+sin(t)+cos(t)}
\begin{pspicture}(-0.900000, -0.900000)(6.683185,2.914198)
\tiny
\fcAxesStandard{-0.650000}{-0.650000}{6.433185}{2.564198}
\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false]{0}{6.28319}{t 1.0000000 t 57.29578 mul cos add t 57.29578 mul sin add }
\end{pspicture}
\item \label{itemMatchPolarGraph,r=t}
\begin{pspicture}(-3.541593, -3.541593)(3.541593,3.616510)
\tiny
\fcAxesStandard{-3.291593}{-3.291593}{3.291593}{3.266510}\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false]{-3.14159}{3.14159}{t t}
\end{pspicture}

\item \label{itemMatchPolarGraph,r=cos(3t)}
\begin{pspicture}(-0.900000, -1.399823)(6.683185,1.500000)
\tiny
\fcAxesStandard{-0.650000}{-1.149823}{6.433185}{1.150000}
\parametricplot[linecolor=\fcColorTangent, plotpoints=1000, algebraic=false] {0}{6.28319}{t t 3.0000000 mul 57.29578 mul cos }

\end{pspicture}


\end{enumerate}
\columnbreak
\renewcommand\theenumii{\roman{enumii}}
\begin{enumerate}
\item \label{itemMatchPolarFormula,r=1+sin(t)+cos(t)} $r=1+\sin(\theta)+cos(\theta)$
\item \label{itemMatchPolarFormula,r=t} $r= \theta, \theta\in [-\pi, \pi]$.
\item \label{itemMatchPolarFormula,r=cos(3t)} $r= \cos(3\theta), \theta\in [0, 2\pi]$.
\item \label{itemMatchPolarFormula,r=1/4sqrt(t)}
$r=\frac{1}4\sqrt{\theta}, \theta\in [0, 10\pi]$.
\item \label{itemMatchPolarFormula,r=2+sin(5t)} $r=2+\sin (5\theta) $.
\item \label{itemMatchPolarFormula,r=2+cos(3*t)} $r=2+cos(3\theta)$.
\end{enumerate}
\end{multicols}


\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/sketch-the-curve-1.tex
~\begin{enumerate}[ref={\fcProblemRef}]
\item Sketch the curve given in polar coordinates by $r=2\sin \theta $. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.
\item Sketch the curve given in polar coordinates by $r=4\cos \theta $. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.
\item \label{problemPolarSketchr=2sec(theta)}  Sketch the curve given in polar coordinates by $r=2\sec \theta $. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.
\answer{the curve is the line $x=2$}
\item Sketch the curve given in polar coordinates by $r=2\csc \theta $. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.
\item \label{problemPolarSketchr=2sec(theta+pi/4)} Sketch the curve given in polar coordinates by $r=2\sec \left(\theta + \frac{\pi}{4} \right) $. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.
\answer{the curve is the line $y=x-2\sqrt{2}$}

\item Sketch the curve given in polar coordinates by $r=2\csc\left(\theta +\frac{\pi}{6}\right)$. What kind of a figure is this curve? Find an equation satisfied by the curve in the $(x,y)$-coordinates.

\end{enumerate}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/sketch-the-curve-1-solutions.tex
\solution{\ref{problemPolarSketchr=2sec(theta)}.
Recall from trigonometry that if we draw a unit circle as shown below, $\sec \theta$ is given by the signed distance as indicated on the figure. Therefore it is clear that the curve given in polar coordinates by $y=\sec \theta$ is the vertical line passing through $x=1$. Analogous considerations can be made for a circle of radius $2$, from where it follows that $y=2\sec \theta$ is the vertical line passing through $x=2$.

Alternatively, we can find an equation in the $(x,y)$-coordinates of the cuve by the direct computation: \[x= r\cos \theta= 2\sec\theta \cos \theta = 2\quad .
\]
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.39998, -1.399995)(1.4,2.7)
\tiny
\fcAxesStandard{-1.14998}{-1.149995}{1.15}{2.6}
%Calculator command: drawPolar{}(1, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 1 t 57.29578 mul cos mul 1 t 57.29578 mul sin mul }
\fcAngle{0}{1.107149}{0.2}{$\theta$}
\psline(0,0)(1,2)
\psline(1,-1)(1,2.6)
\fcLengthIndicator{-0.1}{0.05}{0.9}{2.05}{}
\rput[r](0.5,1.1){$\sec \theta$}
\end{pspicture}
}
\solution{
\ref{problemPolarSketchr=2sec(theta+pi/4)}.

\noindent \textbf{Approach I.}
Adding an angle $\alpha$ to the angle polar coordinate of a point corresponds to rotating that point counterclockwise at an angle $\alpha$ about the origin. Therefore a point $P$ with polar coordinates $P\left( 2\sec \left(\theta + \frac{\pi }{ 4} \right) ,\theta\right)$ is obtained by rotating at an angle $-\frac{\pi}{4}$ the point $Q$ with polar coordinates $Q\left( 2\sec \left(\theta + \frac{\pi }{ 4} \right) ,\theta+ \frac{\pi}{4} \right)$. The point $P$ lies on the curve with equation $r=2\sec \left(\theta+ \frac{\pi}{4}\right)$ and the point $Q$ lies on the curve with equation $r=2\sec \theta$ - the latter curve is the curve from problem \ref{problemPolarSketchr=2sec(theta)}. Thus the curve in the current problem is obtained by rotating the curve from \ref{problemPolarSketchr=2sec(theta)} at an angle of $-\frac{\pi}{4}$. As the curve in Problem \ref{problemPolarSketchr=2sec(theta)} is the vertical line $x=2$, the curve in the present problem is also a line. Rotation at an angle of $-\frac{\pi}{4}$ of a vertical line yields a line with slope $1$. When $\theta=0$, $x=\frac{2}{\frac{\sqrt{2}}{2}}= 2\sqrt{2}$, $y=0$ and the curve passes through $(2\sqrt{2}, 0)$. We know the slope of a line and a point through which it passes; therefore the $(x,y)$-coordinates of our curve satisfy
\[
y=x-2\sqrt{2}\quad .
\]

\noindent \textbf{Approach II. } We compute
\[
\begin{array}{rcll|l}
x&=&\displaystyle r\cos \theta = \frac{2\cos \theta}{\cos (\theta +\frac{\pi}{4})} &&\text{multiply by }\cos \left(\frac{\pi}{4}\right)=\frac{\sqrt{2}}{2} \\
y&=&\displaystyle r\sin \theta = \frac{2\sin \theta}{\cos (\theta +\frac{\pi}{4})} &&\text{multiply by }-\sin \left(\frac{\pi}{4}\right)= -\frac{\sqrt{2 }}{2} \\\hline
&&&&\text{add the above }
\\
x\cos \left(\frac{\pi}{4} \right) -y \sin\left( \frac{\pi}{4}\right)&=&\displaystyle  2 \frac{\cos \theta\cos  \left(\frac{\pi}{4} \right) - \sin \theta \sin  \left(\frac{\pi}{4} \right) }{\cos  \left(\theta +\frac{\pi}{4} \right)} &&\text{use } \cos (\alpha+\beta)=\cos \alpha\cos \beta-\sin\alpha\sin\beta\\
\frac{\sqrt{2}}{2}\left(x-y\right)&=&\displaystyle 2\frac{\cos\left(\theta +\frac{\pi}{4} \right)}{\cos\left(\theta +\frac{\pi}{4} \right)}=2\\
y&=&\displaystyle x-2\sqrt{2},
\end{array}
\]
and therefore our curve is the line given by the equation above.
}


\subsection{Curve tangents}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/find-horizontal-vertical-tangents.tex
Find the values of the parameter $t$ for which the curve has horizontal and vertical tangents.
\begin{multicols}{2}
\begin{enumerate}
\item $y=t^2-t+1$, $x=t^2+t-1$

\psset{xunit=0.25cm, yunit=0.25cm}
\begin{pspicture}(-0.9, -1.65)(13.4,11.416228)
\tiny
\fcAxesStandard{-0.65}{-1.4}{13.15}{11.066228}
%Calculator input: plotCurve{}(t^{2}- t+1, t^{2}+t-1, -3, 3)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-3}{3}{ 1 t -1 mul add t 2 exp add -1 t add t 2 exp add }
\end{pspicture}
\item $x=t^3-t^2-t+1$, $y=t^2-t-1 $.

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-0.9, -1.649998)(3.358221,1.5)
\tiny
\fcAxesStandard{-0.65}{-1.399998}{3.108221}{1.15}
%Calculator input: plotCurve{}(t^{3}- t^{2}- t+1, t^{2}- t-1, -1, 2)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-1}{2}{ 1 t -1 mul add t 2 exp -1 mul add t 3 exp add -1 t -1 mul add t 2 exp add }
\end{pspicture}
\item $x=\cos (t)$, $y=\sin (3t)$

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.4, -1.399999)(1.4,1.499999)
\tiny
\fcAxesStandard{-1.15}{-1.149999}{1.15}{1.149999}
%Calculator input: plotCurve{}(\cos{}t, \sin{}(3 t), - \pi, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-3.14159}{3.14159}{t 57.29578 mul cos t 3 mul 57.29578 mul sin }
\end{pspicture}
\item $x=\cos (t)+\sin (t)$ , $y=\sin (t)$.

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.814213, -1.399999)(1.81421,1.499999)
\tiny
\fcAxesStandard{-1.564213}{-1.149999}{1.56421}{1.149999}
%Calculator input: plotCurve{}(\sin{}t+\cos{}t, \sin{}t, - \pi, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-3.14159}{3.14159}{t 57.29578 mul cos t 57.29578 mul sin add t 57.29578 mul sin }
\end{pspicture}
\end{enumerate}
\end{multicols}


\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/show-multiple-tangents.tex
Show that the parametric curve has multiple tangents at the point and find their slopes.
\begin{multicols}{2}
\begin{enumerate}
\item $x=\cos t$, $y=2\sin (2t)$, two tangents at $(x,y)=(0,0)$.

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.4, -2.399998)(1.4,2.499998)
\tiny
\fcAxesStandard{-1.15}{-2.149998}{1.15}{2.149998}
%Calculator input: plotCurve{}(\cos{}t, 2 \sin{}(2 t), - \pi, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-3.14159}{3.14159}{t 57.29578 mul cos t 2 mul 57.29578 mul sin 2 mul }
\end{pspicture}
\item $x=\cos t \sin (3t)$, $y=\sin(t)\sin (3t)$, six tangents at $(x,y)=(0,0)$.
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.280086, -1.399988)(1.4,1.0625)
\tiny
\fcAxesStandard{-1.030086}{-1.149988}{1.15}{0.7125}
%Calculator input: plotCurve{}(\cos{}t \sin{}(3 t), \sin{}t \sin{}(3 t), -2 \pi, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-6.28319}{6.28319}{t 3 mul 57.29578 mul sin t 57.29578 mul cos mul t 3 mul 57.29578 mul sin t 57.29578 mul sin mul }
\end{pspicture}
\item $x=\cos t, y=\sin (3t)$, find the two points at which the curve has double tangent and find the slopes of both pairs of tangents.
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.399995, -1.399999)(1.4,1.499999)
\tiny
\fcAxesStandard{-1.149995}{-1.149999}{1.15}{1.149999}

%Calculator input: plotCurve{}(\cos{}t, \sin{}(3 t), -2 \pi, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-6.28319}{6.28319}{t 57.29578 mul cos t 3 mul 57.29578 mul sin }
\end{pspicture}
\item $x=t^3-t^2-t+1$, $y=t^2-t-1 $, find a point where the curve has double tangent and find the slopes of the tangents.

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-0.9, -1.649998)(3.358221,1.5)
\tiny
\fcAxesStandard{-0.65}{-1.399998}{3.108221}{1.15}
%Calculator input: plotCurve{}(t^{3}- t^{2}- t+1, t^{2}- t-1, -1, 2)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{-1}{2}{ 1 t -1 mul add t 2 exp -1 mul add t 3 exp add -1 t -1 mul add t 2 exp add }
\end{pspicture}

\end{enumerate}
\end{multicols}


\end{problem}
\subsection{Curve lengths}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/curve-length-1.tex
Plot the curve. Set up an integral that expresses its length. Find the length of the curve. 
\begin{enumerate}[ref={\fcProblemRef}]
\item $y=\sqrt{x}$, $x\in [1, 2]$.
\item $y=x^2$, $x\in [1, 2]$.
\item 
$\gamma:\left| 
\begin{array}{rcl}
x(t)&=&\frac{1}{t}+\frac{t^3}{3}\\
y(t)&=&2t\\
\end{array}\right., t\in [1,2]\quad . $
\item \label{problemlengthx=sqrt(t)-2t,y=8/3t^(3/4)} $\displaystyle x = \sqrt{t} - 2t$ and $\displaystyle y = \frac{8}{3}t^{\frac{3}{4}}$ from $t = 1$ to $t = 4$.
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/curve-length-1-solutions.tex
\solution{ \ref{problemlengthx=sqrt(t)-2t,y=8/3t^(3/4)}.
The length of the parametric curve is given by
\[
L={\displaystyle \int_{1}^4 \sqrt{\left(\frac{\diff x}{\diff t}\right)^2 + \left( \frac{\diff y}{\diff t} \right)^2}  \diff t}\quad .
\]
We have that 
\[
\begin{array}{rclll}
\displaystyle \frac{\diff x}{\diff t} &=&\displaystyle  \frac{1}{2\sqrt{t}} - 2\\
\displaystyle \frac{\diff y}{\diff t} &=&\displaystyle  2t^{-\frac{1}4}\\
\displaystyle \left(\frac{\diff x}{\diff t}\right)^2 &=&\displaystyle  \frac{1}{4t} - \frac{2}{\sqrt{t}} + 4\\
\displaystyle \left(\frac{\diff y}{\diff t}\right)^2 &=&\displaystyle  4t^{-\frac{1}{2}} = \frac{4}{\sqrt{t}}\\
\displaystyle \left(\frac{\diff x}{\diff t}\right)^2+\left(\frac{\diff y}{\diff t}\right)^2 & =&\displaystyle  \frac{1}{4}t + 2\sqrt{t} + 4 = \left(\frac{1}{2}\sqrt{t} + 2\right)^2\quad .
\end{array}
\]

$\frac{1}{2}\sqrt{t} +2$ is positive and $\sqrt{\left(\frac{ 1}{2} \sqrt{t} +2\right)^2} =\frac{1}{2}\sqrt{t} +2$. So the integral becomes 
\[\displaystyle 
L= \int_1^4 \left(\frac{1}{2}\sqrt{t} +2\right)  \diff t=\left[\sqrt{t} + 2t\right]_{t=1}^{t=4}=(2+8)-(1+2)=7\quad .
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/curve-length-2.tex
Set up an integral that expresses the length of the curve and find the length of the curve.
\begin{enumerate}
\item
$
\left|
\begin{array}{rcl}
x(t)&=&e^t+e^{-t}\\
y(t)&=&5-2t\\
\end{array}\right., t\in [0,3]
$

\psset{xunit=0.3cm, yunit=0.3cm}
\begin{pspicture}(-0.9, -1.388012)(20.415591,5.5)
\tiny
\fcAxesStandard{-0.65}{-1.138012}{20.165591}{5.15}

%Calculator input: plotCurve{}(e^{- t}+e^{t}, -2 t+5, 0, 3)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{0}{3}{ 2.718281828 t exp 2.718281828 t -1 mul exp add 5 t -2 mul add }
\end{pspicture}

\answer{ $ e^3-e^{-3}$}

\item
$
\left|
\begin{array}{rcl}
x(t)&=&\sin t +\cos t\\
y(t)&=&\sin t-\cos t\\
\end{array}\right., t\in [0,\pi]
$

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.81421, -1.814213)(1.814213,1.914213)
\tiny
\fcAxesStandard{-1.56421}{-1.564213}{1.564213}{1.564213}

%Calculator input: plotCurve{}(\sin{}t+\cos{}t, \sin{}t- \cos{}t, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, linestyle=dashed, plotpoints=1000]{0}{6.28319}{t 57.29578 mul cos t 57.29578 mul sin add t 57.29578 mul cos -1 mul t 57.29578 mul sin add }

%Calculator input: plotCurve{}(\sin{}t+\cos{}t, \sin{}t- \cos{}t, 0, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000]{0}{3.14159}{t 57.29578 mul cos t 57.29578 mul sin add t 57.29578 mul cos -1 mul t 57.29578 mul sin add }
\end{pspicture}

\answer{ $\sqrt{2} \pi$}

\end{enumerate}


\end{problem}
\subsection{Area under curve}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/parametric-curves/homework/area-under-curve-1.tex
Give a geometric definition of the cycloid curve using a circle of radius 1. Using that definition, derive equations for the cycloid curve. Find area locked between one ``arch'' of the cycloid curve and the $x$ axis.




\end{problem}
\subsection{Area locked by  curve}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/area-locked-by-curve-1.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problem-Area-swept-by-r=1+sin2theta} The curve given in polar coordinates by $r=1+\sin 2\theta$ is plotted below by computer. Find the area lying outside of this curve and inside of the circle $x^2+y^2=1$.
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-2.016386, -2.016424)(2.016407,2.116335)
\tiny
\fcAxesStandard{-1.766386}{-1.766424}{1.766407}{1.766335}
%Calculator command: drawPolar{}(\sin{}(2 t)+1, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 1 t 2 mul 57.29578 mul sin add t 57.29578 mul cos mul 1 t 2 mul 57.29578 mul sin add t 57.29578 mul sin mul }
\end{pspicture}
\answer{$a=2-\frac{\pi}{4}$}
\item \label{problem-Area-swept-by-r=cos2theta} The curve given in polar coordinates by $r=\cos (2\theta)$ is plotted below by computer. Find the area lying inside the curve and outside of the circle $x^2+y^2=\frac14$.
\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-1.399902, -1.399975)(1.4,1.499975)
\tiny
\fcAxesStandard{-1.149902}{-1.149975}{1.15}{1.149975}
%Calculator command: drawPolar{}(\cos{}(2 t), 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
\end{pspicture}


\answer{$\frac{\pi}{6}+\frac{\sqrt{3}}{4} $}
\item \label{problem-Area-swept-byr=sin2theta_outsider=1/2} Below is a computer generated plot of the curve $r=\sin(2\theta)$. Find the area locked inside one petal of the curve and outside of the circle $\displaystyle x^2+y^2=\frac{1}{4}$.

\psset{unit =1.5cm, linewidth=1\pslinewidth}
\begin{pspicture}(1,2)
\psaxes[labels=none, ticks=none, arrows=->](0,0)(-1.5,-1.5)(1.5,1.5)
\pscustom*[linecolor=cyan]{
\parametricplot[linecolor=red, plotpoints=300]{15}{75}{t cos t 2 mul sin mul t sin t 2 mul sin mul}
\parametricplot[linecolor=red]{75}{15}{t cos 0.5 mul  t sin 0.5 mul}
}
\parametricplot[linecolor=red, plotpoints=300]{0}{360}{t cos t 2 mul sin mul t sin t 2 mul sin mul}
\parametricplot[linecolor=red, plotpoints=300]{0}{360}{t cos 0.5 mul  t sin 0.5 mul}
\end{pspicture}

%\item The curve given in polar coordinates by $r=1+\cos (3t)$ is plotted below. Find the area \textbf{outside} of the curve and \textbf{inside} the circle $x^2+y^2=\frac14$.

%\begin{pspicture}(-1.611991, -2.182513)(2.4,2.282513) \tiny \fcAxesStandard{-1.361991}{-1.932513}{2.15}{1.932513}
%Calculator command: drawPolar{}(\cos{}(3 t)+1, 0, 2 \pi)
%\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 1 t 3 mul 57.29578 mul cos add t 57.29578 mul cos mul 1 t 3 mul 57.29578 mul cos add t 57.29578 mul sin mul }
%\end{pspicture}

\end{enumerate}



\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/area-locked-by-curve-1-solutions.tex
\solution{\ref{problem-Area-swept-by-r=1+sin2theta}. A computer generated plot of the two curves is included below. The circle $x^2+y^2=1$ has one-to-one polar representation given by $r=1, \theta\in [0,2\pi)$. Except the origin, which is traversed four times by the curve $r=1+\sin (2\theta)$, the second curve is in a one-to-one correspondence with points in the $r,\theta$-plane given by the equation $r=1+\sin (2\theta), \theta\in [0,2\pi)$. Since the two curves do not meet in the origin, we may conclude that the two curves may intersect only when their values for $r$ and $\theta$ coincide. Therefore we have an intersection when
\[\begin{array}{rcll|l}
1+\sin (2\theta)&=&1\\
\sin (2\theta)&=&0\\
\theta &=& 0,\frac{\pi}{2}, \pi, \frac{3\pi}{2}&&\text{because } \theta\in [0,2\pi) \\
\end{array}
\]
Therefore the two curves meet in the points $(0,1)(-1,0)$ and $(0,-1),(1,0)$.

Denote the investigated region by $A$. From the computer-generated plot, it is clear that when a point has polar coordinates $\theta\in [\frac{\pi}{2}, \pi] \cup[\frac{3\pi}{2}, 2\pi]$, $r\in [1+\sin(2\theta),1]$ it lies in $A$. Furthermore, the points $r,\theta$ lying in the above intervals are in one-to-one correspondence with the points in $A$.

Suppose we have a curve $r=f(\theta), \theta\in [a,b]$ for which no two points lie on the same ray from the origin. Recall from theory that the area swept by that curve is given by
\[
\int\limits_{a}^b\frac{1}{2} f^2(\theta)\diff \theta\quad .
\]

Therefore the area $a$ of $A$ is computed via the integrals
\[
\begin{array}{rcll|l}
a&=&\displaystyle \int\limits_{\frac{\pi}{2}}^{\pi} \frac{1}{2} \left( {\underbrace{ 1}_{\text{outer curve}}}^2- \left(\underbrace{1+\sin(2\theta)}_{\text{inner curve}}\right)^2 \right)\diff \theta + \int \limits_{ \frac{3\pi}{2}}^{ 2\pi} \frac{1}{2} \left(1^2- (1+\sin(2\theta) )^2 \right) \diff \theta &&\text{use the symmetry of } A\\
&=&\displaystyle  \int\limits_{\frac{\pi}{2}}^{\pi} \left(1^2-(1+\sin(2\theta))^2\right)\diff \theta= \int\limits_{\frac{\pi}{2}}^{\pi} \left( - 2\sin(2\theta) - \sin^2(2\theta)\right) \diff \theta  &&\text{use } \sin^2 z=\frac{1-\cos (2z)}{2} \\
&=&\displaystyle  \int\limits_{\frac{\pi}{2}}^{\pi}  \left( -2\sin(2\theta) -\frac{1}{2} +\frac{1}{2}\cos (4\theta)\right)\diff \theta = \left[\cos (2\theta) -\frac{1}{2}\theta -\frac{1}{8}\sin (4\theta) \right]_{\frac{\pi}{2}}^{\pi} \\
&=&2-\frac{\pi}{4}\quad .
\end{array}
\]

\psset{xunit=1cm, yunit=1cm}
\begin{pspicture}(-2.016386, -2.016424)(2.016407,2.116335)
\tiny
\fcAxesStandard{-1.766386}{-1.766424}{1.766407}{1.766335}
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(1, 1/2 \pi, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{1.5708}{3.14159}{ 1 t 57.29578 mul cos mul 1 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\sin{}(2 t)+1, 1/2 \pi, \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{1.5708}{3.14159}{ 1 t 2 mul 57.29578 mul sin add t 57.29578 mul cos mul 1 t 2 mul 57.29578 mul sin add t 57.29578 mul sin mul }
} %pscustom
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(\sin{}(2 t)+1, -1/2 \pi, 0)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{-1.5708}{0}{ 1 t 2 mul 57.29578 mul sin add t 57.29578 mul cos mul 1 t 2 mul 57.29578 mul sin add t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(1, -1/2 \pi, 0)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{-1.5708}{0}{ 1 t 57.29578 mul cos mul 1 t 57.29578 mul sin mul }
} %pscustom

%Calculator command: drawPolar{}(1, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 1 t 57.29578 mul cos mul 1 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\sin{}(2 t)+1, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 1 t 2 mul 57.29578 mul sin add t 57.29578 mul cos mul 1 t 2 mul 57.29578 mul sin add t 57.29578 mul sin mul }
\end{pspicture}
}
\solution{\ref{problem-Area-swept-by-r=cos2theta} A computer generated plot of the figure is included below. The circle $x^2+y^2=\frac{1}{4} $ is centered at $0$ and of radius $\frac{1}{2}$ and therefore can be parametrized in polar coordinates via $r=\frac{1}{2}, \theta\in [0, 2\pi]$.

Points with polar coordinates $(r_1, \theta_1) $ and $(r_2,\theta_2)$ coincide if one of the three holds:
\begin{itemize}
\item[$\bullet$] $r_1=r_2\neq 0$ and $\theta_1=\theta_2+2k\pi, k\in \mathbb Z $,
\item[$\bullet$] $r_1=-r_2\neq 0$ and $\theta_1=\theta_2+(2k+1)\pi, k\in \mathbb Z$,
\item[$\bullet$] $r_1=r_2=0 $ and $\theta$ is arbitrary.
\end{itemize}
To find the intersection points of the two curves we have to explore each of the cases above. The third case is not possible as the circle does not pass through the origin. Suppose we are in the first case. Then the value of $r$ (as a function of $\theta$)  is equal for the two curves. Thus the two curves intersect if
\[
\begin{array}{rcll|l}
r=\cos (2\theta)&=&\frac12\\
2\theta&=& \pm\frac{\pi}{3}+2k\pi&&\text{where }k\in \mathbb Z\\
\theta &=& \pm\frac{\pi}{6}+k\pi &&\text{where }k\in \mathbb Z\\
\theta &=& \frac{\pi}{6}, \frac{\pi}{6}+\pi, -\frac{\pi }{6}+\pi, -\frac{\pi }{6}+2\pi &&\text{all other values discarded as }\theta\in [0,2\pi]\\
\theta&=&\frac{\pi}{6}, \frac{7\pi}{6}, \frac{5\pi}{6}, \frac{11\pi}{6}
\end{array}
\]
This gives us only four intersection points, and the computer-generated plot shows eight. Therefore the second case must yield new intersection points: the two curves intersect also when
\[
\begin{array}{rcll|l}
r=\cos (2\theta)&=&-\frac{1}{2}\\
2\theta &=& \pm \frac{2\pi}{3} +2k\pi &&\text{where } k\in \mathbb Z\\
\theta &=& \pm \frac{\pi}{3} +k\pi &&\text{where } k\in \mathbb Z\\
\theta&=& \frac{\pi }{3}, \frac{\pi}{3}+\pi, \frac{-\pi}{3} +\pi, \frac{-\pi}{3}+2\pi &&\text{all other values are discarded as }\theta \in [0,2\pi]\\
\theta&=&\frac{\pi}{3}, \frac{4\pi}3, \frac{2\pi}{3}, \frac{5\pi}{3}  \quad .
\end{array}
\]
From the computer-generated plot below, we can see that the area we are looking for is 4 times the area locked between the two curves for $\theta\in \left[\frac{-\pi}{6}, \frac{\pi}{6}\right] $. Therefore the area we are looking for is given by
\[
4\int\limits_{-\frac{\pi}{6}}^{\frac{\pi}{6}} \frac{1}{2}\left(\cos^2(2\theta)-\left(\frac{1}{2}\right)^2 \right)\diff \theta\quad .
\]
We leave the above integral to the reader.
\psset{xunit=2cm, yunit=2cm}
\begin{pspicture}(-1.399902, -1.399975)(1.4,1.499975)
\tiny
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(1/2, 1/6 \pi, -1/6 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0.523599}{-0.523599}{ 0.5 t 57.29578 mul cos mul 0.5 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\cos{}(2 t), -1/6 \pi, 1/6 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{-0.523599}{0.523599}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
}
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(1/2, 5/3 \pi, 4/3 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{5.23599}{4.18879}{ 0.5 t 57.29578 mul cos mul 0.5 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\cos{}(2 t), 1/3 \pi, 2/3 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{1.0472}{2.0944}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
}
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(1/2, 7/6 \pi, 5/6 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{3.66519}{2.61799}{ 0.5 t 57.29578 mul cos mul 0.5 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\cos{}(2 t), 5/6 \pi, 7/6 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{2.61799}{3.66519}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
}
\pscustom*[linecolor=\fcColorAreaUnderGraph]{
%Calculator command: drawPolar{}(1/2, 2/3 \pi, 1/3 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{2.0944}{1.0472}{ 0.5 t 57.29578 mul cos mul 0.5 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\cos{}(2 t), 4/3 \pi, 5/3 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{4.18879}{5.23599}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
}
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 0.5 t 57.29578 mul cos mul 0.5 t 57.29578 mul sin mul }
%Calculator command: drawPolar{}(\cos{}(2 t), 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{t 2 mul 57.29578 mul cos t 57.29578 mul cos mul t 2 mul 57.29578 mul cos t 57.29578 mul sin mul }
\psaxes[ticks=none, labels=none, arrows = <->](0,0)(-1.149902,-1.149975)(1.15,1.149975)
\fcLabels{1.15}{1.149975}
\end{pspicture}
%Calculator command: drawPolar{}(1/2, 0, 2 \pi)
}

\noindent \solution{\ref{problem-Area-swept-byr=sin2theta_outsider=1/2}. The circle $x^2+y^2=\frac{1}{4} $ is centered at $0$ and of radius $\frac{1}{2}$ and therefore can be parametrized in polar coordinates via $r=\frac{1}{2}, \theta\in [0, 2\pi)$.

Points with polar coordinates $(r_1, \theta_1) $ and $(r_2,\theta_2)$ coincide if one of the three holds:
\begin{itemize}
\item $r_1=r_2\neq 0$ and $\theta_1=\theta_2+2k\pi, k\in \mathbb Z $,
\item $r_1=-r_2\neq 0$ and $\theta_1=\theta_2+(2k+1)\pi, k\in \mathbb Z$,
\item $r_1=r_2=0 $ and $\theta$ is arbitrary.
\end{itemize}


To find the intersection points of the two curves we have to explore each of the cases above. The third case is not possible as the circle does not pass through the origin. Suppose we are in the first case. Then the value of $r$ (as a function of $\theta$)  is equal for the two curves. Thus the two curves intersect if
\[
\begin{array}{rcll|l}
r=\sin (2\theta)&=&\frac12\\
2\theta&=& \frac{\pi}{6}+2k\pi\text{ or } \frac{5\pi}{6}+2k\pi&&\text{where }k\in \mathbb Z\\
\theta &=& \frac{\pi}{12}+k\pi \text{ or } \frac{5\pi}{12} &&\text{where }k\in \mathbb Z\\
\theta &=& \frac{\pi}{12}, \frac{13\pi}{12}, \frac{5\pi}{12}, \frac{17\pi}{12}&&
\begin{array}{l}
\text{other values discarded as}\\
\theta\in [0,2\pi]
\end{array}
\end{array}
\]
This gives us only four intersection points, and the computer-generated plot shows eight. Therefore the second case must yield 4 new intersection points. However, from the figure we see there are only two intersection points that participate in the boundary of our area, and both of those were found above. Therefore we shall not find the remaining 4 intersections.

Both the areas locked by the petal and the area locked by the section of the circle are found by the formula for the area locked by a polar curve. Subtracting the two we get that the area we are looking for is: 
\[
\begin{array}{rcl}
\text{Area}&=&\displaystyle \int\limits_{\theta=-\frac{\pi}{ 12}}^{\theta= \frac{5\pi}{12}} \frac{1}{2}\left( \sin^2(2\theta)- \left( \frac{1}{2} \right)^2 \right)\diff \theta\quad .\\
&=&\displaystyle \frac{1}{2} \int\limits_{\theta=-\frac{\pi}{ 12}}^{\theta= \frac{5\pi}{12}} \left(\frac{1-\cos(4\theta)}{2}-\frac{1}{4} \right)\diff \theta\\
&=&\displaystyle\frac{1}{2}\left[\frac{1}{4}\theta -\frac{\sin(4\theta)}{8} \right]_{\theta=-\frac{\pi}{ 12}}^{\theta= \frac{5\pi}{12}}\\
&=&\frac{1}{24} \pi+\frac{\sqrt{3}}{16} \quad .
\end{array}
\]
}



\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/polar-curves/homework/area-locked-by-curve-2.tex
The answer key has not been proofread, use with caution.
\begin{enumerate}
\item
Sketch the graph of the curve given in polar coordinates by $r=3\sin (2\theta)$ and find the area of one petal.

\answer{$\frac{9\pi}{8}$, curve sketch: \psset{xunit=0.1cm, yunit=0.1cm}
\begin{pspicture}(-2.709395, -2.709285)(2.709395,2.809368)
\tiny
\fcAxesStandard{-2.459395}{-2.459285}{2.459395}{2.459368}
%Calculator command: drawPolar{}(3 \sin{}(2 t), 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{t 2 mul 57.29578 mul sin 3 mul t 57.29578 mul cos mul t 2 mul 57.29578 mul sin 3 mul t 57.29578 mul sin mul }
\end{pspicture} }

\item Sketch the graph of the curve given in polar coordinates by $r=4+3\sin \theta$ and find the area enclosed by the curve.

\answer{$\frac{41\pi}{2}$ , curve sketch: \psset{xunit=0.1cm, yunit=0.1cm}
\begin{pspicture}(-5.177597, -1.733324)(5.177712,7.499951)
\tiny
\fcAxesStandard{-4.927597}{-2.5}{4.927712}{7.149951}
%Calculator command: drawPolar{}(3 \sin{}t+4, 0, 2 \pi)
\parametricplot[linecolor=\fcColorGraph, plotpoints=1000, algebraic=false]{0}{6.28319}{ 4 t 57.29578 mul sin 3 mul add t 57.29578 mul cos mul 4 t 57.29578 mul sin 3 mul add t 57.29578 mul sin mul }
\end{pspicture} }
\end{enumerate}


\end{problem}
\section{A Bit of Differential Equations}
\subsection{Separable Differential equations}
\subsubsection{The Mixing Problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/mixing-problem-1.tex
\label{problemDFQseparable-mixing-problem-1}
A tank contains $30$ kg of salt dissolved in $10000$ liters of water and salt solution. Brine that contains $0.05$ kg of salt per liter enters the tank at a rate of $10$ liters per minute. The solution is kept thoroughly mixed and drains from the tank at the same rate ($10$ liters per minute). Determine how much salt remains in the tank after $45$ minutes.

\answer{$\displaystyle 500-470 e^{-\frac{9}{200}} \approx 50.68 kg$}

\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/mixing-problem-1-solution.tex
\solution{\ref{problemDFQseparable-mixing-problem-1}. 
Let 
\[
y(t)=\text{salt in the tank after } t \text{ minutes (in kg)}\quad .
\] 
We are given $y(0)= 30$kg, the initial amount of salt. We are looking to find $y(45)$, the amount of salt after $45$ minutes. We have that 
\[
\frac{\diff y}{\diff t}= \text{(rate in)} - \text{(rate~out)} \quad .
\]
The rate of salt entering the tank is constant: 
\[
\text{(rate in)}=0.05 kg/L \cdot 10 L/min= 0.5 kg/min\quad .
\] 
As the solution is thoroughly mixed, at any time the concentration of salt in the tank is 
\[
\displaystyle \frac{y}{ 10000} kg/L.
\] 
Therefore the rate of salt going out of the tank is 
\[
\text{(rate out)}=\frac{y}{10000} kg/L * 10 L/min = \frac{y}{1000} kg/min\quad .
\] 
Therefore the differential equation for the amount of salt in the tank is
\[
\frac{\diff y}{\diff t}= \underbrace{ 0.5}_{\text{(rate  in)}}- \underbrace{ \frac{y}{1000} }_{\text{(rate out)}}\quad .
\]
There are two variants for remainder of the solution. Variant I uses indefinite integration and is slightly informal, but is easier to learn and remember. Variant II is rigorous, but more challenging understand and write up. Both solutions are acceptable for full credit in a Calculus exam. Variant I is recommended when taking exams and Variant II is recommended when writing scientific texts.

\textbf{Variant I} 
\[
{\renewcommand{\arraystretch}{1.5}
\begin{array}{rcll|l}
\displaystyle\frac{\diff y}{\diff t}&=&\displaystyle 0.5-  \frac{y}{1000} \quad .\\
\displaystyle\frac{\diff y}{\diff t}&=&\displaystyle   \frac{500-y}{1000} \quad .\\
\displaystyle \frac{1000}{500- y} \frac{\diff y}{\diff t}&=& \displaystyle 1 &&\text{Use indefinite integration}\\
\displaystyle \int \frac{1000}{500- y} \underbrace{ \frac{\diff y}{\diff t} \diff t}_{\diff y} &=& \displaystyle \int \diff t \\
\displaystyle \int \frac{1000}{500-y}\diff y &=& t+C\\
\displaystyle -1000 \int  \frac{1}{500-y}\diff(500-y)&=& t+C \\
\displaystyle  -1000 \ln |500-y| &=& t+C &&
\begin{array}{l}
\text{The constant from} \\\text{the second integral} \\\text{is accounted by the constant }C
\end{array}
\\
\displaystyle\ln |500-y|&=&\displaystyle -\frac{t+C}{1000} \\
\displaystyle|500-y| &=&\displaystyle e^{-\frac{t+C}{1000}}&& 
\begin{array}{l}
\text{Since }500-y(0)= 500-30=470 >0\\
\text{we can drop the absolute values}
\end{array}\\
\displaystyle 500-y &=&\displaystyle e^{-\frac{t+C}{1000}}\\
\displaystyle y&=& \displaystyle 500-e^{-\frac{t+C}{1000}} &&\text{Set } D= e^{-\frac{C}{1000}}\\
\displaystyle y&=&\displaystyle  500-De^{-\frac{t}{1000}}
\quad .
\end{array}
}
\]
To find the constant $D$, we observe that 
\[
\begin{array}{rcl}
30&=&y(0)= 500 - De^{-\frac{0}{1000}}= 500-D\\
D&=&470\quad .
\end{array}
\]
Therefore 
\[
\displaystyle y(t)= 500- 470 e^{-\frac{t}{1000}}\quad ,
\]
and the final answer is
\[
\displaystyle y(45)=500-470e^{-\frac{45}{1000}}\approx 50.68 
\]
with measurement unit $kg$.

\textbf{Variant II.} 
To find $y(45)$, we integrate from $t=0$ to $t=45$:
\[
{\renewcommand{\arraystretch}{1.5}
\begin{array}{rcll|l}
\displaystyle \int\limits_{t=0}^{45} \frac{1000}{500- y} \underbrace{ \frac{\diff y}{\diff t} \diff t}_{\diff (y(t))} &=& \displaystyle \int\limits_{t=0}^{45} \diff t \\
\displaystyle \int\limits_{t=0}^{t=45} \frac{1000}{500-y(t)}\diff (y(t))&=& 45&&\text{set }z=y(t) \\
\displaystyle -1000 \int \limits_{z=y(0)=30}^{z=y(45)} \frac{1}{500-z}\diff(500-z)&=& 45 \\
\displaystyle \left. -1000 \ln |500-y| \right]_{y(0)=30}^{y(45)}&=& 45 \\
\displaystyle -1000 \left( \ln |500-y(45)|\right. \\
\left. -\ln |500- 30|  \right) &=& 45 \\
\displaystyle \ln \left| \frac{470}{500-y(45)} \right|  &=& \displaystyle \frac{45}{1000}
\\
\displaystyle \ln \left( \frac{470}{500-y(45)} \right)  &=& \displaystyle \frac{45}{1000} &&\text{see below}
\\
\displaystyle \frac{470}{500-y(45)}&=&\displaystyle e^{\frac{45}{1000}}\\
\displaystyle 500-y(45)&=&\displaystyle  470e^{-\frac{9}{200}}\\
\displaystyle y(45)&=&\displaystyle 500-470e^{-\frac{9}{200}}\\
&\approx& 500-470\cdot 0.955997 \\
&\approx& 50.681184 \quad ,
\end{array}
}
\]
where we have used that $\displaystyle \frac{470}{500-y(t)}>0 $. The fact that $\displaystyle \frac{470}{500-y(t)}>0 $ can be seen as follows. As $500-y(0)=470>0$ and $y(t)$ is continuous, in order to have $500-y(t)<0$ there must exist some $x_1$ for which $y(x_1)=500$. However this is impossible since $\displaystyle x=\ln \left|\frac{470}{500-y(x)}\right|  $. 

As the unit of measurement is $kg$, the final answer to the problem is $\approx 50.68 kg$ salt.
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/mixing-problem-2.tex
Mixing problem. A tank contains $1000$ kg of salt dissolved in 10000 liters of water. Brine that contains $0.05$ kg of salt per liter of water enters the tank at a rate of $30$ liters per minute. The solution is kept thoroughly mixed and drains from the tank at the same rate ($30$ liters per minute). 


\begin{enumerate}
\item Determine how much salt remains in the tank after an hour. The answer key has not been proofread, use with caution.

\answer{$\displaystyle 500+ 500 e^{-0.18}\approx 917.64kg$}
\item Determine how much time will be needed in order to have the concentration of salt in the tank reach $0.0501$kg/liter. The answer key has not been proofread, use with caution.

\answer{$\frac{1000}{3}\ln 500\approx 2071.54min\approx 34.53 hours$}
\end{enumerate}


\end{problem}

\subsubsection{General Separable Problems}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-1.tex
\begin{equation}\label{eqDFQseparable-yprime=ysquared-1}
\frac{\diff y}{\diff x}= y^2-1\quad .
\end{equation}
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemDFQseparable-yprime=ysquared-1-part1} Find all solutions of the differential equation above.
\item \label{problemDFQseparable-yprime=ysquared-1-part2} Find a solution for which $y(0)=-\frac{3}{5}$.
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-1-solution.tex
\solution{\noindent \ref{problemDFQseparable-yprime=ysquared-1-part1}.
There are two variants for solving this problem. The first variant uses indefinite integration and is slightly informal, but easier to apply and remember. The second variant is more rigorous but more difficult to write up. Both solutions are acceptable for full credit in a Calculus exam. Variant I is recommended when taking exams and Variant II is recommended when writing scientific texts.

\textbf{Variant I}

\renewcommand{\arraystretch}{2}
\[
\begin{array}{rcll|l}
\displaystyle \frac{ \diff y}{ \diff x}&=&y^2-1 && \text{Suppose } y^2-1\neq 0 \\
\displaystyle \frac{\frac{ \diff y}{ \diff x}}{y^2-1}&=&1 \\
\displaystyle\int\frac{1}{ y^2- 1} \underbrace{ \frac{\diff y}{\diff x}\diff x}_{=\diff y } &=& \displaystyle\int \limits \diff x \\
\displaystyle\int \frac{\diff y}{ y^2-1}& =& \displaystyle x +C \\
\displaystyle\int \left(\frac{\frac{1}{2} }{y-1}- \frac{\frac{1 }{2}}{ y+1}\right)\diff y&=& x +C \\
\displaystyle \frac{1}2 \ln \left|\frac{y-1}{y+1}\right| &=& x+C\\
\displaystyle \ln \left|\frac{y-1}{y+1}\right|&=& 2t + 2C\\
\displaystyle\left|\frac{y-1}{y+1}\right|&=& e^{ 2x +2C} \\
\displaystyle\frac{y-1}{y+1}&=& \pm e^{ 2x +2C} \\
\displaystyle y-1&=&\displaystyle \pm e^{2x+2C} (y+1)\\
\displaystyle y(1\mp e^{2x+2C})&=&\displaystyle 1\pm e^{2x+2C} \\
\displaystyle y&=&\displaystyle \frac{1\pm e^{2x+2C}}{1\mp e^{2x+2C}}  \\
\displaystyle y&=&\displaystyle \frac{1\pm e^{2C} e^{2x}}{1\mp e^{2C}e^{2x}}&&\text{Set }D=\pm e^{2C}\\
\displaystyle y&=&\displaystyle  \frac{1+D e^{2x}}{1- De^{2x}}\quad .
\end{array}
\]
The above solution works on condition that $y^2-1\neq 0$. So the only case not covered is that of $y^2-1=0$, which yields the two solutions $y=\pm 1$.

Our final answer is
\[
y(x)= \frac{1+De^{2x}}{1-De^{2x}} \quad \text{ or }\quad y(x)=-1,
\]
where $D$ is an arbitrary real number. Notice that in the above answer, by allowing $D=0$, we have covered the case $y(x)=1 $. Finally, we note that if we let $D\to \infty$, the solution $y(x) = \frac{1+De^{2x }}{ 1- De^{2x}}  $ tends to the solution $y(x)=-1$ (here we fix a value of $x$ before we let $D\to \infty$).


\textbf{Variant II}

\noindent Case 1. Suppose there exists a number $x_0$ such that $(y(x_0) )^2 - 1\neq 0$. Since $y$ is a differentiable function of $x$, it is also continuous. Therefore for some $t$ sufficiently close to $x_0$, all numbers $x$ in the interval between $t$ and $x_0$ satisfy $ y(x)^2-1\neq 0$.
\[
\begin{array}{rcll|l}
\displaystyle \frac{\frac{ \diff y}{ \diff x}}{y^2-1}&=&1 \\
\displaystyle\int\limits_{x=x_0}^{x=t} \frac{1}{ y^2- 1} \underbrace{ \frac{\diff y}{\diff x}\diff x}_{=\diff (y(x)) }&=&\displaystyle\int\limits_{x=x_0}^{x=t}\diff x &&\text{can integrate as }  y(x)^2-1\neq 0\\
\displaystyle\int\limits_{t=x_0 }^{x=t} \frac{\diff (y(x))}{ (y(x))^2-1}& =& \displaystyle\left.x \right|_{ x=x_0}^{x=t} &&\text{set } z=y(x)\\
\displaystyle\int\limits_{z=y(x_0) }^{z=y(t)} \frac{\diff z}{ z^2-1}& =& \displaystyle t-x_0 \\
\displaystyle\int\limits_{z=y(x_0)}^{z=y(t)} \left(\frac{\frac12 }{z-1}- \frac{\frac12}{z+1}\right)\diff z&=& t-x_0
\\
\displaystyle\left .\frac{1}2 \ln \left|\frac{z-1}{z+1}\right|\right]_{z=y(x_0)}^{z=y(t)}&=& t-x_0 && \text{Set } C=2x_0-  \ln \left|\frac{y(x_0)-1}{ y(x_0)+ 1} \right|\\
\displaystyle \ln \left|\frac{y(t)-1}{y(t)+1}\right|&=& 2t - C&&\text{relabel dummy variable } t \text { to } x \\
\displaystyle
\ln \left|\frac{y(x)-1}{y(x)+1}\right|&=& 2x - C
\end{array}
\]
Set
\[
D=e^{-C}\quad .
\]
By the assumption of our case, $ (y(x_0))^2-1\neq 0$, so there are two remaining cases: $ (y(x_0))^2-1>0$ and $ (y(x_0))^2-1<0$.

\noindent Case 1.1. Suppose $\displaystyle \frac{y(x_0)-1}{ y(x_0)+1}>0$. As the function $y(x)$ is differentiable, it is also continuous. Therefore $\displaystyle \frac{y(x)-1}{y(x)+1}>0$ for all $x$ near $x_0$. Then we can remove the absolute values in the equality above to get that for all $x$ close to $x_0$ we have that
\[
\begin{array}{rcll|l}
\displaystyle \ln \left(\frac{y(x)-1}{y(x)+1}\right)&=& 2x - C&&\text{exponentiate, recall }D=e^{-C}\\
\displaystyle \frac{y(x)-1}{y(x)+1}&=& D e^{2x}\\
\displaystyle y(x)-1&=&\displaystyle  De^{2x}(y(x)+1)\\
\displaystyle y(x)\left(1- De^{2x}\right)&=&\displaystyle  De^{2x}+1\\
\displaystyle y(x)&=&\displaystyle  \frac{ 1+De^{2x}}{1- De^{2x}}\quad .\\
\end{array}
\]
The solution $y(x)$ given above satisfies $\displaystyle \frac{y(x)-1}{y(x)+1}= De^{2x}$ for all $x$. As $D>0$, this implies that $\displaystyle \frac{y(x)-1}{ y(x)+1}>0$. Therefore the considerations above are valid for all $x$, rather than only for those $x$ near $x_0$. Therefore our first case yields the solution
\[
y(x)=\frac{ 1+De^{2x}}{1- De^{2x}}\quad .
\]

\noindent Case 1.2. Suppose  $\displaystyle \frac{y(x_0) -1}{y(x_0) +1} <0$. Then for all $x$ near $x_0$ we get $\displaystyle \ln \left| \frac{y(x) -1}{y(x) +1}\right|= \ln \left( \frac{ 1- y(x) }{ y( x) +1}\right)$ and, similarly to Case 1, we get
\[
\begin{array}{rcl}
\displaystyle \frac{1-y(x)}{y(x)+1}&=& D e^{2x}\\
1-y(x)&=& De^{2x}(y(x)+1)\\
y(x)\left(1+ De^{2x}\right)&=& 1-De^{2x}\\
y(x)&=&\displaystyle \frac{1- De^{2x}}{1+ De^{2x}}\quad .
\end{array}
\]
Since $D$ is a positive constant, we conclude in a fashion analogous to Case 1 that $y(x)<0$ for all $ x$.

Case 2.  Suppose $\displaystyle  (y(x_0))^2-1=0 $.  Then $y(x_0)=\pm 1$. Clearly the constant functions $y(x)= \pm 1$ are two solutions: if we can plug back $y=\pm 1$ in the original equation we get that $\frac{\diff y}{\diff x}= 0$ and $y$ is a constant function of $x$. From the preceding two cases we know that if $\frac{y(x) -1}{y(x) +1}$ is defined and not equal to zero for some value of $x$, then $\frac{y(x)-1}{y(x)+1}$ is defined and not equal to zero for all values of $x$. Therefore the present case yields only two solutions, the constant functions $y(x)=\pm 1$.

Our final answer is
\[
y(x)= \frac{1+De^{2x}}{1-De^{2x}} \quad \text{ or }\quad y(x)=-1,
\]
where $D$ is an arbitrary real number. Notice that in the above answer, we have combined Cases 1.1, 1.2 and the case $y(x)=1 $: by allowing $D$ to be negative we included Case 1.2 and by allowing $D $ to be zero we included the case $y(x)=1$. Finally, we note that if we let $D\to \infty$, the solution $y(x) = \frac{1+De^{2x }}{ 1- De^{2x}}  $ tends to the solution $y(x)=-1$ (for all values of $x$).


\textbf{Solution plots.}

We may plot solutions for a few values of $D$ as follows. We overlay the solutions on top of the direction field of the differential equation. The picture tells us a lot about the properties of the solutions of the differential equations.
\optionalDisplay{
\begin{pspicture}(-6,-6)(6,6)
\newcommand{\Dconst}{1}
\psplot[linecolor=green]{-4}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul sub 1 \Dconst\space 2.718281828 2 x mul exp mul add div}
\renewcommand{\Dconst}{0.25}
\psplot[linecolor=green]{-4}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul sub 1 \Dconst\space 2.718281828 2 x mul exp mul add div}
\renewcommand{\Dconst}{4}
\psplot[linecolor=green]{-4}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul sub 1 \Dconst\space 2.718281828 2 x mul exp mul add div}
\rput[l](5,2 ){$\frac{1- \frac{1}4 e^{2x}}{1+\frac 14 e^{2x}}$ }
\rput[l](5,0.5 ){$\frac{1- e^{2x}}{1+e^{2x}}$ }
\rput[l](5,-2 ){$\frac{1- 4e^{2x}}{1+4e^{2x}}$ }
\psline[arrows=->, linestyle=dotted](5,2)(0,0.6)
\psline[arrows=->, linestyle=dotted](5,0.5)(0,0)
\psline[arrows=->, linestyle=dotted](5,-2)(0,-0.6)

\renewcommand{\Dconst}{1}
\psplot[linecolor=green]{-4}{-0.17}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}
\psplot[linecolor=green]{0.17}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}
\renewcommand{\Dconst}{4}

\psplot[linecolor=green]{-4}{-0.863147181}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}
\psplot[linecolor=green]{-0.523147181}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}

\renewcommand{\Dconst}{0.25}
\psplot[linecolor=green]{-4}{0.523147181}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}
\psplot[linecolor=green]{0.863147181}{4}{1 \Dconst\space 2.718281828 2 x mul exp mul add 1 \Dconst\space 2.718281828 2 x mul exp mul sub  div}
\rput[r](-5,0.5 ){$\frac{1+\frac 14 e^{2x}}{1- \frac{1}4 e^{2x}}$ }
\rput[r](-5,2 ){$\frac{1+e^{2x}}{1- e^{2x}}$ }
\rput[r](-5,-2 ){$\frac{1+4e^{2x}}{1- 4e^{2x}}$ }
\psline[arrows=->, linestyle=dotted](-5,0.5)(0,1.6667)
\psline[arrows=->, linestyle=dotted](-5,0.5)(1,-3.360539267)
\psline[arrows=->, linestyle=dotted](-5,2)(-0.2,5.066489563)
\psline[arrows=->, linestyle=dotted](-5,2)(0.2,-5.066489563)
\psline[arrows=->, linestyle=dotted](-5,-2)(0,-1.6667)
\psline[arrows=->, linestyle=dotted](-5,-2)(-1,3.360539267)
\psaxes[arrows=<->](0,0)(-4.5,-4.5)(4.5,4.5)

\rput (5,5){The direction field  $\frac{\diff y}{\diff x}=y^2-1$}

\fcDirectionFieldDefault{y y mul 1 sub}{-4}{-4}{0.5}{17}
\end{pspicture}
} %optionalDisplay

\noindent \ref{problemDFQseparable-yprime=ysquared-1-part2}.
From the computer generated picture above, we may visually estimate that $y(x)=\frac{1-4 e^{2x} }{1+4 e^{2x} }$ intersects the $x$-axis at $\left(0, -\frac {3}{ 5}\right)$. Furthermore, we may check directly that for
\[
y(x)=\frac{1-4 e^{2x} }{1+4 e^{2x} }
\]
we have $y(0)= \frac{1-4}{1+5}=  -\frac{3}{5}$ and that is a solution to our problem (this however does not prove the solution is unique).

Alternatively, let us give an algebraic solution. As we are given that $y(0)=-\frac35$ and so
\[
\begin{array}{rcl}
\displaystyle -\frac{3}{5}&=&\displaystyle y(0)= \frac{1-De^{2\cdot 0}}{1+ De^{2\cdot 0}}= \frac{1-D}{1+D}\\
\displaystyle -\frac{3}{5} (1+D)&=&1-D\\
\displaystyle \frac{2}{5} D&=&\displaystyle \frac{8}{5}\\
D&=&4\quad ,
\end{array}
\]
which is our final answer.
}



\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-2.tex
\begin{enumerate}
\item Find the general solution to the differential equation
\[
\frac{\diff y}{\diff x}= y^2-4\quad .
\]
Below is a computer-generated plot of the direction field  $\displaystyle \frac{\diff y}{\diff x}=y^2-4$, you may use it to get a feeling for what your answer should look like.

\optionalDisplay{
\begin{pspicture}(-6,-6)(6,6)
\newcommand{\Dconst}{4}
\psplot[linecolor=green]{-4}{4}{1 \Dconst\space 2.718281828 4 x mul exp mul sub 1 \Dconst\space 2.718281828 4 x mul exp mul add div 2 mul}
\psaxes{<->}(0,0)(-5,-5)(5,5)
\rput[l](0.4,5){The direction field  $\frac{\diff y}{\diff  x}=y^2-4$}
\fcDirectionFieldDefault{y y mul 4 sub}{-4}{-4}{0.5}{17}
\end{pspicture}
}
\item {Find a solution of the above equation for which $ y(0)= -\frac{6}{5}$.}
\end{enumerate}


\end{problem}
\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-3.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item 
\label{problemy'=y^2(1+x),y(0)=3}
Solve the initial-value differential equation $\displaystyle y' = y^2(1+x)$, $y(0) = 3$.

\item Solve the initial-value differential equation problem
\[
y'=xe^{-y}
\quad,\quad  \quad \quad y(4)=0.
\]
Below is a computer-generated plot of the corresponding direction field, you may use it to get a feeling for what your answer should look like.

\optionalDisplay{
\begin{pspicture}(-6,-6)(9.5,9.5)
\psaxes{<->}(0,0)(-5,-5)(9,9)
\fcFullDot{4}{0}
\rput[lt](0.4,9){The direction field  $\frac{\diff y}{\diff  x}=y'=xe^{-y} $}
\fcDirectionFieldDefault{2.718281828 y -1 mul exp x mul}{-4}{-4}{0.5}{25}
\psplot[linecolor=\fcColorGraph]{3.745}{8.2}{-7 x 2 exp 0.5 mul add ln}
\end{pspicture}
}

\answer{$y(x)=\ln \left(\frac{x^2}{2}-7\right)$}
\item Solve the initial-value differential equation problem
\[
y'=\frac{\ln x}{x y}
\quad,\quad  \quad \quad y(1)=2.
\]
Below is a computer-generated plot of the corresponding direction field, you may use it to get a feeling for what your answer should look like.

\optionalDisplay{
\begin{pspicture}(-1,-6)(11,6)
\psaxes{<->}(0,0)(-0.5,-5)(10,6)
\fcFullDot{1}{2}
\rput[l](0.4,5){The direction field  $\frac{\diff y}{\diff  x}=y'=\frac{\ln x}{x y} $}
\fcDirectionFieldDefault{x ln y x mul div}{0.01}{-4.01}{0.5}{17}
\psplot[linecolor=\fcColorGraph, plotpoints=600 ]{0.2}{8}{4 x ln 2 exp add 0.5 exp}
\end{pspicture}
}
\answer{$y(x)= \sqrt{(\ln x)^2+4}$}
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-3-solutions.tex
\solution{\ref{problemy'=y^2(1+x),y(0)=3}. 
\[\begin{array}{rcl}
\displaystyle \frac{\diff y}{\diff x}&=&\displaystyle y^2(1+x)\\
\displaystyle \frac{\diff y}{y^2} &=&\displaystyle  (1+x) \diff x\\
\displaystyle \int \frac{\diff y}{y^2} &=&\displaystyle \int (1+x) \diff x\\
\displaystyle -\frac{1}{y} &=&\displaystyle  x + \frac{x^2}{2} + C\\
\displaystyle -\frac{1}{3}& =&\displaystyle  0 + 0 + C\\
\displaystyle y &=&\displaystyle  -\frac{1}{\frac{x^2}{2}+x  - \frac{1}{3}} = -\frac{3}{3x^2+6x-2}\quad .
\end{array}
\]
}


\begin{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-4.tex
\begin{enumerate}[ref={\fcProblemRef}]
\item \label{problemDFQseparabley'=xtany_initial_condition1} Solve the initial-value differential equation problem
\[
y'=x\tan y
\quad,\quad  \quad \quad y(0)=\Arcsin\left(\frac{1}{e}\right)\approx 0.376728.
\]

\answer{$y(x)=\Arcsin\left(e^{\frac{x^2}{2}-1}\right)$}
\item \label{problemDFQseparabley'=xtany_initial_condition2} Solve the same differential equation with initial condition $y(0)= \pi+\Arcsin \left(-\frac{1}{e}\right)\approx 2.764865$.

\answer{$y(x)= \pi+ \Arcsin\left(- e^{ \frac{x^2}{2}- 1}\right)$}


Below is a computer-generated plot of corresponding direction field, you may use it to get a feeling for what your answer should look like.

\optionalDisplay{
\begin{pspicture}(-6,-6)(9.5,9.5)
\psaxes{<->}(0,0)(-5,-5)(9,9)
\rput[lt](0.4,9){The direction field  $\frac{y}{\diff  x}=y'=x\tan y $}
\fcDirectionFieldDefault{y 57.29578 mul sin x mul y 57.29578 mul cos div}{-4}{-4}{0.5}{25}
\psplot[linecolor=\fcColorGraph, plotpoints=500]{-1.41421356}{1.41421356}{2.718281828 -1 x 2 exp 0.5 mul add exp ASIN}
\psplot[linecolor=green, plotpoints=500]{-1.41421356}{1.41421356}{3.141592654 2.718281828 -1 x 2 exp 0.5 mul add exp -1 mul ASIN add}
\end{pspicture}
}
\end{enumerate}


\end{problem}
%input from file: /home/todor/math/freecalc/homework/UMB-All-Problems-By-Course/../../modules/diff-eq-separable/homework/separable-DFQs-4-solutions.tex
\solution{\ref{problemDFQseparabley'=xtany_initial_condition1} and 
\ref{problemDFQseparabley'=xtany_initial_condition2}
\[\begin{array}{rcll|l}
\displaystyle y'&=&\displaystyle x\tan y\\
\displaystyle\frac{y'}{\tan y}&=&\displaystyle x\\
\displaystyle\frac{(\cos y) y'}{\sin y}&=&\displaystyle x &&\text{Integrate from }0\\
\displaystyle \int\limits_{t=0}^{t=x} \frac{\cos(y(t))}{\sin (y(t))} (y' \diff t)&=&\displaystyle  \int\limits_{t=0}^xt \diff t \\
\displaystyle \int\limits_{t=0}^{t=x} \frac{\cos(y(t))}{\sin (y(t))}\diff (y(t))&=&\displaystyle  \frac{x^2}{2} &&\text{Set }z=y(t)\\
\displaystyle \int \limits_{z=y(0)}^{z=y(x)} \frac{\cos z}{\sin z} \diff z&=&\displaystyle  \frac{x^2}{2}\\
\displaystyle \int \limits_{z=y(0)}^{z=y(x)} \frac{\diff (\sin z)}{\sin z} &=&\displaystyle  \frac{x^2}{2}\\
\displaystyle \left[\ln | \sin z|\right]_{y(0)}^{y} & = & \displaystyle  \frac{x^2}{2}\\
\displaystyle \ln |\sin y|- \ln |\sin (y(0))|&=& \displaystyle  \frac{x^2}{2} \\
\displaystyle \ln |\sin y|&=& \displaystyle  \frac{x^2}{2}+\ln |\sin (y(0))| \\
|\sin y|&=&\displaystyle  e^{\frac{x^2}{2}+\ln |\sin (y(0))|}\\ |\sin y|&=&\displaystyle \doublebrace{e^{\frac{x^2}{2}+\ln \left|\sin \left(\Arcsin \left(\frac{1}{e}\right) \right)\right|}}{\text{for problem \ref{problemDFQseparabley'=xtany_initial_condition1}}}{e^{\frac{x^2}{2}+\ln \left|\sin \left(\pi+ \Arcsin \left(\frac{1}{e}\right) \right)\right|} }{\text{for problem \ref{problemDFQseparabley'=xtany_initial_condition2}}} \\
|\sin y|&=&\displaystyle  e^{\frac{x^2}{2}+ \ln \left(\frac{1}{ e}\right)}\\
\displaystyle |\sin y|&=&\displaystyle e^{\frac{x^2}{2}-1} &&\begin{array}{l} y(0)>0 \text{ for both problems}\\
\text{therefore }  \sin y(0) > 0\end{array}\\
\displaystyle \sin y&=&e^{\frac{x^2}{2}-1} \quad.
\end{array}
\]
From the elementary properties of the trigonometric functions, we know that  $\sin y=\sin \alpha$ implies that either
\begin{itemize}
\item $y=\alpha +2k\pi$, where $k$ is an arbitrary integer or
\item $y=(2k+1)\pi-\alpha$, where $k$ is an arbitrary integer.
\end{itemize}
In other words, if we are given $\sin y$, we know $y$ up to a choice of sign and a choice of an integer $k$. For our problem, this means that 

\[
y=\triplebrace{ 2 k \pi+\Arcsin\left( e^{\frac{x^2}{2}-1} \right)}{k -\text{integer}}{\text{or}}{}{(2k+1)\pi- \Arcsin\left( e^{\frac{x^2}{2}-1} \right)}{k-\text{integer}}
\]

For problem \ref{problemDFQseparabley'=xtany_initial_condition1}, 
the only choice for $k$ and sign which fits the initial condition $y(0)= \Arcsin\left(\frac{1}{e}\right)$ is
\[
y=\Arcsin\left(e^{\frac{x^2}{2}-1} \right)\quad ,
\]
which is our final answer. 

For problem \ref{problemDFQseparabley'=xtany_initial_condition2}, 
the only choice for $k$ and sign which fits the initial condition $y(0)=\pi+ \Arcsin\left(-\frac{1}{e}\right)=\pi- \Arcsin \left( \frac{1}{e}\right) $ is
\[
y=\pi- \Arcsin\left(e^{\frac{x^2}{2}-1} \right)\quad, 
\]
which is our final answer.
}

\end{document}

