-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexercise4.tex
65 lines (49 loc) · 1.77 KB
/
exercise4.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
\documentclass[11pt]{article}
\include{packages}
\begin{document}
% ========== Edit your name here
%\author{Your Name}
\title{\coursename~Quiz 4: Due by \DueDate{\coursedate}{30}}
\date{}
\maketitle
\medskip
% ========== Begin answering questions here
\section*{Exercises}
\begin{enumerate}
\item Programming on paper (2 credits): \\
Write a program that outputs the Fibonacci sequence up to a number $N$. The Fibonacci sequence is given as
\begin{align*}
F(0) &= 0 \text{ and } F(1) = 1 \\
F(n) &= F(n-1) + F(n-2) \; \forall n > 1\text{.}
\end{align*}
\item Definitions (2 credits): \\
Explain the following terms in your own words:
\begin{itemize}
\item Race condition and data race (1 credit)
\item Deadlock (1 credit)
\end{itemize}
\end{enumerate}
\section*{Programming exercise}
\begin{enumerate}
\item CMake: (2 credits)\\
Use any of your previous exercises and write a CMake file to compile this exercise.
\item Numerical integration (4 credits)\\
The trapezoidal rule can be used to approximate the definite integral
\begin{align*}
\int\limits_a^b f(x) dx \approx \frac{h}{2} \sum\limits_{k=1}^N (f(x_{k-1}) + f(x_k))
\end{align*}
assuming a uniform grid in the interval $[a,b]$ with the grid size $h=\frac{b-a}{N}$.
\begin{enumerate}
\item Write a C++ program which approximates the integral for $f(x)=x^2$ on $[0,2]$ for any given $N$. (2 credits)
\item Use \lstinline|std::future| and \lstinline|std::async| compute the solution asynchronously. (2 credit)
\end{enumerate}
Validate both of your implementations against the solution
\begin{align*}
\int\limits_0^2 x^2 = \left\vert \frac{x^3}{3}\right\vert_0^2 = \frac{2^3}{3} - \frac{0^2}{3} = \frac{8}{3}\text{.}
\end{align*}
% ========== Continue adding items as needed
\end{enumerate}
\doclicenseThis
\end{document}
\grid
\grid