diff --git a/README.md b/README.md index f4ba268..4d24ad9 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,27 @@ Hiển thị bảng có kích thước lớn hơn trang văn bản.
+ Bài tập 8: +Tạo bảng/ma trận trong đại số tuyến tính (nâng cao) + + +``` +Vẽ các bảng/ma trận trong đại số tuyến tính phục vụ cho mục đích mô tả và giải thích. + +**Yêu cầu:** + +* Tạo được bảng/ma trận trong đại số tuyến tính. +``` + +**Tham khảo:** [exercise_08.pdf](problemset/exercise_08.pdf) - [solution](problemset/solutions/8.tex) +
+ + + +
+ + Bài tập 9: Hình ảnh trong Latex @@ -205,13 +225,13 @@ Hình ảnh trong Latex * Đặt hình ảnh tại vị trí chỉ định. ``` -**Tham khảo:** [exercise_08.pdf](problemset/exercise_08.pdf) - [solution](problemset/solutions/8.tex) +**Tham khảo:** [exercise_09.pdf](problemset/exercise_09.pdf) - [solution](problemset/solutions/9.tex)
- Bài tập 9: + Bài tập 10: Chèn mã nguồn vào tài liệu @@ -223,12 +243,12 @@ Format mã nguồn * Sử dụng package `listings` để chèn một đoạn mã. ``` -**Tham khảo:** [exercise_09.pdf](problemset/exercise_09.pdf) - [solution](problemset/solutions/9.tex) +**Tham khảo:** [exercise_10.pdf](problemset/exercise_10.pdf) - [solution](problemset/solutions/10.tex)
- Bài tập 10: + Bài tập 11: Làm việc với khoảng cách dòng @@ -240,12 +260,12 @@ Làm cho mã nguồn hiển thị đẹp hơn. * Tăng khoảng cách giữa các dòng trong đoạn mã. ``` -**Tham khảo:** [exercise_10.pdf](problemset/exercise_10.pdf) - [solution](problemset/solutions/10.tex) +**Tham khảo:** [exercise_11.pdf](problemset/exercise_11.pdf) - [solution](problemset/solutions/11.tex)
- Bài tập 11: + Bài tập 12: Trích dẫn tài liệu @@ -259,7 +279,7 @@ Hướng dẫn trích dẫn và danh sách tài liệu tham khảo bằng BibTeX ``` -**Tham khảo:** [exercise_11.pdf](problemset/exercise_11.pdf) - [solution](problemset/solutions/11.tex) +**Tham khảo:** [exercise_12.pdf](problemset/exercise_12.pdf) - [solution](problemset/solutions/12.tex)
diff --git a/problemset/exercise_08.pdf b/problemset/exercise_08.pdf index 9bfb24e..ef79014 100644 Binary files a/problemset/exercise_08.pdf and b/problemset/exercise_08.pdf differ diff --git a/problemset/exercise_09.pdf b/problemset/exercise_09.pdf index c13ac50..9bfb24e 100644 Binary files a/problemset/exercise_09.pdf and b/problemset/exercise_09.pdf differ diff --git a/problemset/exercise_10.pdf b/problemset/exercise_10.pdf index 1751cc6..c13ac50 100644 Binary files a/problemset/exercise_10.pdf and b/problemset/exercise_10.pdf differ diff --git a/problemset/exercise_11.pdf b/problemset/exercise_11.pdf index 0d9433d..1751cc6 100644 Binary files a/problemset/exercise_11.pdf and b/problemset/exercise_11.pdf differ diff --git a/problemset/exercise_12.pdf b/problemset/exercise_12.pdf new file mode 100644 index 0000000..0d9433d Binary files /dev/null and b/problemset/exercise_12.pdf differ diff --git a/problemset/solutions/10.tex b/problemset/solutions/10.tex index 6909018..7245ab8 100644 --- a/problemset/solutions/10.tex +++ b/problemset/solutions/10.tex @@ -9,9 +9,6 @@ \usepackage{graphicx} \usepackage{listings} \usepackage{float} -\usepackage{setspace} - - \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} @@ -82,7 +79,6 @@ \subsection{Bài toán 3} \end{figure} Mã giả nguồn của thuật toán -\begin{onehalfspace} \begin{lstlisting}[language=Python] def sobel_edge_detection(image, filter): import numpy as np @@ -93,5 +89,4 @@ \subsection{Bài toán 3} gradient_magnitude *= 255.0 / gradient_magnitude.max() return gradient_magnitude \end{lstlisting} -\end{onehalfspace} \end{document} \ No newline at end of file diff --git a/problemset/solutions/11.tex b/problemset/solutions/11.tex index 8340592..6909018 100644 --- a/problemset/solutions/11.tex +++ b/problemset/solutions/11.tex @@ -11,14 +11,12 @@ \usepackage{float} \usepackage{setspace} -\bibliographystyle{ieeetr} \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} \definecolor{backcolour}{rgb}{0.95,0.95,0.92} - \lstdefinestyle{mystyle}{ backgroundcolor=\color{backcolour}, commentstyle=\color{codegreen}, @@ -47,8 +45,6 @@ \tableofcontents \pagebreak \section{Mô tả bài toán} - - \subsection{Bài toán 1} Dữ liệu được đưa dưới dạng một danh sách các vector $D$ chiều được ký hiệu là: $X = (\vec{x}_1, \vec{x}_2, \ldots, \vec{x}_n)^T$ với $\vec{x}_i \in \mathbb{R}^d$. \\ @@ -59,7 +55,7 @@ \subsection{Bài toán 1} \label{congthuc1} \end{equation} \subsection{Bài toán 2} -Thầy Dũng muốn tham dự trại hè Pima 2022 ở Cape Town, Nam Phi. Tuy nhiên, do không có đường bay thẳng từ Thành phố Hồ Chí Minh đến Nam Phi nên thầy Dũng phải quá cảnh ở hai thành phố khác. Dựa vào bảng sau đây, hãy giúp thầy Dũng chọn lộ trình bay ít tốn kém nhất. Nguồn bài toán gốc từ bài giảng \cite{graph}. +Thầy Dũng muốn tham dự trại hè Pima 2022 ở Cape Town, Nam Phi. Tuy nhiên, do không có đường bay thẳng từ Thành phố Hồ Chí Minh đến Nam Phi nên thầy Dũng phải quá cảnh ở hai thành phố khác. Dựa vào bảng sau đây, hãy giúp thầy Dũng chọn lộ trình bay ít tốn kém nhất.\\ \begin{table}[h] \centering \begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|X|}\hline @@ -98,5 +94,4 @@ \subsection{Bài toán 3} return gradient_magnitude \end{lstlisting} \end{onehalfspace} -\bibliography{references} \end{document} \ No newline at end of file diff --git a/problemset/solutions/12.tex b/problemset/solutions/12.tex new file mode 100644 index 0000000..8340592 --- /dev/null +++ b/problemset/solutions/12.tex @@ -0,0 +1,102 @@ +\documentclass{article} +\usepackage[utf8]{vietnam} +\usepackage{xcolor} + +\usepackage{amsmath} +\usepackage{amssymb} + +\usepackage{tabularx} +\usepackage{graphicx} +\usepackage{listings} +\usepackage{float} +\usepackage{setspace} + +\bibliographystyle{ieeetr} + +\definecolor{codegreen}{rgb}{0,0.6,0} +\definecolor{codegray}{rgb}{0.5,0.5,0.5} +\definecolor{codepurple}{rgb}{0.58,0,0.82} +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} + + +\lstdefinestyle{mystyle}{ + backgroundcolor=\color{backcolour}, + commentstyle=\color{codegreen}, + keywordstyle=\color{magenta}, + numberstyle=\tiny\color{codegray}, + stringstyle=\color{codepurple}, + basicstyle=\ttfamily\footnotesize, + breakatwhitespace=false, + breaklines=true, + captionpos=b, + keepspaces=true, + numbers=left, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2 +} + +\lstset{style=mystyle} +\title{Pima2021} +\author{Long Nguyen} +\date{July 26, 2021} +\begin{document} +\maketitle +\tableofcontents +\pagebreak +\section{Mô tả bài toán} + + +\subsection{Bài toán 1} +Dữ liệu được đưa dưới dạng một danh sách các vector $D$ chiều được ký hiệu là: $X = (\vec{x}_1, \vec{x}_2, \ldots, \vec{x}_n)^T$ với $\vec{x}_i \in \mathbb{R}^d$. \\ + +Một phân phối chuẩn nhiều chiều định nghĩa bởi vector trung bình và $\vec{\mu}$ ma trận covariance $\Sigma$. Vector ngẫu nhiên $\vec{X}$ được gọi là tuân theo phân phối đều $D$ chiều ký hiệu là: $\vec{X} \sim N_D(\vec{\mu}, \Sigma)$, khi đó hàm mật độ xác suất có thể được tính như công thức \ref{congthuc1} +\begin{equation} + f(\vec{x}; \vec{\mu}, \Sigma) + = \dfrac{1}{\sqrt{(2\pi)^k|\Sigma|}} \exp{-\dfrac{1}{2} (\vec{x} - \vec{\mu}) \Sigma^{-1} (\vec{x}-\vec{\mu})^T} + \label{congthuc1} +\end{equation} +\subsection{Bài toán 2} +Thầy Dũng muốn tham dự trại hè Pima 2022 ở Cape Town, Nam Phi. Tuy nhiên, do không có đường bay thẳng từ Thành phố Hồ Chí Minh đến Nam Phi nên thầy Dũng phải quá cảnh ở hai thành phố khác. Dựa vào bảng sau đây, hãy giúp thầy Dũng chọn lộ trình bay ít tốn kém nhất. Nguồn bài toán gốc từ bài giảng \cite{graph}. +\begin{table}[h] + \centering +\begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|X|}\hline + {}&HCM&Chia\-ngmai&Singa\-pore&Santa Marta&San Antonio&Los Angeles&Paris&Cape Town \\ \hline + {{\text{HCM}}}& - &{250}&{176}&{1039}& - & - & - & - \\ \hline + {{\text{Chiangmai}}}& - & - & - & - &{1480}&{1565}&{647}& - \\ \hline + {{\text{Singapore}}}& - & - & - & - &{1733}& - &{546}& - \\ \hline + {{\text{Santa Marta}}}& - & - & - & - &{540}&{769}& - & - \\ \hline + {{\text{San Antonio}}}& - & - & - & - & - &{-}&{-}&{1103} \\ \hline + {{\text{Los Angeles}}}& - & - & - & - & - & - &{-}&{967} \\ \hline + {{\text{Paris}}}& - & - & - & - & - & - & - &{2016} \\\hline + {{\text{Cape Town}}}& - & - & - & - & - & - & - & - \\ \hline +\end{tabularx} +\caption{Bảng trọng số đường bay giữa các trạm} +\end{table} + +\subsection{Bài toán 3} +Sobel là một thuận toán phát hiện biên cạnh dựa theo gradient trên hướng x và y. Dưới đây là mô tả của thuật toán. + +\begin{figure}[H] + \centering + \includegraphics[width=0.45\textwidth]{airplane_raw.png} + \includegraphics[width=0.45\textwidth]{airplane.png} +\end{figure} + +Mã giả nguồn của thuật toán +\begin{onehalfspace} +\begin{lstlisting}[language=Python] +def sobel_edge_detection(image, filter): + import numpy as np + im_x = convolution(image, filter) + im_y = convolution(image, np.flip(filter.T, axis=0)) + gradient_magnitude = np.square(im_x) + np.square(im_y) + gradient_magnitude = np.sqrt(gradient_magnitude) + gradient_magnitude *= 255.0 / gradient_magnitude.max() + return gradient_magnitude +\end{lstlisting} +\end{onehalfspace} +\bibliography{references} +\end{document} \ No newline at end of file diff --git a/problemset/solutions/8.tex b/problemset/solutions/8.tex index 61c60d4..fc3995b 100644 --- a/problemset/solutions/8.tex +++ b/problemset/solutions/8.tex @@ -1,5 +1,6 @@ \documentclass{article} -\usepackage[utf8]{vietnam} +% \usepackage[utf8]{vietnam} +\usepackage[a4paper, total={6in, 8in}, margin=1in]{geometry} \usepackage{xcolor} \usepackage{amsmath} @@ -7,50 +8,140 @@ \usepackage{tabularx} \usepackage{graphicx} +\usepackage{listings} +\usepackage{float} +\usepackage{setspace} -\title{Pima2021} -\author{Long Nguyen} -\date{July 26, 2021} +\usepackage{array} +\usepackage{multicol} +\usepackage{multirow} +\usepackage{arydshln} + +\bibliographystyle{ieeetr} + +\definecolor{codegreen}{rgb}{0,0.6,0} +\definecolor{codegray}{rgb}{0.5,0.5,0.5} +\definecolor{codepurple}{rgb}{0.58,0,0.82} +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} + + +\lstdefinestyle{mystyle}{ + backgroundcolor=\color{backcolour}, + commentstyle=\color{codegreen}, + keywordstyle=\color{magenta}, + numberstyle=\tiny\color{codegray}, + stringstyle=\color{codepurple}, + basicstyle=\ttfamily\footnotesize, + breakatwhitespace=false, + breaklines=true, + captionpos=b, + keepspaces=true, + numbers=left, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2 +} + +\lstset{style=mystyle} +\title{Pima2024} +\author{Toan Vong} +\date{July 29, 2024} \begin{document} \maketitle \tableofcontents \pagebreak -\section{Mô tả bài toán} -\subsection{Bài toán 1} -Dữ liệu được đưa dưới dạng một danh sách các vector $D$ chiều được ký hiệu là: $X = (\vec{x}_1, \vec{x}_2, \ldots, \vec{x}_n)^T$ với $\vec{x}_i \in \mathbb{R}^d$. \\ - -Một phân phối chuẩn nhiều chiều định nghĩa bởi vector trung bình và $\vec{\mu}$ ma trận covariance $\Sigma$. Vector ngẫu nhiên $\vec{X}$ được gọi là tuân theo phân phối đều $D$ chiều ký hiệu là: $\vec{X} \sim N_D(\vec{\mu}, \Sigma)$, khi đó hàm mật độ xác suất có thể được tính như công thức \ref{congthuc1} -\begin{equation} - f(\vec{x}; \vec{\mu}, \Sigma) - = \dfrac{1}{\sqrt{(2\pi)^k|\Sigma|}} \exp{-\dfrac{1}{2} (\vec{x} - \vec{\mu}) \Sigma^{-1} (\vec{x}-\vec{\mu})^T} - \label{congthuc1} -\end{equation} -\subsection{Bài toán 2} -Thầy Dũng muốn tham dự trại hè Pima 2022 ở Cape Town, Nam Phi. Tuy nhiên, do không có đường bay thẳng từ Thành phố Hồ Chí Minh đến Nam Phi nên thầy Dũng phải quá cảnh ở hai thành phố khác. Dựa vào bảng sau đây, hãy giúp thầy Dũng chọn lộ trình bay ít tốn kém nhất.\\ -\begin{table}[h] - \centering - \begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|X|} - \hline - {}&HCM&Chia\-ngmai&Singa\-pore&Santa Marta&San Antonio&Los Angeles&Paris&Cape Town \\ - \hline - {{\text{HCM}}}& - &{250}&{176}&{1039}& - & - & - & - \\ \hline - {{\text{Chiangmai}}}& - & - & - & - &{1480}&{1565}&{647}& - \\ \hline - {{\text{Singapore}}}& - & - & - & - &{1733}& - &{546}& - \\ \hline - {{\text{Santa Marta}}}& - & - & - & - &{540}&{769}& - & - \\ \hline - {{\text{San Antonio}}}& - & - & - & - & - &{-}&{-}&{1103} \\ \hline - {{\text{Los Angeles}}}& - & - & - & - & - & - &{-}&{967} \\ \hline - {{\text{Paris}}}& - & - & - & - & - & - & - &{2016} \\ \hline - {{\text{Cape Town}}}& - & - & - & - & - & - & - & - \\ \hline - \end{tabularx} - \caption{Bảng trọng số đường bay giữa các trạm} -\end{table} - -\subsection{Bài toán 3} -Sobel là một thuật toán phát hiện biên cạnh dựa theo gradient trên hướng x và y. Dưới đây là mô tả của thuật toán. - -\begin{figure} - \centering - \includegraphics[width=0.45\textwidth]{airplane_raw.png} - \includegraphics[width=0.45\textwidth]{airplane.png} -\end{figure} +\section{Problem Description} + + +\subsection{Problem 1} +Render the matrix below: + +\[ + \begin{array}{rl@{}:cccc:cccc:c:@{}r r@{}c@{}l} + & & \multicolumn{4}{c:}{\scriptstyle{\times d}} & \multicolumn{4}{c:}{\scriptstyle{\times d}} & \multicolumn{1}{c:}{\scriptstyle{\times 1}} & \\ + & \multirow{1}{*}{$\left[\begin{array}{r}\end{array}\right.$} & \multicolumn{4}{c:}{\multirow{1}{*}{$\mathbf t$}} & \multicolumn{4}{c:}{\multirow{1}{*}{$\mathbf w$}} & w_0 & \multirow{1}{*}{$\left.\begin{array}{r}\end{array}\right]$} \\[0.5em] + \hdashline + \rule{0pt}{0.1em} + \multirow{4}{*}{$\scriptstyle{\times d}$} & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & \multicolumn{4}{c:}{\multirow{4}{*}{$-\mathbb I_d$}} & \multicolumn{4}{c:}{\multirow{4}{*}{$-\mathbb I_d$}} & \multicolumn{1}{c:}{\multirow{4}{*}{$\mathbf {(0)}_d$}} & \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & \multirow{4}{*}{$\mathbf {(0)}_d$}& \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + \hdashline \rule{0pt}{1.5em} + \multirow{4}{*}{$\scriptstyle{\times d}$} & & \multicolumn{4}{c:}{\multirow{4}{*}{$-\mathbb I_d$}} & \multicolumn{4}{c:}{\multirow{4}{*}{$\mathbb I_d$}} & \multicolumn{1}{c:}{\multirow{4}{*}{$\mathbf {(0)}_d$}} & & & \multirow{4}{*}{$\mathbf {(0)}_d$} \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{} & \multicolumn{1}{c:}{ } & & & \\ + \hdashline + \rule{0pt}{1.5em} + \multirow{4}{*}{$\scriptstyle{\times n}$} & & \multicolumn{4}{c:}{\multirow{4}{*}{$\mathbf {(0)}_{n\times d}$}} & \multicolumn{4}{c:}{\multirow{1}{*}{$-y_1 \mathbf x_1^T$}} & \multicolumn{1}{c:}{\multirow{4}{*}{$-\mathbf y$}} & & & \multirow{4}{*}{$-\mathbf y$}\\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{\multirow{1}{*}{$-y_2 \mathbf x_2^T$}} & \multicolumn{1}{c:}{} & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{\vdots} & \multicolumn{1}{c:}{} & & & \\ + & & \multicolumn{4}{c:}{} & \multicolumn{4}{c:}{\multirow{1}{*}{$-y_n \mathbf x_n^T$}} & \multicolumn{1}{c:}{} & & & \\ + \end{array} +\] + +\textbf{Hints:} +\begin{itemize} + \item Use \textbackslash\texttt{array} or \textbackslash\texttt{tabular} instead of normal matrices commands for easy aligning. + \item Use \textbackslash\texttt{scriptstyle} for small text in math mode. Can be used for $\times d$, $\times n$ and $\times 1$. +\end{itemize} + +\subsection{Problem 2} +Render the matrix below: +\[ + \begin{array}{rl@{}:cccc:cccc:c:@{}r r@{}c@{}l} + & & \scriptstyle 1 & & & \scriptstyle d & \scriptstyle{d+1} & & & \scriptstyle{2d} & \scriptstyle{2d+1} & \\ + & \multirow{1}{*}{$\left[\begin{array}{r}\end{array}\right.$} & t_1 & t_2 & \cdots & t_d & w_1 & w_2 & \cdots & w_d & w_0 & \multirow{1}{*}{$\left.\begin{array}{r}\end{array}\right]$} \\[0.5em] + \hdashline + \rule{0pt}{1.5em} + \scriptscriptstyle 1 & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & -1 & 0 & \cdots & 0 & -1 & 0 & \cdots & 0 & 0 & \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & 0 & \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} \\ + & & 0 & -1 & \cdots & 0 & 0 & -1 & \cdots & 0 & 0 & & & 0 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle d & & 0 & 0 & \cdots & -1 & 0 & 0 & \cdots & -1 & 0 & & & 0 \\ + \hdashline \rule{0pt}{1.5em} + \scriptscriptstyle{d+1} & & -1 & 0 & \cdots & 0 & 1 & 0 & \cdots & 0 & 0 & & & 0 \\ + & & 0 & -1 & \cdots & 0 & 0 & 1 & \cdots & 0 & 0 & & & 0 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle 2d & & 0 & 0 & \cdots & -1 & 0 & 0 & \cdots & 1 & 0 & & & 0 \\ + \hdashline + \rule{0pt}{1.5em} + \scriptscriptstyle{2d+1} & & 0 & 0 & \cdots & 0 & -y_1x_{1, 1} & -y_1x_{1, 2} & \cdots & -y_1x_{1, d} & -y_1 & & & -y_1 \\ + & & 0 & 0 & \cdots & 0 & -y_2x_{2, 1} & -y_2x_{2, 2} & \cdots & -y_2x_{2, d} & -y_2 & & & -y_2 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle{2d+n} & & 0 & 0 & \cdots & 0 & -y_nx_{n, 1} & -y_nx_{n, 2} & \cdots & -y_nx_{n, d} & -y_n & & & -y_n \\ + \end{array} +\] + +\subsection{Problem 3} +Try to scale the matrix in Problem 2 to 75\% of the text width. +\begin{center} + \resizebox{0.75\textwidth}{!}{ + $ + \begin{array}{rl@{}:cccc:cccc:c:@{}r r@{}c@{}l} + & & \scriptstyle 1 & & & \scriptstyle d & \scriptstyle{d+1} & & & \scriptstyle{2d} & \scriptstyle{2d+1} & \\ + & \multirow{1}{*}{$\left[\begin{array}{r}\end{array}\right.$} & t_1 & t_2 & \cdots & t_d & w_1 & w_2 & \cdots & w_d & w_0 & \multirow{1}{*}{$\left.\begin{array}{r}\end{array}\right]$} \\[0.5em] + \hdashline + \rule{0pt}{1.5em} + \scriptscriptstyle 1 & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & -1 & 0 & \cdots & 0 & -1 & 0 & \cdots & 0 & 0 & \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} & \multirow{15}{*}{$\left[\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right.$} & 0 & \multirow{15}{*}{$\left.\begin{array}{r}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\end{array}\right]$} \\ + & & 0 & -1 & \cdots & 0 & 0 & -1 & \cdots & 0 & 0 & & & 0 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle d & & 0 & 0 & \cdots & -1 & 0 & 0 & \cdots & -1 & 0 & & & 0 \\ + \hdashline \rule{0pt}{1.5em} + \scriptscriptstyle{d+1} & & -1 & 0 & \cdots & 0 & 1 & 0 & \cdots & 0 & 0 & & & 0 \\ + & & 0 & -1 & \cdots & 0 & 0 & 1 & \cdots & 0 & 0 & & & 0 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle 2d & & 0 & 0 & \cdots & -1 & 0 & 0 & \cdots & 1 & 0 & & & 0 \\ + \hdashline + \rule{0pt}{1.5em} + \scriptscriptstyle{2d+1} & & 0 & 0 & \cdots & 0 & -y_1x_{1, 1} & -y_1x_{1, 2} & \cdots & -y_1x_{1, d} & -y_1 & & & -y_1 \\ + & & 0 & 0 & \cdots & 0 & -y_2x_{2, 1} & -y_2x_{2, 2} & \cdots & -y_2x_{2, d} & -y_2 & & & -y_2 \\ + & & \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots & & & \vdots \\ + \scriptscriptstyle{2d+n} & & 0 & 0 & \cdots & 0 & -y_nx_{n, 1} & -y_nx_{n, 2} & \cdots & -y_nx_{n, d} & -y_n & & & -y_n \\ + \end{array} + $ + } +\end{center} + \end{document} \ No newline at end of file diff --git a/problemset/solutions/9.tex b/problemset/solutions/9.tex index 7245ab8..61c60d4 100644 --- a/problemset/solutions/9.tex +++ b/problemset/solutions/9.tex @@ -7,33 +7,7 @@ \usepackage{tabularx} \usepackage{graphicx} -\usepackage{listings} -\usepackage{float} -\definecolor{codegreen}{rgb}{0,0.6,0} -\definecolor{codegray}{rgb}{0.5,0.5,0.5} -\definecolor{codepurple}{rgb}{0.58,0,0.82} -\definecolor{backcolour}{rgb}{0.95,0.95,0.92} -\lstdefinestyle{mystyle}{ - backgroundcolor=\color{backcolour}, - commentstyle=\color{codegreen}, - keywordstyle=\color{magenta}, - numberstyle=\tiny\color{codegray}, - stringstyle=\color{codepurple}, - basicstyle=\ttfamily\footnotesize, - breakatwhitespace=false, - breaklines=true, - captionpos=b, - keepspaces=true, - numbers=left, - numbersep=5pt, - showspaces=false, - showstringspaces=false, - showtabs=false, - tabsize=2 -} - -\lstset{style=mystyle} \title{Pima2021} \author{Long Nguyen} \date{July 26, 2021} @@ -55,38 +29,28 @@ \subsection{Bài toán 2} Thầy Dũng muốn tham dự trại hè Pima 2022 ở Cape Town, Nam Phi. Tuy nhiên, do không có đường bay thẳng từ Thành phố Hồ Chí Minh đến Nam Phi nên thầy Dũng phải quá cảnh ở hai thành phố khác. Dựa vào bảng sau đây, hãy giúp thầy Dũng chọn lộ trình bay ít tốn kém nhất.\\ \begin{table}[h] \centering -\begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|X|}\hline - {}&HCM&Chia\-ngmai&Singa\-pore&Santa Marta&San Antonio&Los Angeles&Paris&Cape Town \\ \hline - {{\text{HCM}}}& - &{250}&{176}&{1039}& - & - & - & - \\ \hline - {{\text{Chiangmai}}}& - & - & - & - &{1480}&{1565}&{647}& - \\ \hline - {{\text{Singapore}}}& - & - & - & - &{1733}& - &{546}& - \\ \hline - {{\text{Santa Marta}}}& - & - & - & - &{540}&{769}& - & - \\ \hline - {{\text{San Antonio}}}& - & - & - & - & - &{-}&{-}&{1103} \\ \hline - {{\text{Los Angeles}}}& - & - & - & - & - & - &{-}&{967} \\ \hline - {{\text{Paris}}}& - & - & - & - & - & - & - &{2016} \\\hline - {{\text{Cape Town}}}& - & - & - & - & - & - & - & - \\ \hline -\end{tabularx} -\caption{Bảng trọng số đường bay giữa các trạm} + \begin{tabularx}{\linewidth}{|l|X|X|X|X|X|X|X|X|} + \hline + {}&HCM&Chia\-ngmai&Singa\-pore&Santa Marta&San Antonio&Los Angeles&Paris&Cape Town \\ + \hline + {{\text{HCM}}}& - &{250}&{176}&{1039}& - & - & - & - \\ \hline + {{\text{Chiangmai}}}& - & - & - & - &{1480}&{1565}&{647}& - \\ \hline + {{\text{Singapore}}}& - & - & - & - &{1733}& - &{546}& - \\ \hline + {{\text{Santa Marta}}}& - & - & - & - &{540}&{769}& - & - \\ \hline + {{\text{San Antonio}}}& - & - & - & - & - &{-}&{-}&{1103} \\ \hline + {{\text{Los Angeles}}}& - & - & - & - & - & - &{-}&{967} \\ \hline + {{\text{Paris}}}& - & - & - & - & - & - & - &{2016} \\ \hline + {{\text{Cape Town}}}& - & - & - & - & - & - & - & - \\ \hline + \end{tabularx} + \caption{Bảng trọng số đường bay giữa các trạm} \end{table} \subsection{Bài toán 3} -Sobel là một thuận toán phát hiện biên cạnh dựa theo gradient trên hướng x và y. Dưới đây là mô tả của thuật toán. +Sobel là một thuật toán phát hiện biên cạnh dựa theo gradient trên hướng x và y. Dưới đây là mô tả của thuật toán. -\begin{figure}[H] +\begin{figure} \centering \includegraphics[width=0.45\textwidth]{airplane_raw.png} \includegraphics[width=0.45\textwidth]{airplane.png} \end{figure} - -Mã giả nguồn của thuật toán -\begin{lstlisting}[language=Python] -def sobel_edge_detection(image, filter): - import numpy as np - im_x = convolution(image, filter) - im_y = convolution(image, np.flip(filter.T, axis=0)) - gradient_magnitude = np.square(im_x) + np.square(im_y) - gradient_magnitude = np.sqrt(gradient_magnitude) - gradient_magnitude *= 255.0 / gradient_magnitude.max() - return gradient_magnitude -\end{lstlisting} \end{document} \ No newline at end of file