193 lines
8.9 KiB
TeX
193 lines
8.9 KiB
TeX
\documentclass[titlepage]{article}
|
|
\usepackage{amsmath}
|
|
\usepackage{mathtools}
|
|
\usepackage{cancel}
|
|
\usepackage{amssymb}
|
|
|
|
|
|
\setcounter{section}{-1}
|
|
|
|
\begin{document}
|
|
|
|
\include{titlePage}
|
|
|
|
\section*{Introduction}
|
|
This document contains the work I, Uzair Hamed Mohammed, have done as required by this course. This is my first time using \LaTeX \ to type homework, so strange formatting may occur.\\[0.1in]
|
|
I once read in a math and Linux oriented blog that handwriting your math homework and notes, and then typing it up in \LaTeX \ greatly boosts mastery and memorization of concepts. My plan is to do exactly that, and append homework assignments to this document as they are completed. At the end of the semester, the result should be a nice and comprehensive compilation of assignments.\\[0.1in]
|
|
My current workflow is as follows:
|
|
|
|
\begin{enumerate}
|
|
\item Read the homework instructions and try to understand the assignment.
|
|
|
|
\item Work by hand, on my tablet, in the Samsung Notes app.
|
|
|
|
\item Beautify my work by transcribing it here using \LaTeX.
|
|
\end{enumerate}
|
|
When it's time to submit an assignment, I will export this document as a PDF file and turn in just the relevant pages. Please let me know what you think of this format!
|
|
|
|
\newpage
|
|
|
|
\section{Homework 0}
|
|
\textit{By turning in this assignment, I agree to abide by SFSU's academic integrity code and declare that all of my solutions are my own work: }
|
|
|
|
\subsection{About You}
|
|
\begin{enumerate}
|
|
\item[a.] My pronouns are he/him.
|
|
\item[b.] I've taken a lot of math and computer science courses. I'm not sure if I can list them, as I took most of them at the College of San Mateo and their course numbers are different. However, off the top of my head, I've taken:
|
|
\begin{itemize}
|
|
\item Calculus 1
|
|
\item Calculus 2
|
|
\item Calculus 3
|
|
\item Discrete Mathematics
|
|
\item Linear Algebra
|
|
\item Analysis of Algorithms
|
|
\item Data Structures
|
|
\end{itemize}
|
|
This list consists of the courses I think are relevant to this class; I've taken other CS courses, of course.
|
|
\item [c.] Yes, I am okay with being called on. I won't always know the answer, and I might embarrass myself sometimes, but that's alright because I believe it will force me to pay more attention and learn better, and as a result be more prepared for assignments and exams.
|
|
\end{enumerate}
|
|
|
|
\subsection{Optimization}
|
|
\begin{itemize}
|
|
\item [a.] Let a, b, and c be positive real numbers. Consider the quadratic function
|
|
$$f(\theta) = a{\theta}^2 + b\theta + c$$
|
|
Note that $\theta$ here is a real number. What value of $\theta$ minimizes $f(\theta)$?\\[0.1in]
|
|
\underline{Solution}:
|
|
Since this is a positive parabola, we can use the formula for the vertex of a parabola, $\frac{-b}{2a}$, to find the minimum:\\
|
|
$$
|
|
\boxed{\theta = \frac{-b}{2a}}
|
|
$$
|
|
|
|
\fbox{\parbox{\textwidth}{For the following problems, I'm going to use the general approach of:
|
|
\begin{enumerate}
|
|
\item Take derivative of equation
|
|
\item Set derivative equal to 0
|
|
\item Solve for $\theta$
|
|
\end{enumerate}}}
|
|
|
|
\item [b.] Let $x_1,\dots,x_n$ be real numbers. Consider the quadratic function
|
|
$$g(\theta) = \sum^n_{i=1}(\theta - x_i)^2.$$
|
|
What value of $\theta$ minimizes $g(\theta)$?\\
|
|
\underline{Solution}:
|
|
|
|
\begin{align*}
|
|
g'(\theta) &= \sum_{i=1}^{n} 2(\theta -x_i)\\
|
|
0 &= \sum_{i=1}^{n} 2(\theta -x_i)\\
|
|
\theta \sum_{i=1}^{n} 2 &= \sum_{i=1}^{n} 2x_i\\
|
|
\Aboxed{\theta &= \frac{\sum_{i=1}^{n}x_i}{n}}
|
|
\end{align*}
|
|
|
|
|
|
\item [c.] Let $x_1,\dots,x_n$ again be real numbers, and let $w_1,\dots,w_n$ be positive real numbers that we can interpret as representing the importance of each of the $x_i$'s. Consider the weighted quadratic function
|
|
$$h(\theta) = \sum_{i=1}^{n}w_i(\theta - x_i)^2.$$
|
|
What value of $\theta$ minimizes $h(\theta)$?\\
|
|
\underline{Solution}:
|
|
|
|
\begin{align*}
|
|
h'(\theta) &= 2 * \sum_{i=1}^{n} w_i (\theta - x_i)\\
|
|
0 &= 2 * \sum_{i=1}^{n} w_i (\theta - x_i)\\
|
|
\frac{0}{2} &= \frac{\cancel{2}*\sum_{i=1}^{n} w_i (\theta - x_i)}{\cancel{2}}\\
|
|
0 &= \sum_{i=1}^{n} w_i (\theta - x_i)\\
|
|
0 &= \sum_{i=1}^{n} (w_i \theta - w_i x_i)\\
|
|
0 &= \sum_{i=1}^{n} w_i \theta - \sum_{i=1}^{n} w_i x_i\\
|
|
\sum_{i=1}^{n} w_i x_i &= \sum_{i=1}^{n} w_i \theta\\
|
|
\Aboxed{\frac{\sum_{i=1}^{n} w_i x_i}{\sum_{i=1}^{n} w_i } &= \theta}
|
|
\end{align*}
|
|
|
|
\item [d.] What issue could arise in the minimization of $h$ if some of the $w_i$'s are negative?\\
|
|
\underline{Solution}: If some of the $w_i$'s are negative, it can lead to convoluted results and a possible divergence towards $\infty$
|
|
\end{itemize}
|
|
|
|
\subsection{Probability}
|
|
|
|
\begin{itemize}
|
|
\item [a.] Consider a standard 52-card deck of cards with 13 card values (Ace, King, Queen, Jack, and
|
|
2-10) in each of the four suits (clubs, diamonds, hearts, spades). If a card is drawn at random, what
|
|
is the probability that it is a spade or a two?
|
|
|
|
\underline{Solution}:\\
|
|
$\rightarrow$ \underline{Let} $P(S)$ be the probability of drawing a spade = $\frac{13}{52} = \frac{1}{4}$\\
|
|
$\rightarrow$ \underline{Let} $P(T)$ be the probability of drawing a card that is a two = $\frac{4}{52} = \frac{1}{13}$\\
|
|
|
|
$$
|
|
P(S \cap T) = \frac{1}{52}
|
|
$$
|
|
|
|
The overall probability of drawing a spade or a two is:
|
|
\begin{align*}
|
|
P(S \cup T) &= (P(S) + P(T)) - P(S \cap T)\\
|
|
&= (\frac{1}{4} + \frac{1}{13}) - \frac{1}{52}\\
|
|
\Aboxed{&= \frac{4}{13} \approx 30.7\%}
|
|
\end{align*}
|
|
|
|
|
|
\item [b.] Two factories — Factory A and Factory B — design batteries to be used in mobile phones.
|
|
Factory A produces 60\% of all batteries, and Factory B produces the other 40\%. 2\% of Factory A's
|
|
batteries have defects, and 4\% of Factory B's batteries have defects. What is the probability that a
|
|
battery is both made by Factory A and defective?
|
|
|
|
\underline{Solution}:\\
|
|
$\rightarrow$ \underline{Let} $P(A) = 0.6$ (probability battery is from Factory A)\\
|
|
$\rightarrow$ \underline{Let} $P(D|A) = 0.02$ (probaility battery is defective if it's from Factory A)\\
|
|
$\rightarrow$ \underline{Let} $P(A)' = 0.4$ (probability battery is not from Factory A)\\
|
|
$\rightarrow$ \underline{Let} $P(D|A)' = 0.04$ (probability battery is defective if it's not from Factory A)
|
|
|
|
$\rightarrow$ \underline{Find} $P(A \cap D)$.
|
|
|
|
$$\begin{gathered}$$
|
|
...\\...\\...\\P(A \cap D) = 0.012 \approx 1.2\%
|
|
$$\end{gathered}$$
|
|
|
|
|
|
\item [c.] Consider the following (made up) facts about COVID incidence and testing:
|
|
\begin{itemize}
|
|
\item In the absence of any special information, the probability that a person has COVID is 1\%.
|
|
\item If a person has COVID, the probability that a test will correctly read positive is 80\%.
|
|
\item If a person does not have COVID, the probability that a test will incorrectly produce a false positive is 10\%.
|
|
\end{itemize}
|
|
|
|
Suppose you take a COVID test and it reads positive. Given the facts above, what is the probability
|
|
that you have COVID?
|
|
|
|
\underline{Solution}:\\
|
|
$\rightarrow$ \underline{Let} $C$ = COVID\\
|
|
$\rightarrow$ \underline{Let} $T$ = Positive Test\\[0.5cm]
|
|
$\rightarrow$ \underline{Let} $P(C) = 0.01$ (probability of having COVID)\\
|
|
$\rightarrow$ \underline{Let} $P(T|C)$ = $0.8$ (probability of a positive test if a person has COVID)\\
|
|
$\rightarrow$ \underline{Let} $P(T|C)' = 0.1$ (probability of a false positive)\\
|
|
$\rightarrow$ \underline{Find} $P(C|T)$ (probability of having COVID with a positive test result)
|
|
|
|
\begin{align*}
|
|
P(T) &= P(T|C) * (P(C) + (P(T|C)' * P(C)'))\\
|
|
P(T) &= 0.8 * (0.01 + (0.1 * 0.99))\\
|
|
P(T) &= 0.0872
|
|
\end{align*}
|
|
|
|
\rule{4.4in}{0.5pt}
|
|
|
|
\begin{align*}
|
|
P(C|T) &= \frac{(0.8*0.01)}{0.0872}\\
|
|
&= \frac{0.008}{0.0872}\\
|
|
\Aboxed{&= \frac{10}{109}\approx 9.17\%}
|
|
\end{align*}
|
|
|
|
\item [d. ] Suppose you repeatedly roll a fair six-sided die until you roll a 1 (and then you stop). Every
|
|
time you roll a 3, you win a points, and every time you roll a 6, you lose b points. You do not win or
|
|
lose any points if you roll a 2, 4, or 5. What is the expected number of points (as a function of a and
|
|
b) you will have when you stop?
|
|
\end{itemize}
|
|
|
|
\subsection{Counting}
|
|
|
|
\begin{itemize}
|
|
\item [a.] $n \times n$ grid, rectangle, Big O?\\
|
|
\underline{Solution}: $O(n^2)$
|
|
|
|
\item [b.] Three rectangles, possible ways?\\
|
|
\underline{Solution}: $n^2 * n^2 * n^2 = n^6$
|
|
\end{itemize}
|
|
|
|
\subsection{Programming in Python}
|
|
See attached .py file
|
|
|
|
\end{document} |