\documentclass{exam} \examtitle{MAS/104 Computational Mathematics II} % \examtime{Summer 1999} \examtime{Thursday 20 May 1999, 10:00\,am -- 12:00\,noon} % For use with pdflatex: % \pdfcompresslevel=9 \pdfoutput=1 \begin{document} \begin{rubric} The duration of this examination is 2 hours. This paper has two Sections and you should attempt both Sections. Please read carefully the instructions given at the beginning of each Section. \emph{SECTION A:} This section carries 40 marks and each question carries 4 marks. You should attempt ALL 10 questions. \emph{SECTION B:} This section carries 60 marks and each question carries 20 marks. You may attempt all 4 questions but only marks for the best 3 questions will be counted. Calculators may be used in this examination but any programming, graph plotting or algebraic facility may not be used. Please state on your answer book the name and type of machine used. \end{rubric} \section[short]{A} \begin{rubric} This section carries 40 marks and each question carries 4 marks. You should attempt ALL 10 questions. \textbf{Do \emph{NOT} begin each answer in this section on a fresh page. Write the number of the question in the \emph{left} margin.} Write the \emph{Maple} statements necessary to perform each of the following computations: \end{rubric} \begin{questions} \begin{question} % 1 Generate the sequence consisting of all the integers between 1 and 100 inclusive in reverse order, i.e.\ 100, 99, 98, \ldots, 3, 2, 1 (\textit{without} writing every element explicitly). \end{question} \begin{question} % 2 The variable \textit{L} evaluates to a list containing the element \textit{a}. Delete this element from the list, i.e.\ construct a copy of the list \textit{L} without the element \textit{a}. \end{question} \begin{question} % 3 Construct from an arbitrary list \textit{L} the list with the same elements in reverse order. \end{question} \begin{question} % 4 The variable \textit{S} evaluates to a set of sets. Construct the union (i.e.\ the set of all the elements) of all the sets in \textit{S}. \end{question} \begin{question} % 5 Find the number of elements in the largest set in a set \textit{S} of sets. \end{question} \begin{question} % 6 Define the mapping \textit{E} such that \[ \mathrm{E}(x, \,n)=1 + x + \frac {x^{2}}{2} + \frac {x^{3}}{3!} + \cdots + \frac {x^{n}}{n!}. \] The definition must allow \textit{n} to be symbolic, in which case it will treat the sum symbolically. \end{question} \begin{question} % 7 Define the mapping \textit{f} such that \[ \mathrm{f}(x)=\cases{ \sqrt{x} & if $x > 0$ \cr 0 & otherwise } \] and plot it on the domain $[-1, 1]$. \end{question} \begin{question} % 8 Define a mapping \textit{dfseq} that takes as arguments (\textit{y}, \textit{x}, \textit{n}) an expression \textit{y} that depends on a variable \textit{x} and a positive integer \textit{n}, and returns a sequence of \textit{y} followed by its first \textit{n} derivatives with respect to \textit{x}, e.g. \[ \mathrm{dfseq}(\mathrm{f}(x), \,x, \,3)=(\mathrm{f}(x), \, {\frac {\partial }{\partial x}}\,\mathrm{f}(x), \,{\frac { \partial ^{2}}{\partial x^{2}}}\,\mathrm{f}(x), \,{\frac { \partial ^{3}}{\partial x^{3}}}\,\mathrm{f}(x)). \] \end{question} \begin{question} % 9 Evaluate $\int x \tan(x^{2})\,dx$ exactly. Evaluate $\int_{0}^{\pi} \sin(x^{3})\,dx$ numerically, accurate to 15 significant figures, \emph{without} attempting to evaluate it exactly. \end{question} \begin{question} % 10 Plot the curve in two dimensions defined parametrically by $x=t^{2}, \,y=t^{3}$ for \linebreak $-1 \leq t \leq 1$. \end{question} \end{questions} \section{B} \begin{rubric} This section carries 60 marks and each question carries 20 marks. You may attempt all 4 questions but only marks for the best 3 questions will be counted. \textbf{Begin each answer in this section on a fresh page. Write the number of the question at the \emph{top} of \emph{each} page.} Except in Question 1, all \emph{Maple} functions and procedures \textbf{must} check that their arguments are of the correct types, and you should declare and use local variables where appropriate. Write the \emph{Maple} statements necessary to perform the following computations: \end{rubric} \begin{questions} \begin{question} % 1 A point $\mathrm{P}(\theta )$ in two dimensions is defined, in terms of a parameter $\theta $, to have Cartesian coordinates ($x, \,y$) such that $x=r\,\cos(\theta ), \,y=r\,\sin(\theta )$, where $r=e^{(\frac {\theta }{2\,\pi })}$. \begin{subquestions} \subquestion{} [3 marks] Load the \texttt{plots} package, and set the default for two-dimensional plotting so that the scaling is the same in both directions and no axes are plotted. \subquestion{} [2 marks] Write a mapping \textit{r} that implements the above definition of \textit{r} as a function of $\theta $. \subquestion{} [2 marks] Write a mapping \textit{S} such that S$(\Theta)$ returns a plot of the locus of $\mathrm{P}(\theta )$ as defined above for $0 \leq \theta \leq \Theta$. \subquestion{} [2 marks] Write a mapping \textit{L} such that L$(\Theta)$ returns a plot of the straight line from the origin to the point $\mathrm{P}(\Theta)$. \subquestion{} [2 marks] Write a mapping \textit{B} that combines the curve \textit{S} and the line \textit{L}. \subquestion{} [3 marks] Animate the line L$(\Theta)$ tracing out the curve S$(\Theta)$ for $0 \leq \Theta \leq 4\,\pi$ using a total of 32 frames. \subquestion{} [3 marks] Plot the space curve in three dimensions defined in terms of a parameter $\theta $ to have Cartesian coordinates ($x, \,y, \,z$) such that $x=r\,\cos(\theta ), \,y=r\,\sin(\theta ), \,z= \theta $, where $r=e^{(\frac {\theta }{2\,\pi })}$ and $0\leq \theta \leq 4\,\pi $, using normal axes through the origin. \subquestion{} [3 marks] Plot the surface in three dimensions defined in terms of parameters $\rho , \,\theta $ to have Cartesian coordinates ($x, \,y, \,z$) such that $x=\rho \,\cos(\theta ), \,y=\rho \,\sin(\theta ) , \,z=\theta $, for $0\leq \rho \leq r$ where $r=e^{(\frac {\theta }{2\,\pi })}$ and $0\leq \theta \leq 2\,\pi $. \end{subquestions} \end{question} \begin{question} % 2 \begin{subquestions} \subquestion{} [5 marks] Write a procedure called \texttt{E2D} that takes as its argument \textit{E} a relative error that must be numerical and returns the corresponding value for \texttt{Digits}, by \textit{using exact arithmetic} to compute and return the smallest positive integer \textit{d} such that $10^{-d}\leq E$. \subquestion{} [15 marks] Write a procedure called \texttt{Newton} that takes three arguments (\textit{f}, \textit{x0}, \textit{RelErr}), where \textit{f} must be a mapping (taking one argument, which you are not required to check) and \textit{x0} and \textit{RelErr} must be numerical values. The procedure should find a numerical approximation to a zero of \textit{f} near to \textit{x0} to an estimated maximum relative error \textit{RelErr} by implementing the following algorithm. \begin{enumerate} \item Determine and set an appropriate value for the precision of the numerical computation, based on the value of \textit{RelErr.} \item Compute the derivative of the mapping \textit{f}. \item Initialise the variable ${x_{\mathit{old}}}$ to the \textit{floating point approximation} to \textit{x0.} \item Compute $x_{\mathit{new}}=x_{\mathit{old}} - \frac {f(x_{\mathit{old}})}{f'(x_{\mathit{old}})}$ where $f'$ denotes the derivative of \textit{f}. \item If the \textit{magnitude} of the difference between ${x_{\mathit{new}}}$ and ${x_{\mathit{old}}}$ \textit{relative} to the \textit{magnitude} of ${x_{\mathit{new}}}$ is smaller than \textit{RelErr} then return the value of ${x_{\mathit{new}}}$. (You may assume that ${x_{\mathit{new}}}$ will never be zero.) \item Otherwise, assign the value of ${x_{\mathit{new}}}$ to the variable ${x_{\mathit{old}}}$ and repeat the algorithm from step 4. \end{enumerate} \end{subquestions} \end{question} % \pagebreak \begin{question} % 3 [20 marks] Write a procedure called \texttt{Area} that takes two arguments (\textit{y}, \textit{var}), where \textit{y} must be a polynomial with numerical coefficients and \textit{var} must have the form $x=a .. b$, where \textit{x} is a variable name and \textit{a} and \textit{b} are both numerical. The procedure should calculate a numerical approximation (accurate to the current default precision) to the total geometrical area bounded by the \textit{x}-axis, the graph of \textit{y} (a polynomial in \textit{x}) and the lines $x=a$ and $x=b$. The procedure must regard all areas as positive, regardless of whether the graph is above or below the \textit{x}-axis, by dividing the area into sub-areas bounded by segments of the graph that do not cross the \textit{x}-axis and adding the magnitudes of these sub-areas. (You may assume that the Maple equation solvers return numerical solutions in increasing numerical order.) \end{question} \abovedisplayshortskip=0pt \belowdisplayshortskip=0pt \abovedisplayskip=0pt \belowdisplayskip=0pt \begin{question}[last] % 4 \begin{subquestions} \subquestion{} [6 marks] Write a procedure \texttt{N2D} that takes two arguments (\textit{B}, \textit{n}), where \textit{B} must be a positive integer and \textit{n} must be a non-negative integer, and returns the digit sequence that corresponds to the positional representation of \textit{n} in base (radix) \textit{B}. (You may assume $B < 10$.) The procedure should work like this: \begin{verbatim} > N2D(10, 123); \end{verbatim} \[ 1, \,2, \,3 \] \subquestion{} [8 marks] Write a procedure \texttt{D2N} that takes one required argument \textit{B}, which must be a positive integer, followed by a sequence of an arbitrary number of non-negative integers that represent the digits of the positional representation of \textit{n} in base \textit{B}, and returns the corresponding integer. The procedure should work like this: \begin{verbatim} > D2N(10, 1, 2, 3); \end{verbatim} \[ 123 \] \subquestion{} [6 marks] Write a procedure \begin{center} \texttt{ConvertBase(DigitList, OldBase, NewBase)} \end{center} that calls procedures \texttt{N2D} and \texttt{D2N} as appropriate to convert a \emph{list} of digits representing a number in base \textit{OldBase} to the \emph{list} of digits representing the same number in base \textit{NewBase}. Do this by applying \texttt{N2D} to the value returned by \texttt{D2N}, and converting between sequences and lists as necessary. The procedure must check that its arguments have appropriate types. It should work as follows. \begin{verbatim} > ConvertBase([1,2,3], 10, 2); \end{verbatim} \[ [1, \,1, \,1, \,1, \,0, \,1, \,1] \] \begin{verbatim} > ConvertBase([1,1,1,1,0,1,1], 2, 10); \end{verbatim} \[ [1, \,2, \,3] \] \end{subquestions} \end{question} \end{questions} \end{document}