Skip to main content ☰ Contents Index You! < Prev ^ Up Next > \(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 2.4 Practice Your Arrays
Activity 2.1 .
Stirling’s approximation for large factorials is given by
\begin{equation*}
n! \approx \sqrt{2\pi n}(\frac{n}{e})^n
\end{equation*}
where \(\approx\) means that the ratio of left and right hand sides approaches 1 as n goes to infinity.
Use the formula to calculate an approximation for 20! and compare the result with the true value obtained with MATLAB’s built-in function factorial by calculating the ratio of the two quantities. Repeat for n = 50 and n = 100.
Activity 2.2 .
Create a row vector that has the following elements:
\begin{equation*}
3,\, 4\cdot 2.55,\, \frac{68}{16},\, 45,\, \sqrt[3]{110},\, \cos{25°},\, 0.05
\end{equation*}
Activity 2.3 .
Define the variables x = 0.85, y = 12.5, and then use them to create a column vector that has the following elements:
\begin{equation*}
y,\, y^x,\, ln\frac{y}{x},\, y\cdot x,\, x+y
\end{equation*}
Activity 2.4 .
Create a row vector in which the first element is 2, and the last element is 37, with an increment of 5 between the elements.
Activity 2.5 .
Create a row vector with 9 equally spaced elements in which the first element is 81 and the last element is 12.
Activity 2.6 .
Use a single command to create a row vector (assign it to a variable named a) with 19 elements such that
\begin{equation*}
a\: =\: 1\: 2\: 3\: 4\: 5\: 6\: 7\: 8\: 9\: 10\: 9\: 8\: 7\: 6\: 5\: 4\: 3\: 2\: 1
\end{equation*}
Do not type the vector explicitly.