diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2025-11-05 10:13:24 -0700 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2025-11-05 10:13:24 -0700 |
| commit | 397ba81d210dad7331626e4bbaccfca3b745576c (patch) | |
| tree | c5dd8180103638bf0394cd2104dc687e68d0e6df | |
| parent | 6a5f11936e4419866b941f35b5dfad0729008cb5 (diff) | |
Removed book/ from tracking
44 files changed, 0 insertions, 4111 deletions
diff --git a/book/computingME.pdf b/book/computingME.pdf Binary files differdeleted file mode 100644 index bef3ef5..0000000 --- a/book/computingME.pdf +++ /dev/null diff --git a/book/computingME.tex b/book/computingME.tex deleted file mode 100644 index 2267856..0000000 --- a/book/computingME.tex +++ /dev/null @@ -1,28 +0,0 @@ -% arara: pdflatex: { synctex: on } -% arara: pdflatex: { synctex: on } - - -\input{preamble.inc} -\title{MECH 305 - Computing for Mechanical: Tutorials} -\author{Christian Kolset} -\date{April 2025} -\titlehead{Tutorials for MECH 305 - Computing for Mechanical Engineers} -\publishers{Walter Scott Jr. College of Engineering\\Colorado State University} - -\begin{document} -\maketitle -\frontmatter -\tableofcontents -%\listoffigures -%\listoftables -%\chapter{Acknowledgements} -%I would like to thank my supervisor, Professor Someone. This research was funded by the Imaginary Research Council. -\include{module0/module0} -\mainmatter -\include{module1/module1} -\include{module2/module2} -\include{module3/module3} -\include{module4/module4} -\include{module5/module5} -\backmatter -\end{document} diff --git a/book/figures b/book/figures deleted file mode 120000 index c849073..0000000 --- a/book/figures +++ /dev/null @@ -1 +0,0 @@ -../tutorials/figures
\ No newline at end of file diff --git a/book/generate_module_tex.sh b/book/generate_module_tex.sh deleted file mode 100644 index 4d3c449..0000000 --- a/book/generate_module_tex.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -book_dir="." - -# Loop through all module directories (module1, module2, etc.) -for module_path in "$book_dir"/module*/; do - [ -d "$module_path" ] || continue - - module_name=$(basename "$module_path") # e.g. module2 - module_number="${module_name//[!0-9]/}" # extract number: 2 - output_file="$module_path/$module_name.tex" - - echo "Generating $output_file" - - # Start writing the .tex file - { - echo "\\chapter{Module $module_number}" - for texfile in "$module_path"/*.tex; do - tex_base=$(basename "$texfile" .tex) - - # Skip the module.tex itself - [[ "$tex_base" == "$module_name" ]] && continue - - echo "\\input{$module_name/$tex_base}" - done - } > "$output_file" -done diff --git a/book/generate_tex_files.sh b/book/generate_tex_files.sh deleted file mode 100644 index 87238f4..0000000 --- a/book/generate_tex_files.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -markdown_dir="../tutorials" -book_dir="." - -# Enable recursive globbing with ** -shopt -s globstar - -# Loop through markdown files in source directory -for filepath in "$markdown_dir"/module_*/**/*.md; do - [ -e "$filepath" ] || continue - - # Get module name and clean it (remove underscore) - module_base=$(basename "$(dirname "$filepath")") # module_# - module_clean="${module_base//_/}" # module# - - # Get filename without extension - filename="${filepath##*/}" # file.md - filename_no_ext="${filename%.md}" # file - - # Make sure output directory exists - output_dir="$book_dir/$module_clean" - mkdir -p "$output_dir" - - # Define output .tex file path - output_file="$output_dir/$filename_no_ext.tex" - - # Convert markdown to LaTeX - pandoc -f markdown -t latex "$filepath" -o "$output_file" - - echo "Converted $filepath -> $output_file" -done diff --git a/book/module0/installing_anaconda.tex b/book/module0/installing_anaconda.tex deleted file mode 100644 index 0ff3d6f..0000000 --- a/book/module0/installing_anaconda.tex +++ /dev/null @@ -1,158 +0,0 @@ -\section{Installing Anaconda}\label{installing-anaconda} - -This tutorial will cover the steps on how to install Anaconda. - -\emph{Note for Advanced users: For those who wish to have a lightweight -installation, can install miniconda or miniForge, however for this -course we will show you how to use Anaconda Navigator. If you've never -used the programs before then using Anaconda is recommended.} - -\subsubsection{What is Anaconda?}\label{what-is-anaconda} - -Anaconda Distribution is a popular open-source Python distribution -specifically designed for scientific computing, data science, machine -learning, and artificial intelligence applications. It simplifies the -set up and use of Python for data science, machine learning, and -scientific computing. It comes with all the important tools you need, -like NumPy, Pandas, and JupyterLab, so you don't have to install -everything separately. The Conda package manager helps you install and -update software without worrying about breaking other programs. It also -lets you create separate environments, so different projects don't -interfere with each other. Additionally, Anaconda includes programs like -JupyterLab for interactive coding, and Spyer a MATLAB-like IDE. - -\subsection{Instructions}\label{instructions} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\item - Find the latest version of Navigator from the official Anaconda - Inc.~website: \href{https://www.anaconda.com/download}{Download - Anaconda} -\item - Press the \emph{Download Now} button. -\item - Press the \emph{Skip registration} button below the submit button, - otherwise submit your email address to subscribe to the Anaconda email - list. -\item - Under Anaconda Installers press \emph{Download} or find the - appropriate version for your operating system below. -\end{enumerate} - -Proceed to next section for your respective operating system. - -\subsubsection{Windows}\label{windows} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{4} -\tightlist -\item - Once the download is complete, double click the executable (.exe) file - to start the installer. Proceed with the installation instructions. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_01_welcome.png} -\caption{Welcome screen} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_02_terms.png} -\caption{Terms and conditions} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{5} -\tightlist -\item - Select the \emph{Just Me} recommended option. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_03_for.png} -\caption{Install for} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{6} -\tightlist -\item - You can leave the destination folder as is, just make sure you have a - minimum of \textasciitilde5 GB available storage space. Press - \emph{Next} to proceed. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_04_destination.png} -\caption{Installation destination} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{7} -\tightlist -\item - It is recommended to register Anaconda3 as the default python version - if you already have an instance of python installed. Otherwise, you - can leave the checkboxes as defaults. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_05_advanced.png} -\caption{Avanced Options} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_06_installing.png} -\caption{Installing} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_07_installing2.png} -\caption{Installing 2} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_08_installing_complete.png} -\caption{Complete} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_09_cloud.png} -\caption{Cloud} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_10_finish.png} -\caption{Finish} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{8} -\tightlist -\item - You made it! Anaconda is now installed, you are ready for launch. - Assuming that you didn't add Anaconda to PATH environment variable you - will need to start navigator from the start menu. -\end{enumerate} - -\subsubsection{Mac/Linux}\label{maclinux} - -Anaconda provides installation documentation for Mac and Linux users, -please refer to the -\href{https://docs.anaconda.com/anaconda/install/}{documentation page}. diff --git a/book/module0/intro_to_anaconda.tex b/book/module0/intro_to_anaconda.tex deleted file mode 100644 index e35138a..0000000 --- a/book/module0/intro_to_anaconda.tex +++ /dev/null @@ -1,193 +0,0 @@ -\section{Introduction to Anaconda Navigator}\label{introduction-to-anaconda-navigator} - -Anaconda Navigator is a program that we will be using in this course to -manage Python environments, libraries and launch programs to help us -write our python code. - -The Anaconda website nicely describes \emph{Navigator} as: - -a graphical user interface (GUI) that enables you to work with packages -and environments without needing to type conda commands in a terminal -window.Find the packages you want, install them in an environment, run -the packages, and update them -- all inside Navigator. - -To better understand how Navigator works and interacts with the anaconda -ecosystem see the figure below. - -\includegraphics{figures/AnacondaSchematic.png} - -As you schematic -indicated, Navigator is a tool in the Anaconda toolbox that allows the -user to select and configure python environments and libraries. Let's -see how we can do this. - -\subsection{Getting Started}\label{getting-started} - -Note to windows 10 users: Some installation instances do not allow users -to search the start menu for \emph{Navigator}, instead, you'll have to -find the program under the \emph{Anaconda (anaconda3)} folder. Expand -the folder and click on \emph{Anaconda Navigator} to launch the program. - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_launched.png} -\caption{Anaconda Navigator screen} -\end{figure} - -Once Navigator starts, under \emph{Home}, you'll see tiles of programs -that come with anaconda. The tab allows you to launch the programs we -will be using in this course. Before jumping straight into the programs -we will first need to configure our Python instance. - -The \emph{Environment} page allows us to install a variety of libraries -and configure our environments for different project, more on this in -the next section. - -\subsection{Environments}\label{environments} - -A Python environment can be thought of as a ``container'' where you can -have all the tools, libraries, and dependencies your Python project -needs without interfering with other projects. Think of it as a -dedicated toolbox for your project. - -Although the base environment comes with many libraries and programs -pre-installed, it's recommended to create a dedicated environment for -your projects. This protects the base environment from breaking due to -complex dependency conflicts. Let us go ahead and create a new -environment for us to use Spyder with. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - Click on the \emph{Environments} page located on the left hand side. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_environment_page.png} -\caption{Environment Page} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{1} -\tightlist -\item - At the bottom of the environments list, click \emph{Create}. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_create_new_environment.png} -\caption{Create new environment} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{2} -\item - Select the python checkbox. -\item - Select versions of python. At the time of making this tutorial the - latest version of Python is 3.xx.x. We will go ahead and use that one. -\item - Choose an appropriate name for your project. We will be creating an - environment for the Spyder IDE so we'll call it ``Spyder-env''. -\item - Click \emph{Create}. -\end{enumerate} - -For more information see -\href{https://docs.anaconda.com/working-with-conda/environments/}{Anaconda -Environments} and -\href{https://docs.anaconda.com/navigator/tutorials/manage-environments/}{Managing -environment}. - -\subsection{Package Management}\label{package-management} - -Now that we have a clean environment configured, let us install some -library we will be using for this class. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - Navigate to the environment page and select the environment we just - created in the previous section. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_select_package_to_manage.png} -\caption{Select environment to manage} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{1} -\tightlist -\item - Use the search bar in the top right corner to search for the following - packages: -\end{enumerate} - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Library & Usage \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -numpy & Numerical computation \\ -scipy & Scientific and techical computing \\ -pandas & Data manipulation and analysis \\ -matplotlib & Plots and visualizations \\ -sympy & Symbolic mathematics \\ -\end{longtable} - -\emph{Note: The libraries list may change throughout the development of -this course} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{2} -\tightlist -\item - Check the boxes to install the selected packages to the current - environment. -\end{enumerate} - -\subsection{Installing Applications}\label{installing-applications} - -From the \emph{Home} page you can install applications, to the current -environment we created in the Environment section above. In this section -we will install Spyder IDE, but the process is exactly the same for -other applications. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\item - Go to the \emph{Home} page. -\item - Select the desired environment. In our case, we select - \emph{Spyder-env}. -\item - From the Home page find the Spyder IDE tile. Click the \emph{Install} - button to start the download. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_homepage.png} -\caption{Anaconda Home Page} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{3} -\tightlist -\item - Once the download is complete, press \emph{Launch} to start the - applications. -\end{enumerate} diff --git a/book/module0/intro_to_programming.tex b/book/module0/intro_to_programming.tex deleted file mode 100644 index c73dcf4..0000000 --- a/book/module0/intro_to_programming.tex +++ /dev/null @@ -1,38 +0,0 @@ -\section{Introduction to Programming}\label{introduction-to-programming} - -\subsection{The Importance of Programming in -Engineering}\label{the-importance-of-programming-in-engineering} - -Engineering is all about solving problems, designing innovative -solutions, and making systems work efficiently. Whether you're designing -cars, airplanes, rockets, or even everyday machines, programming plays a -critical role in modern engineering. - -In mechanical engineering, programming helps us \textbf{analyze data, -model complex systems, automate repetitive tasks, and simulate -real-world physics.} For example, instead of spending hours solving -equations by hand, engineers can write a program that does it in -seconds. This saves time and therefore do more. - -With programming, mechanical engineers can: - -\begin{itemize} -\tightlist -\item - \textbf{Automate calculations:} Quickly solve equations for heat - transfer, fluid dynamics, and mechanical stresses. -\item - \textbf{Simulate systems:} Model how a bridge bends under weight or - how an engine burns fuel efficiently. -\item - \textbf{Analyze data:} Process thousands of test results to improve - designs. -\item - \textbf{Control machines:} Program robots, 3D printers, and CNC's. -\end{itemize} - -In this course, you'll see how computing and programming applies to -mechanical engineering and how they can make you a better problem -solver. By the end, you'll have the skills and understanding of how to -write programs that help you \textbf{think like an engineer in the -digital age.} diff --git a/book/module0/module0.tex b/book/module0/module0.tex deleted file mode 100644 index 6f2a4ad..0000000 --- a/book/module0/module0.tex +++ /dev/null @@ -1,3 +0,0 @@ -\chapter{Getting Started} -\input{module0/intro_to_programming} -\input{module0/installing_anaconda} diff --git a/book/module1/1_excel_to_python.tex b/book/module1/1_excel_to_python.tex deleted file mode 100644 index 300c951..0000000 --- a/book/module1/1_excel_to_python.tex +++ /dev/null @@ -1,119 +0,0 @@ -\section{Excel to Python}\label{excel-to-python} - -\begin{itemize} -\tightlist -\item - Importing -\item - Plotting -\item - Statistical analysis -\end{itemize} - -\subsection{\texorpdfstring{\textbf{How Excel Translates to -Python}}{How Excel Translates to Python}}\label{how-excel-translates-to-python} - -Here's how common Excel functionalities map to Python: - -\begin{longtable}[]{@{} - >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.2911}} - >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.7089}}@{}} -\toprule\noalign{} -\begin{minipage}[b]{\linewidth}\raggedright -\textbf{Excel Feature} -\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright -\textbf{Python Equivalent} -\end{minipage} \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -Formulas (SUM, AVERAGE) & \texttt{numpy}, \texttt{pandas} -(\texttt{df.sum()}, \texttt{df.mean()}) \\ -Sorting \& Filtering & \texttt{pandas.sort\_values()}, -\texttt{df{[}df{[}\textquotesingle{}col\textquotesingle{}{]}\ \textgreater{}\ value{]}} \\ -Conditional Formatting & \texttt{matplotlib} for highlighting \\ -Pivot Tables & \texttt{pandas.pivot\_table()} \\ -Charts \& Graphs & \texttt{matplotlib}, \texttt{seaborn}, -\texttt{plotly} \\ -Regression Analysis & \texttt{scipy.stats.linregress}, -\texttt{sklearn.linear\_model} \\ -Solver/Optimization & \texttt{scipy.optimize} \\ -VBA Macros & Python scripting with \texttt{openpyxl}, \texttt{pandas}, -or \texttt{xlwings} \\ -\end{longtable} - -\subsection{Statistical functions}\label{statistical-functions} - -\paragraph{SUM}\label{sum} - -Built-in: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{]} -\NormalTok{total }\OperatorTok{=} \BuiltInTok{sum}\NormalTok{(my\_array)} -\BuiltInTok{print}\NormalTok{(total) }\CommentTok{\# Output: 15} -\end{Highlighting} -\end{Shaded} - -Numpy: - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\NormalTok{total }\OperatorTok{=}\NormalTok{ np.}\BuiltInTok{sum}\NormalTok{(my\_array)} -\BuiltInTok{print}\NormalTok{(total) }\CommentTok{\# Output: 15} -\end{Highlighting} -\end{Shaded} - -\subsubsection{Average}\label{average} - -Built-in: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{]} -\NormalTok{average }\OperatorTok{=} \BuiltInTok{sum}\NormalTok{(my\_array) }\OperatorTok{/} \BuiltInTok{len}\NormalTok{(my\_array)} -\BuiltInTok{print}\NormalTok{(average) }\CommentTok{\# Output: 3.0} -\end{Highlighting} -\end{Shaded} - -Numpy: - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\NormalTok{average }\OperatorTok{=}\NormalTok{ np.mean(my\_array)} -\BuiltInTok{print}\NormalTok{(average) }\CommentTok{\# Output: 3.0} -\end{Highlighting} -\end{Shaded} - -\subsection{Plotting}\label{plotting} - -We can use the package \emph{matplotlib} to plot our graphs in python. -Matplotlib provides data visualization tools for the Scientific Python -Ecosystem. You can make very professional looking figures with this -tool. - -Here is a section from the matplotlib documentation page that you can -run in python. - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ matplotlib.pyplot }\ImportTok{as}\NormalTok{ plt} - -\NormalTok{fig, ax }\OperatorTok{=}\NormalTok{ plt.subplots() }\CommentTok{\# Create a figure containing a single Axes.} -\NormalTok{ax.plot([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{], [}\DecValTok{1}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{]) }\CommentTok{\# Plot some data on the Axes.} -\NormalTok{plt.show() }\CommentTok{\# Show the figure.} -\end{Highlighting} -\end{Shaded} - -Check out the documentation pages for a -\href{https://matplotlib.org/stable/users/explain/quick_start.html\#a-simple-example}{simple -example} or more information on the types of plots you came create -\href{https://matplotlib.org/stable/plot_types/index.html}{here}. diff --git a/book/module1/array.tex b/book/module1/array.tex deleted file mode 100644 index e442ba6..0000000 --- a/book/module1/array.tex +++ /dev/null @@ -1,293 +0,0 @@ -\section{Arrays}\label{arrays} - -In computer programming, an array is a structure for storing and -retrieving data. We often talk about an array as if it were a grid in -space, with each cell storing one element of the data. For instance, if -each element of the data were a number, we might visualize a -``one-dimensional'' array like a list: - -\begin{longtable}[]{@{}llll@{}} -\toprule\noalign{} -1 & 5 & 2 & 0 \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -\end{longtable} - -A two-dimensional array would be like a table: - -\begin{longtable}[]{@{}llll@{}} -\toprule\noalign{} -1 & 5 & 2 & 0 \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -8 & 3 & 6 & 1 \\ -1 & 7 & 2 & 9 \\ -\end{longtable} - -A three-dimensional array would be like a set of tables, perhaps stacked -as though they were printed on separate pages. If we visualize the -position of each element as a position in space. Then we can represent -the value of the element as a property. In other words, if we were to -analyze the stress concentration of an aluminum block, the property -would be stress. - -\begin{itemize} -\tightlist -\item - From - \href{https://numpy.org/doc/2.2/user/absolute_beginners.html}{Numpy - documentation} -\end{itemize} - -\begin{figure} -\centering -\includegraphics{figures/multi-dimensional-array.png} -\caption{Mathworks 3-D array} -\end{figure} - -If the load on this block changes over time, then we may want to add a -4th dimension i.e.~additional sets of 3-D arrays for each time -increment. As you can see - the more dimensions we add, the more -complicated of a problem we have to solve. It is possible to increase -the number of dimensions to the n-th order. This course we will not be -going beyond dimensional analysis. - -\subsection{Numpy - the python's array -library}\label{numpy---the-pythons-array-library} - -In this tutorial we will be introducing arrays and we will be using the -numpy library. Arrays, lists, vectors, matrices, sets - You might've -heard of them before, they all store data. In programming, an array is a -variable that can hold more than one value at a time. We will be using -the Numpy python library to create arrays. Since we already have -installed Numpy previously, we can start using the package. - -Before importing our first package, let's as ourselves \emph{what is a -package?} A package can be thought of as pre-written python code that we -can re-use. This means the for every script that we write in python we -need to tell it to use a certain package. We call this importing a -package. - -\subsubsection{Importing Numpy}\label{importing-numpy} - -When using packages in python, we need to let it know what package we -will be using. This is called importing. To import numpy we need to -declare it a the start of a script as follows: - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} -\end{Highlighting} -\end{Shaded} - -\begin{itemize} -\tightlist -\item - \texttt{import} - calls for a library to use, in our case it is Numpy. -\item - \texttt{as} - gives the library an alias in your script. It's common - convention in Python programming to make the code shorter and more - readable. We will be using \emph{np} as it's a standard using in many - projects. -\end{itemize} - -\subsection{Creating arrays}\label{creating-arrays} - -Now that we have imported the library we can create a one dimensional -array or \emph{vector} with three elements. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{])} -\end{Highlighting} -\end{Shaded} - -To create a \emph{matrix} we can nest the arrays to create a two -dimensional array. This is done as follows. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{matrix }\OperatorTok{=}\NormalTok{ np.array([[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{],} -\NormalTok{ [}\DecValTok{4}\NormalTok{,}\DecValTok{5}\NormalTok{,}\DecValTok{6}\NormalTok{],} -\NormalTok{ [}\DecValTok{7}\NormalTok{,}\DecValTok{8}\NormalTok{,}\DecValTok{9}\NormalTok{]])} -\end{Highlighting} -\end{Shaded} - -\emph{Note: for every array we nest, we get a new dimension in our data -structure.} - -\subsubsection{Numpy array creation -functions}\label{numpy-array-creation-functions} - -Numpy comes with some built-in function that we can use to create arrays -quickly. Here are a couple of functions that are commonly used in -python. \#\#\#\# np.arange The \texttt{np.arange()} function returns an -array with evenly spaced values within a specified range. It is similar -to the built-in \texttt{range()} function in Python but returns a Numpy -array instead of a list. The parameters for this function are the start -value (inclusive), the stop value (exclusive), and the step size. If the -step size is not provided, it defaults to 1. - -\begin{Shaded} -\begin{Highlighting}[] -\OperatorTok{\textgreater{}\textgreater{}\textgreater{}}\NormalTok{ np.arange(}\DecValTok{4}\NormalTok{)} -\NormalTok{array([}\FloatTok{0.}\NormalTok{ , }\FloatTok{1.}\NormalTok{, }\FloatTok{2.}\NormalTok{, }\FloatTok{3.}\NormalTok{ ])} -\end{Highlighting} -\end{Shaded} - -In this example, \texttt{np.arange(4)} generates an array starting from -0 and ending before 4, with a step size of 1. - -\paragraph{np.linspace}\label{np.linspace} - -The \texttt{np.linspace()} function returns an array of evenly spaced -values over a specified range. Unlike \texttt{np.arange()}, which uses a -step size to define the spacing between elements, \texttt{np.linspace()} -uses the number of values you want to generate and calculates the -spacing automatically. It accepts three parameters: the start value, the -stop value, and the number of samples. - -\begin{Shaded} -\begin{Highlighting}[] -\OperatorTok{\textgreater{}\textgreater{}\textgreater{}}\NormalTok{ np.linspace(}\FloatTok{1.}\NormalTok{, }\FloatTok{4.}\NormalTok{, }\DecValTok{6}\NormalTok{)} -\NormalTok{array([}\FloatTok{1.}\NormalTok{ , }\FloatTok{1.6}\NormalTok{, }\FloatTok{2.2}\NormalTok{, }\FloatTok{2.8}\NormalTok{, }\FloatTok{3.4}\NormalTok{, }\FloatTok{4.}\NormalTok{ ])} -\end{Highlighting} -\end{Shaded} - -In this example, \texttt{np.linspace(1.,\ 4.,\ 6)} generates 6 evenly -spaced values between 1. and 4., including both endpoints. - -Try this and see what happens: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.linspace(}\DecValTok{0}\NormalTok{,}\DecValTok{100}\NormalTok{,}\DecValTok{101}\NormalTok{)} -\NormalTok{y }\OperatorTok{=}\NormalTok{ np.sin(x)} -\end{Highlighting} -\end{Shaded} - -\paragraph{Other useful functions}\label{other-useful-functions} - -\begin{itemize} -\tightlist -\item - \texttt{np.zeros()} -\item - \texttt{np.ones()} -\item - \texttt{np.eye()} -\end{itemize} - -\subsubsection{Working with Arrays}\label{working-with-arrays} - -Now that we have been introduced to some ways to create arrays using the -Numpy functions let's start using them. \#\#\#\# Indexing Indexing in -Python allows you to access specific elements within an array based on -their position. This means you can directly retrieve and manipulate -individual items as needed. - -Python uses \textbf{zero-based indexing}, meaning the first element is -at position \textbf{0} rather than \textbf{1}. This approach is common -in many programming languages. For example, in a list with five -elements, the first element is at index \texttt{0}, followed by elements -at indices \texttt{1}, \texttt{2}, \texttt{3}, and \texttt{4}. - -Here's an example of data from a rocket test stand where thrust was -recorded as a function of time. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{thrust\_lbf }\OperatorTok{=}\NormalTok{ np.array(}\FloatTok{0.603355}\NormalTok{, }\FloatTok{2.019083}\NormalTok{, }\FloatTok{2.808092}\NormalTok{, }\FloatTok{4.054973}\NormalTok{, }\FloatTok{1.136618}\NormalTok{, }\FloatTok{0.943668}\NormalTok{)} - -\BuiltInTok{print}\NormalTok{(thrust\_lbs[}\DecValTok{3}\NormalTok{])} -\end{Highlighting} -\end{Shaded} - -Due to the nature of zero-based indexing. If we want to call the value -\texttt{4.054973} that will be the 3rd index. \#\#\#\# Operations on -arrays - Arithmetic operations (\texttt{+}, \texttt{-}, \texttt{*}, -\texttt{/}, \texttt{**}) - \texttt{np.add()}, \texttt{np.subtract()}, -\texttt{np.multiply()}, \texttt{np.divide()} - \texttt{np.dot()} for dot -product - \texttt{np.matmul()} for matrix multiplication - -\texttt{np.linalg.inv()}, \texttt{np.linalg.det()} for linear algebra -\#\#\#\#\# Statistics - \texttt{np.mean()}, \texttt{np.median()}, -\texttt{np.std()}, \texttt{np.var()} - \texttt{np.min()}, -\texttt{np.max()}, \texttt{np.argmin()}, \texttt{np.argmax()} - -Summation along axes: \texttt{np.sum(arr,\ axis=0)} - -\subsection{Exercise}\label{exercise} - -Let's solve a statics problem given the following problem - -A simply supported bridge of length L = 20 m is subjected to three point -loads: - -\begin{itemize} -\tightlist -\item - \(P_1 = 10 kN\) at \(x = 5 m\) -\item - \(P_2 = 15 kN\) at \(x = 10 m\) -\item - \(P_3 = 20 kN\) at \(x = 15 m\) -\end{itemize} - -The bridge is supported by two reaction forces at points AAA (left -support) and BBB (right support). We assume the bridge is in static -equilibrium, meaning the sum of forces and sum of moments about any -point must be zero. - -\subparagraph{Equilibrium Equations:}\label{equilibrium-equations} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - \textbf{Sum of Forces in the Vertical Direction}: - \(R_A + R_B - P_1 - P_2 - P_3 = 0\) -\item - \textbf{Sum of Moments About Point A}: - \(5 P_1 + 10 P_2 + 15 P_3 - 20 R_B = 0\) -\item - \textbf{Sum of Moments About Point B}: - \(20 R_A - 15 P_3 - 10 P_2 - 5 P_1 = 0\) -\end{enumerate} - -\subparagraph{System of Equations:}\label{system-of-equations} - -\[ -\begin{cases} R_A + R_B - 10 - 15 - 20 = 0 \\ 5(10) + 10(15) + 15(20) - 20 R_B = 0 \\ 20 R_A - 5(10) - 10(15) - 15(20) = 0 \end{cases} -\] - -\subsubsection{Solution}\label{solution} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\CommentTok{\# Define the coefficient matrix A} -\NormalTok{A }\OperatorTok{=}\NormalTok{ np.array([} -\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{],} -\NormalTok{ [}\DecValTok{0}\NormalTok{, }\OperatorTok{{-}}\DecValTok{20}\NormalTok{],} -\NormalTok{ [}\DecValTok{20}\NormalTok{, }\DecValTok{0}\NormalTok{]} -\NormalTok{])} - -\CommentTok{\# Define the right{-}hand side vector b} -\NormalTok{b }\OperatorTok{=}\NormalTok{ np.array([} - \DecValTok{45}\NormalTok{,} - \DecValTok{5}\OperatorTok{*}\DecValTok{10} \OperatorTok{+} \DecValTok{10}\OperatorTok{*}\DecValTok{15} \OperatorTok{+} \DecValTok{15}\OperatorTok{*}\DecValTok{20}\NormalTok{,} - \DecValTok{5}\OperatorTok{*}\DecValTok{10} \OperatorTok{+} \DecValTok{10}\OperatorTok{*}\DecValTok{15} \OperatorTok{+} \DecValTok{15}\OperatorTok{*}\DecValTok{20} -\NormalTok{])} - -\CommentTok{\# Solve the system of equations Ax = b} -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.linalg.lstsq(A, b, rcond}\OperatorTok{=}\VariableTok{None}\NormalTok{)[}\DecValTok{0}\NormalTok{] }\CommentTok{\# Using least squares to handle potential overdetermination} - -\CommentTok{\# Display the results} -\BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Reaction force at A (R\_A): }\SpecialCharTok{\{}\NormalTok{x[}\DecValTok{0}\NormalTok{]}\SpecialCharTok{:.2f\}}\SpecialStringTok{ kN"}\NormalTok{)} -\BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"Reaction force at B (R\_B): }\SpecialCharTok{\{}\NormalTok{x[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{:.2f\}}\SpecialStringTok{ kN"}\NormalTok{)} -\end{Highlighting} -\end{Shaded} diff --git a/book/module1/arrays.tex b/book/module1/arrays.tex deleted file mode 100644 index a5486d9..0000000 --- a/book/module1/arrays.tex +++ /dev/null @@ -1,411 +0,0 @@ - \hypertarget{matrixarrays}{% -\section{matrixArrays}\label{matrixarrays}} - -In computer programming, an array is a structure for storing and -retrieving data. We often talk about an array as if it were a grid in -space, with each cell storing one element of the data. For instance, if -each element of the data were a number, we might visualize a -``one-dimensional'' array like a list: - -\begin{longtable}[]{@{}llll@{}} -\toprule -1 & 5 & 2 & 0 \\ -\midrule -\endhead -\bottomrule -\end{longtable} - -A two-dimensional array would be like a table: - -\begin{longtable}[]{@{}llll@{}} -\toprule -1 & 5 & 2 & 0 \\ -\midrule -\endhead -8 & 3 & 6 & 1 \\ -1 & 7 & 2 & 9 \\ -\bottomrule -\end{longtable} - -A three-dimensional array would be like a set of tables, perhaps stacked -as though they were printed on separate pages. If we visualize the -position of each element as a position in space. Then we can represent -the value of the element as a property. In other words, if we were to -analyze the stress concentration of an aluminum block, the property -would be stress. - -\begin{itemize} -\tightlist -\item - From - \href{https://numpy.org/doc/2.2/user/absolute_beginners.html}{Numpy - documentation} - -\end{itemize} - -If the load on this block changes over time, then we may want to add a -4th dimension i.e.~additional sets of 3-D arrays for each time -increment. As you can see - the more dimensions we add, the more -complicated of a problem we have to solve. It is possible to increase -the number of dimensions to the n-th order. This course we will not be -going beyond dimensional analysis. - -\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} - -\hypertarget{numpy---the-pythons-array-library}{% -\section{Numpy - the python's array -library}\label{numpy---the-pythons-array-library}} - -In this tutorial we will be introducing arrays and we will be using the -numpy library. Arrays, lists, vectors, matrices, sets - You might've -heard of them before, they all store data. In programming, an array is a -variable that can hold more than one value at a time. We will be using -the Numpy python library to create arrays. Since we already have -installed Numpy previously, we can start using the package. - -Before importing our first package, let's as ourselves \emph{what is a -package?} A package can be thought of as pre-written python code that we -can re-use. This means the for every script that we write in python we -need to tell it to use a certain package. We call this importing a -package. - -\hypertarget{importing-numpy}{% -\subsection{Importing Numpy}\label{importing-numpy}} - -When using packages in python, we need to let it know what package we -will be using. This is called importing. To import numpy we need to -declare it a the start of a script as follows: - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} -\end{Highlighting} -\end{Shaded} - -\begin{itemize} -\tightlist -\item - \texttt{import} - calls for a library to use, in our case it is Numpy. -\item - \texttt{as} - gives the library an alias in your script. It's common - convention in Python programming to make the code shorter and more - readable. We will be using \emph{np} as it's a standard using in many - projects. -\end{itemize} - -\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} - -\hypertarget{creating-arrays}{% -\section{Creating arrays}\label{creating-arrays}} - -Now that we have imported the library we can create a one dimensional -array or \emph{vector} with three elements. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{])} -\end{Highlighting} -\end{Shaded} - -To create a \emph{matrix} we can nest the arrays to create a two -dimensional array. This is done as follows. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{matrix }\OperatorTok{=}\NormalTok{ np.array([[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{],} -\NormalTok{ [}\DecValTok{4}\NormalTok{,}\DecValTok{5}\NormalTok{,}\DecValTok{6}\NormalTok{],} -\NormalTok{ [}\DecValTok{7}\NormalTok{,}\DecValTok{8}\NormalTok{,}\DecValTok{9}\NormalTok{]])} -\end{Highlighting} -\end{Shaded} - -\emph{Note: for every array we nest, we get a new dimension in our data -structure.} - - \hypertarget{display-arrays}{% -\section{Display arrays}\label{display-arrays}} - -Using command print("") Accessing particular elements of an array -\ldots.. - - \hypertarget{practice-problem}{% -\section{Practice Problem}\label{practice-problem}} - -Problem statement - - \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] -\prompt{In}{incolor}{1}{\boxspacing} -\begin{Verbatim}[commandchars=\\\{\}] -\PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np} - -\PY{n}{x} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{array}\PY{p}{(}\PY{p}{[}\PY{l+m+mi}{7}\PY{p}{,} \PY{l+m+mi}{10} \PY{p}{,}\PY{l+m+mi}{12}\PY{p}{]}\PY{p}{)} - -\PY{n+nb}{print}\PY{p}{(}\PY{n}{x}\PY{p}{)} - -\PY{n+nb}{print}\PY{p}{(}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)} -\end{Verbatim} -\end{tcolorbox} - - \begin{Verbatim}[commandchars=\\\{\}] -[ 7 10 12] -10 - \end{Verbatim} - - \hypertarget{numpy-array-creation-functions}{% -\subsection{Numpy array creation -functions}\label{numpy-array-creation-functions}} - -Numpy comes with some built-in function that we can use to create arrays -quickly. Here are a couple of functions that are commonly used in -python. - -\hypertarget{np.arange}{% -\subsubsection{np.arange}\label{np.arange}} - -The \texttt{np.arange()} function returns an array with evenly spaced -values within a specified range. It is similar to the built-in -\texttt{range()} function in Python but returns a Numpy array instead of -a list. The parameters for this function are the start value -(inclusive), the stop value (exclusive), and the step size. If the step -size is not provided, it defaults to 1. - -\begin{Shaded} -\begin{Highlighting}[] -\OperatorTok{\textgreater{}\textgreater{}\textgreater{}}\NormalTok{ np.arange(}\DecValTok{4}\NormalTok{)} -\NormalTok{array([}\FloatTok{0.}\NormalTok{ , }\FloatTok{1.}\NormalTok{, }\FloatTok{2.}\NormalTok{, }\FloatTok{3.}\NormalTok{ ])} -\end{Highlighting} -\end{Shaded} - -In this example, \texttt{np.arange(4)} generates an array starting from -0 and ending before 4, with a step size of 1. - -\hypertarget{np.linspace}{% -\subsubsection{np.linspace}\label{np.linspace}} - -The \texttt{np.linspace()} function returns an array of evenly spaced -values over a specified range. Unlike \texttt{np.arange()}, which uses a -step size to define the spacing between elements, \texttt{np.linspace()} -uses the number of values you want to generate and calculates the -spacing automatically. It accepts three parameters: the start value, the -stop value, and the number of samples. - -\begin{Shaded} -\begin{Highlighting}[] -\OperatorTok{\textgreater{}\textgreater{}\textgreater{}}\NormalTok{ np.linspace(}\FloatTok{1.}\NormalTok{, }\FloatTok{4.}\NormalTok{, }\DecValTok{6}\NormalTok{)} -\NormalTok{array([}\FloatTok{1.}\NormalTok{ , }\FloatTok{1.6}\NormalTok{, }\FloatTok{2.2}\NormalTok{, }\FloatTok{2.8}\NormalTok{, }\FloatTok{3.4}\NormalTok{, }\FloatTok{4.}\NormalTok{ ])} -\end{Highlighting} -\end{Shaded} - -In this example, \texttt{np.linspace(1.,\ 4.,\ 6)} generates 6 evenly -spaced values between 1. and 4., including both endpoints. - -Try this and see what happens: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.linspace(}\DecValTok{0}\NormalTok{,}\DecValTok{100}\NormalTok{,}\DecValTok{101}\NormalTok{)} -\NormalTok{y }\OperatorTok{=}\NormalTok{ np.sin(x)} -\end{Highlighting} -\end{Shaded} - -\hypertarget{other-useful-functions}{% -\subsubsection{Other useful functions}\label{other-useful-functions}} - -\begin{itemize} -\tightlist -\item - \texttt{np.zeros()} -\item - \texttt{np.ones()} -\item - \texttt{np.eye()} -\end{itemize} - - \hypertarget{practice-problem}{% -\subsection{Practice problem}\label{practice-problem}} - -Problem statement below - - \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] -\prompt{In}{incolor}{2}{\boxspacing} -\begin{Verbatim}[commandchars=\\\{\}] -\PY{n}{y}\PY{o}{=}\PY{n}{np}\PY{o}{.}\PY{n}{linspace}\PY{p}{(}\PY{l+m+mi}{10}\PY{p}{,}\PY{l+m+mi}{20}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)} -\PY{n+nb}{print}\PY{p}{(}\PY{n}{y}\PY{p}{)} -\end{Verbatim} -\end{tcolorbox} - - \begin{Verbatim}[commandchars=\\\{\}] -[10. 12.5 15. 17.5 20. ] - \end{Verbatim} - - \hypertarget{working-with-arrays}{% -\subsection{Working with Arrays}\label{working-with-arrays}} - -Now that we have been introduced to some ways to create arrays using the -Numpy functions let's start using them. - -\hypertarget{indexing}{% -\subsubsection{Indexing}\label{indexing}} - -Indexing in Python allows you to access specific elements within an -array based on their position. This means you can directly retrieve and -manipulate individual items as needed. - -Python uses \textbf{zero-based indexing}, meaning the first element is -at position \textbf{0} rather than \textbf{1}. This approach is common -in many programming languages. For example, in a list with five -elements, the first element is at index \texttt{0}, followed by elements -at indices \texttt{1}, \texttt{2}, \texttt{3}, and \texttt{4}. - -Here's an example of data from a rocket test stand where thrust was -recorded as a function of time. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{thrust\_lbf }\OperatorTok{=}\NormalTok{ np.array(}\FloatTok{0.603355}\NormalTok{, }\FloatTok{2.019083}\NormalTok{, }\FloatTok{2.808092}\NormalTok{, }\FloatTok{4.054973}\NormalTok{, }\FloatTok{1.136618}\NormalTok{, }\FloatTok{0.943668}\NormalTok{)} - -\OperatorTok{\textgreater{}\textgreater{}\textgreater{}}\NormalTok{ thrust\_lbs[}\DecValTok{3}\NormalTok{]} -\end{Highlighting} -\end{Shaded} - -Due to the nature of zero-based indexing. If we want to call the value -\texttt{4.054973} that will be the 3rd index. - -\hypertarget{operations-on-arrays}{% -\subsubsection{Operations on arrays}\label{operations-on-arrays}} - -\begin{itemize} -\tightlist -\item - Arithmetic operations (\texttt{+}, \texttt{-}, \texttt{*}, \texttt{/}, - \texttt{**}) -\item - \texttt{np.add()}, \texttt{np.subtract()}, \texttt{np.multiply()}, - \texttt{np.divide()} -\item - \texttt{np.dot()} for dot product -\item - \texttt{np.matmul()} for matrix multiplication -\item - \texttt{np.linalg.inv()}, \texttt{np.linalg.det()} for linear algebra -\end{itemize} - -\hypertarget{statistics}{% -\paragraph{Statistics}\label{statistics}} - -\begin{itemize} -\tightlist -\item - \texttt{np.mean()}, \texttt{np.median()}, \texttt{np.std()}, - \texttt{np.var()} -\item - \texttt{np.min()}, \texttt{np.max()}, \texttt{np.argmin()}, - \texttt{np.argmax()} -\item - Summation along axes: \texttt{np.sum(arr,\ axis=0)} -\end{itemize} - -\hypertarget{combining-arrays}{% -\paragraph{Combining arrays}\label{combining-arrays}} - -\begin{itemize} -\tightlist -\item - Concatenation: \texttt{np.concatenate((arr1,\ arr2),\ axis=0)} -\item - Stacking: \texttt{np.vstack()}, \texttt{np.hstack()} -\item - Splitting: \texttt{np.split()} -\end{itemize} - - \hypertarget{exercise}{% -\section{Exercise}\label{exercise}} - -Let's solve a statics problem given the following problem - -A simply supported bridge of length L=20L = 20L=20 m is subjected to -three point loads: - -\begin{itemize} -\tightlist -\item - \(P1=1010 kN\) at \(x=5m\) -\item - \(P2=15 kN\) at \(x=10m\) -\item - \(P3=20 kN\) at \(x=15m\) -\end{itemize} - -The bridge is supported by two reaction forces at points AAA (left -support) and BBB (right support). We assume the bridge is in static -equilibrium, meaning the sum of forces and sum of moments about any -point must be zero. - -\hypertarget{equilibrium-equations}{% -\paragraph{Equilibrium Equations:}\label{equilibrium-equations}} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\item - \textbf{Sum of Forces in the Vertical Direction}: - - \(R_A + R_B - P_1 - P_2 - P_3 = 0\) -\item - \textbf{Sum of Moments About Point A}: - - \(5 P_1 + 10 P_2 + 15 P_3 - 20 R_B = 0\) -\item - \textbf{Sum of Moments About Point B}: - - \(20 R_A - 15 P_3 - 10 P_2 - 5 P_1 = 0\) -\end{enumerate} - -\hypertarget{system-of-equations}{% -\paragraph{System of Equations:}\label{system-of-equations}} - -\[ -\begin{cases} -R_A + R_B - 10 - 15 - 20 = 0 \\ -5 \cdot 10 + 10 \cdot 15 + 15 \cdot 20 - 20 R_B = 0 \\ -20 R_A - 5 \cdot 10 - 10 \cdot 15 - 15 \cdot 20 = 0 -\end{cases} -\] - - \hypertarget{solution}{% -\subsubsection{Solution}\label{solution}} - - \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] -\prompt{In}{incolor}{3}{\boxspacing} -\begin{Verbatim}[commandchars=\\\{\}] -\PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np} - -\PY{c+c1}{\PYZsh{} Define the coefficient matrix A} -\PY{n}{A} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{array}\PY{p}{(}\PY{p}{[} - \PY{p}{[}\PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{]}\PY{p}{,} - \PY{p}{[}\PY{l+m+mi}{0}\PY{p}{,} \PY{o}{\PYZhy{}}\PY{l+m+mi}{20}\PY{p}{]}\PY{p}{,} - \PY{p}{[}\PY{l+m+mi}{20}\PY{p}{,} \PY{l+m+mi}{0}\PY{p}{]} -\PY{p}{]}\PY{p}{)} - -\PY{c+c1}{\PYZsh{} Define the right\PYZhy{}hand side vector b} -\PY{n}{b} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{array}\PY{p}{(}\PY{p}{[} - \PY{l+m+mi}{45}\PY{p}{,} - \PY{l+m+mi}{5}\PY{o}{*}\PY{l+m+mi}{10} \PY{o}{+} \PY{l+m+mi}{10}\PY{o}{*}\PY{l+m+mi}{15} \PY{o}{+} \PY{l+m+mi}{15}\PY{o}{*}\PY{l+m+mi}{20}\PY{p}{,} - \PY{l+m+mi}{5}\PY{o}{*}\PY{l+m+mi}{10} \PY{o}{+} \PY{l+m+mi}{10}\PY{o}{*}\PY{l+m+mi}{15} \PY{o}{+} \PY{l+m+mi}{15}\PY{o}{*}\PY{l+m+mi}{20} -\PY{p}{]}\PY{p}{)} - -\PY{c+c1}{\PYZsh{} Solve the system of equations Ax = b} -\PY{c+c1}{\PYZsh{} Using least squares to handle potential overdetermination} -\PY{n}{x} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{linalg}\PY{o}{.}\PY{n}{lstsq}\PY{p}{(}\PY{n}{A}\PY{p}{,} \PY{n}{b}\PY{p}{,} \PY{n}{rcond}\PY{o}{=}\PY{k+kc}{None}\PY{p}{)}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]} - -\PY{c+c1}{\PYZsh{} Display the results} -\PY{n+nb}{print}\PY{p}{(}\PY{l+s+sa}{f}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Reaction force at A (R\PYZus{}A): }\PY{l+s+si}{\PYZob{}}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{l+s+si}{:}\PY{l+s+s2}{.2f}\PY{l+s+si}{\PYZcb{}}\PY{l+s+s2}{ kN}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} -\PY{n+nb}{print}\PY{p}{(}\PY{l+s+sa}{f}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Reaction force at B (R\PYZus{}B): }\PY{l+s+si}{\PYZob{}}\PY{n}{x}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{l+s+si}{:}\PY{l+s+s2}{.2f}\PY{l+s+si}{\PYZcb{}}\PY{l+s+s2}{ kN}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} -\end{Verbatim} -\end{tcolorbox} - - \begin{Verbatim}[commandchars=\\\{\}] -Reaction force at A (R\_A): 25.11 kN -Reaction force at B (R\_B): -24.89 kN - \end{Verbatim} - - - % Add a bibliography block to the postdoc diff --git a/book/module1/basics_of_python.tex b/book/module1/basics_of_python.tex deleted file mode 100644 index a68400e..0000000 --- a/book/module1/basics_of_python.tex +++ /dev/null @@ -1,248 +0,0 @@ -\section{Basics of Python}\label{basics-of-python} - -This page contains important fundamental concepts used in Python such as -syntax, operators, order or precedence and more. - -\subsection{Syntax}\label{syntax} - -\subsubsection{Indentations and blocks}\label{indentations-and-blocks} - -In python \emph{indentations} or the space at the start of each line, -signifies a block of code. This becomes important when we start working -with function and loops. We will talk more about this in the controls -structures tutorial. - -\subsubsection{Comments}\label{comments} - -Comments can be added to your code using the hash operator (\#). Any -text behind the comment operator till the end of the line will be -rendered as a comment. If you have an entire block of text or code that -needs to be commented out, the triple quotation marks (``\,``\,``) can -be used. Once used all the code after it will be considered a comment -until the comment is ended with the triple quotation marks.f - -\subsection{Operators}\label{operators} - -In python, operators are special symbols or keywords that perform -operations on values or variables. This section covers some of the most -common operator that you will see in this course. - -\subsubsection{Arithmetic operators}\label{arithmetic-operators} - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Operator & Name \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -+ & Addition \\ -- & Subtraction \\ -* & Multiplication \\ -/ & Division \\ -\% & Modulus \\ -** & Exponentiation \\ -// & Floor division \\ -\end{longtable} - -\subsubsection{Comparison operators}\label{comparison-operators} - -Used in conditional statements such as \texttt{if} statements or -\texttt{while} loops. Note that in the computer world a double equal -sign (\texttt{==}) means \emph{is equal to}, where as the single equal -sign assigns the variable or defines the variable to be something. - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Operator & Name \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -== & Equal \\ -!= & Not equal \\ -\textgreater{} & Greater than \\ -\textless{} & Less than \\ -\textgreater= & Greater than or equal to \\ -\textless= & Less than or equal to \\ -\end{longtable} - -\subsubsection{Logical operators}\label{logical-operators} - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Operator & Descrription \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -and & Returns True if both statemetns are true \\ -or & Returns True if one of the statements is true \\ -not & Reerse the result, returns False if the result is true \\ -\end{longtable} - -\subsubsection{Identity operators}\label{identity-operators} - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Operator & Description \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -is & Returns True if both variables are the same object \\ -is not & Returns True if both variables are not the same object \\ -\end{longtable} - -\subsection{Order of Operation}\label{order-of-operation} - -Similarly to the order or precedence in mathematics, different computer -languages have their own set of rules. Here is a comprehensive table of -the order of operation that python follows. - -\begin{longtable}[]{@{} - >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5093}} - >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.4907}}@{}} -\toprule\noalign{} -\begin{minipage}[b]{\linewidth}\raggedright -Operator -\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright -Description -\end{minipage} \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -\texttt{()} & Parentheses \\ -\texttt{**} & Exponentiation \\ -\texttt{+x} \texttt{-x} \texttt{\textasciitilde{}x} & Unary plus, unary -minus, and bitwise NOT \\ -\texttt{*} \texttt{/} \texttt{//} \texttt{\%} & Multiplication, -Division, floor division, and modulus \\ -\texttt{+} \texttt{-} & Addition and subtraction \\ -\texttt{\textless{}\textless{}} \texttt{\textgreater{}\textgreater{}} & -Bitwise left and right shifts \\ -\& & Bitwise AND \\ -\^{} & Bitwise XOR \\ -\textbar{} & Bitwise OR \\ -\texttt{==} \texttt{!=} \texttt{\textgreater{}} \texttt{\textgreater{}=} -\texttt{\textless{}} \texttt{\textless{}=} \texttt{is} \texttt{is\ not} -\texttt{in} \texttt{not\ in} & Comparision, identity and membership -operators \\ -\texttt{not} & logical NOT \\ -\texttt{and} & AND \\ -\texttt{or} & OR \\ -\end{longtable} - -\subsection{Data types}\label{data-types} - -Data types are different ways a computer stores data. Other data types -use fewer bits than others allowing you to better utilize your computer -memory. This is important for engineers because The most common data -types that an engineer encounters in python are numeric types. - -\texttt{int} - integer - \texttt{float} - a decimal number - -\texttt{complex} - imaginary number - -The comprehensive table below show all built-in data types available in -python. - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Category & Data Type \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -Text & int, float, complex \\ -Sequance & list, tuple, range \\ -Mapping & dict \\ -Set & set, frozenset \\ -Boolean & bytes, bytearray, memoryview \\ -Binary & bytes, bytearray, memoryview \\ -None & NoneType \\ -\end{longtable} - -\subsection{Variables}\label{variables} - -A \textbf{variable} in Python is a name that stores a value, allowing -you to use and manipulate data efficiently. - -\paragraph{Declaring and Assigning -Variables}\label{declaring-and-assigning-variables} - -It is common in low-level computer languages to declare the datatype if -the variable. In python, the datatype is set whilst you assign it. We -assign values to variables using a single \texttt{=}. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=} \DecValTok{10} \CommentTok{\# Integer} -\NormalTok{y }\OperatorTok{=} \FloatTok{3.14} \CommentTok{\# Float} -\NormalTok{name }\OperatorTok{=} \StringTok{"Joe"} \CommentTok{\# String} -\NormalTok{is\_valid }\OperatorTok{=} \VariableTok{True} \CommentTok{\# Boolean} -\end{Highlighting} -\end{Shaded} - -You can assign multiple variables at once: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{a, b, c }\OperatorTok{=} \DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3} -\end{Highlighting} -\end{Shaded} - -Similarly we can assign the same value to multiple variables: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=}\NormalTok{ y }\OperatorTok{=}\NormalTok{ z }\OperatorTok{=} \DecValTok{100} -\end{Highlighting} -\end{Shaded} - -\subparagraph{Rules}\label{rules} - -\begin{itemize} -\tightlist -\item - Must start with a letter or \texttt{\_} -\item - Cannot start with a number -\item - Can only contain letters, numbers, and \texttt{\_} -\item - Case-sensitive (\texttt{Name} and \texttt{name} are different) -\end{itemize} - -\paragraph{Updating Variables}\label{updating-variables} - -You can change a variable's value at any time. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=} \DecValTok{5} -\NormalTok{x }\OperatorTok{=}\NormalTok{ x }\OperatorTok{+} \DecValTok{10} \CommentTok{\# Now x is 15} -\end{Highlighting} -\end{Shaded} - -Or shorthand: - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{+=} \DecValTok{10} \CommentTok{\# Same as x = x + 10} -\end{Highlighting} -\end{Shaded} - -\paragraph{Variable Types \& Type -Checking}\label{variable-types-type-checking} - -Use \texttt{type()} to check a variable's type. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=} \DecValTok{10} -\BuiltInTok{print}\NormalTok{(}\BuiltInTok{type}\NormalTok{(x)) }\CommentTok{\# Output: \textless{}class \textquotesingle{}int\textquotesingle{}\textgreater{}} - -\NormalTok{y }\OperatorTok{=} \StringTok{"Hello"} -\BuiltInTok{print}\NormalTok{(}\BuiltInTok{type}\NormalTok{(y)) }\CommentTok{\# Output: \textless{}class \textquotesingle{}str\textquotesingle{}\textgreater{}} -\end{Highlighting} -\end{Shaded} diff --git a/book/module1/classes_and_objects.tex b/book/module1/classes_and_objects.tex deleted file mode 100644 index b783048..0000000 --- a/book/module1/classes_and_objects.tex +++ /dev/null @@ -1,120 +0,0 @@ -\section{Modular Programming}\label{modular-programming} - -\subsection{1. Introduction}\label{introduction} - -\begin{itemize} -\tightlist -\item - A. What is Object-Oriented Programming? -\item - B. Why use OOP? (vs.~procedural) -\item - C. Real-world analogies (e.g., modeling components like pumps, motors, - or vehicles) -\end{itemize} - -\subsection{2. Core OOP Concepts}\label{core-oop-concepts} - -\begin{itemize} -\tightlist -\item - A. \textbf{Classes and Objects} - - \begin{itemize} - \tightlist - \item - Definitions - \item - Syntax in Python - \end{itemize} -\item - B. \textbf{Attributes and Methods} - - \begin{itemize} - \tightlist - \item - Instance variables - \item - Functions inside classes - \end{itemize} -\item - C. \textbf{Encapsulation} - - \begin{itemize} - \tightlist - \item - Public vs private variables - \item - Using \texttt{\_\_init\_\_} and \texttt{self} - \end{itemize} -\item - D. \textbf{Inheritance} - - \begin{itemize} - \tightlist - \item - Parent and child classes - \item - Reuse and extension of code - \end{itemize} -\item - E. \textbf{Polymorphism} \emph{(brief overview)} - - \begin{itemize} - \tightlist - \item - Method overriding - \item - Flexibility in interfaces - \end{itemize} -\end{itemize} - -\subsection{3. Python OOP Syntax and -Examples}\label{python-oop-syntax-and-examples} - -\begin{itemize} -\tightlist -\item - A. Define a simple class (e.g., \texttt{Spring}) -\item - B. Instantiate objects and use methods -\item - C. Show \texttt{\_\_init\_\_}, \texttt{\_\_str\_\_}, custom methods -\item - D. Add a derived class (e.g., \texttt{DampedSpring} inherits from - \texttt{Spring}) -\end{itemize} - -\subsection{4. Engineering Applications of -OOP}\label{engineering-applications-of-oop} - -\begin{itemize} -\tightlist -\item - A. Modeling a mechanical system using classes - - \begin{itemize} - \tightlist - \item - Example: Mass-Spring-Damper system - \end{itemize} -\item - B. Creating reusable components (e.g., \texttt{Material}, - \texttt{Beam}, \texttt{Force}) -\item - C. Organizing simulation code with OOP -\end{itemize} - -\subsection{5. Hands-On Coding Activity}\label{hands-on-coding-activity} - -\begin{itemize} -\tightlist -\item - A. Write a class for a basic physical component (e.g., \texttt{Motor}) -\item - B. Add behavior (e.g., \texttt{calculate\_torque}) -\item - C. Extend with inheritance (e.g., \texttt{ServoMotor}) -\item - D. Bonus: Integrate two objects to simulate interaction -\end{itemize} diff --git a/book/module1/computational_expense.tex b/book/module1/computational_expense.tex deleted file mode 100644 index f315969..0000000 --- a/book/module1/computational_expense.tex +++ /dev/null @@ -1 +0,0 @@ -\section{Computational Expense}\label{computational-expense} diff --git a/book/module1/computing_fundamentals.tex b/book/module1/computing_fundamentals.tex deleted file mode 100644 index af38b93..0000000 --- a/book/module1/computing_fundamentals.tex +++ /dev/null @@ -1,19 +0,0 @@ -\section{Computing Fundamentals}\label{computing-fundamentals} - -\subsection{Using computers as a tool for -engineers}\label{using-computers-as-a-tool-for-engineers} - -\subsection{How do computers work?}\label{how-do-computers-work} - -Globe analogy: Hardware, Kernel, Shell, Application, Software. - -\subsection{Interfaces}\label{interfaces} - -\subsubsection{Text editor for -Scripting}\label{text-editor-for-scripting} - -\subsubsection{Command window}\label{command-window} - -Command window, terminal, console, command prompt you might've heard of -theses terms before. They all essentially mean the same thing. The -command window is used to control your system. diff --git a/book/module1/control_structures.tex b/book/module1/control_structures.tex deleted file mode 100644 index 4042e09..0000000 --- a/book/module1/control_structures.tex +++ /dev/null @@ -1,202 +0,0 @@ -\section{Control Structures}\label{control-structures} - -Control structures allow us to control the flow of execution in a Python -program. The two main types are \textbf{conditional statements -(\texttt{if} statements)} and \textbf{loops (\texttt{for} and -\texttt{while} loops)}. - -\subsection{Conditional Statements}\label{conditional-statements} - -Conditional statements allow a program to execute different blocks of -code depending on whether a given condition is \texttt{True} or -\texttt{False}. These conditions are typically comparisons, such as -checking if one number is greater than another. - -\subsubsection{\texorpdfstring{The \texttt{if} -Statement}{The if Statement}}\label{the-if-statement} - -The simplest form of a conditional statement is the \texttt{if} -statement. If the condition evaluates to \texttt{True}, the indented -block of code runs. Otherwise, the program moves on without executing -the statement. - -For example, consider a situation where we need to determine if a person -is an adult based on their age. If the age is 18 or greater, we print a -message saying they are an adult. - -\subsubsection{\texorpdfstring{The \texttt{if-else} -Statement}{The if-else Statement}}\label{the-if-else-statement} - -Sometimes, we need to specify what should happen if the condition is -\texttt{False}. The \texttt{else} clause allows us to handle this case. -Instead of just skipping over the block, the program can execute an -alternative action. - -For instance, if a person is younger than 18, they are considered a -minor. If the condition of being an adult is not met, the program will -print a message indicating that the person is a minor. - -\subsubsection{\texorpdfstring{The \texttt{if-elif-else} -Statement}{The if-elif-else Statement}}\label{the-if-elif-else-statement} - -When dealing with multiple conditions, the \texttt{if-elif-else} -structure is useful. The program evaluates conditions in order, -executing the first one that is \texttt{True}. If none of the conditions -are met, the \texttt{else} block runs. - -For example, in a grading system, different score ranges correspond to -different letter grades. If a student's score is 90 or higher, they -receive an ``A''. If it's between 80 and 89, they get a ``B'', and so -on. If none of the conditions match, they receive an ``F''. - -\subsubsection{\texorpdfstring{Nested \texttt{if} -Statements}{Nested if Statements}}\label{nested-if-statements} - -Sometimes, we need to check conditions within other conditions. This is -known as \textbf{nesting}. For example, if we first determine that a -person is an adult, we can then check if they are a student. Based on -that information, we print different messages. - -\begin{Shaded} -\begin{Highlighting}[] -\CommentTok{\# Getting user input for the student\textquotesingle{}s score} -\NormalTok{score }\OperatorTok{=} \BuiltInTok{int}\NormalTok{(}\BuiltInTok{input}\NormalTok{(}\StringTok{"Enter the student\textquotesingle{}s score (0{-}100): "}\NormalTok{))} - -\ControlFlowTok{if} \DecValTok{0} \OperatorTok{\textless{}=}\NormalTok{ score }\OperatorTok{\textless{}=} \DecValTok{100}\NormalTok{:} - \ControlFlowTok{if}\NormalTok{ score }\OperatorTok{\textgreater{}=} \DecValTok{90}\NormalTok{:} -\NormalTok{ grade }\OperatorTok{=} \StringTok{"A"} - \ControlFlowTok{elif}\NormalTok{ score }\OperatorTok{\textgreater{}=} \DecValTok{80}\NormalTok{:} -\NormalTok{ grade }\OperatorTok{=} \StringTok{"B"} - \ControlFlowTok{elif}\NormalTok{ score }\OperatorTok{\textgreater{}=} \DecValTok{70}\NormalTok{:} -\NormalTok{ grade }\OperatorTok{=} \StringTok{"C"} - \ControlFlowTok{elif}\NormalTok{ score }\OperatorTok{\textgreater{}=} \DecValTok{60}\NormalTok{:} -\NormalTok{ grade }\OperatorTok{=} \StringTok{"D"} - \ControlFlowTok{else}\NormalTok{:} -\NormalTok{ grade }\OperatorTok{=} \StringTok{"F"} \CommentTok{\# Score below 60 is a failing grade} - - - \ControlFlowTok{if}\NormalTok{ grade }\OperatorTok{==} \StringTok{"F"}\NormalTok{:} - \BuiltInTok{print}\NormalTok{(}\StringTok{"The student has failed."}\NormalTok{)} -\NormalTok{ retake\_eligible }\OperatorTok{=} \BuiltInTok{input}\NormalTok{(}\StringTok{"Is the student eligible for a retest? (yes/no): "}\NormalTok{).strip().lower()} - - \ControlFlowTok{if}\NormalTok{ retake\_eligible }\OperatorTok{==} \StringTok{"yes"}\NormalTok{:} - \BuiltInTok{print}\NormalTok{(}\StringTok{"The student is eligible for a retest."}\NormalTok{)} - \ControlFlowTok{else}\NormalTok{:} - \BuiltInTok{print}\NormalTok{(}\StringTok{"The student has failed the course and must retake it next semester."}\NormalTok{)} - - -\end{Highlighting} -\end{Shaded} - -\subsection{Loops in Python}\label{loops-in-python} - -Loops allow a program to execute a block of code multiple times. This is -especially useful for tasks such as processing lists of data, performing -repetitive calculations, or automating tasks. - -\subsubsection{\texorpdfstring{The \texttt{for} -Loop}{The for Loop}}\label{the-for-loop} - -A \texttt{for} loop iterates over a sequence, such as a list, tuple, -string, or a range of numbers. Each iteration assigns the next value in -the sequence to a loop variable, which can then be used inside the loop. - -For instance, if we have a list of fruits and want to print each fruit's -name, a \texttt{for} loop can iterate over the list and display each -item. - -Another useful feature of \texttt{for} loops is the \texttt{range()} -function, which generates a sequence of numbers. This is commonly used -when we need to repeat an action a specific number of times. For -example, iterating from 0 to 4 allows us to print a message five times. - -Additionally, the \texttt{enumerate()} function can be used to loop -through a list while keeping track of the index of each item. This is -useful when both the position and the value in a sequence are needed. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{fruits }\OperatorTok{=}\NormalTok{ [}\StringTok{"apple"}\NormalTok{, }\StringTok{"banana"}\NormalTok{, }\StringTok{"cherry"}\NormalTok{] } -\ControlFlowTok{for}\NormalTok{ x }\KeywordTok{in}\NormalTok{ fruits: } - \BuiltInTok{print}\NormalTok{(x)} -\end{Highlighting} -\end{Shaded} - -\begin{Shaded} -\begin{Highlighting}[] -\ControlFlowTok{for}\NormalTok{ x }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(}\DecValTok{6}\NormalTok{): } - \BuiltInTok{print}\NormalTok{(x) } -\ControlFlowTok{else}\NormalTok{: } - \BuiltInTok{print}\NormalTok{(}\StringTok{"Finally finished!"}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -\subsubsection{\texorpdfstring{The \texttt{while} -Loop}{The while Loop}}\label{the-while-loop} - -Unlike \texttt{for} loops, which iterate over a sequence, \texttt{while} -loops continue running as long as a specified condition remains -\texttt{True}. This is useful when the number of iterations is not known -in advance. - -For example, a countdown timer can be implemented using a \texttt{while} -loop. The loop will continue decreasing the count until it reaches zero. - -It's important to be careful with \texttt{while} loops to avoid infinite -loops, which occur when the condition never becomes \texttt{False}. To -prevent this, ensure that the condition will eventually change during -the execution of the loop. - -A \texttt{while} loop can also be used to wait for a certain event to -occur. For example, in interactive programs, a \texttt{while\ True} loop -can keep running until the user provides a valid input, at which point -we break out of the loop. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{i }\OperatorTok{=} \DecValTok{1} -\ControlFlowTok{while}\NormalTok{ i }\OperatorTok{\textless{}} \DecValTok{6}\NormalTok{: } -\NormalTok{  print(i) } -\NormalTok{  i }\OperatorTok{+=} \DecValTok{1} -\end{Highlighting} -\end{Shaded} - -\subsection{Loop Control Statements}\label{loop-control-statements} - -Python provides special statements to control the behavior of loops. -These can be used to break out of a loop, skip certain iterations, or -simply include a placeholder for future code. - -\subsubsection{\texorpdfstring{The \texttt{break} -Statement}{The break Statement}}\label{the-break-statement} - -The \texttt{break} statement is used to exit a loop before it has -iterated through all its elements. When the \texttt{break} statement is -encountered, the loop stops immediately, and the program continues -executing the next statement outside the loop. - -For instance, if we are searching for a specific value in a list, we can -use a \texttt{break} statement to stop the loop as soon as we find the -item, instead of continuing unnecessary iterations. - -\subsubsection{\texorpdfstring{The \texttt{continue} -Statement}{The continue Statement}}\label{the-continue-statement} - -The \texttt{continue} statement is used to skip the current iteration -and proceed to the next one. Instead of exiting the loop entirely, it -simply moves on to the next cycle. - -For example, if we are iterating over numbers and want to skip -processing number 2, we can use \texttt{continue}. The loop will ignore -that iteration and proceed with the next number. - -\subsubsection{\texorpdfstring{The \texttt{pass} -Statement}{The pass Statement}}\label{the-pass-statement} - -The \texttt{pass} statement is a placeholder that does nothing. It is -useful when a block of code is syntactically required but no action -needs to be performed yet. - -For example, in a loop where a condition has not yet been implemented, -using \texttt{pass} ensures that the code remains valid while avoiding -errors. diff --git a/book/module1/functions.tex b/book/module1/functions.tex deleted file mode 100644 index 19a8a85..0000000 --- a/book/module1/functions.tex +++ /dev/null @@ -1,110 +0,0 @@ -\section{Functions}\label{functions} - -Like a traditional mathematical functions, python functions can take an -input, process it, and give an output. In python, the input variables -are referred to as \emph{arguments}. Functions are blocks of code that -is run every time it's called. This allows us to re-use code. - -Functions are defined by using the def keyword. Reminder: it is -important to keep track of indentations as it signifies the end of the -function when the indentation returns back to the same level. - -\subsection{Defining Functions}\label{defining-functions} - -\subsubsection{Simple function}\label{simple-function} - -A simple function with no input variable can be useful if you need to -re-use code multiple times without having to re-write it. - -\begin{Shaded} -\begin{Highlighting}[] - \KeywordTok{def}\NormalTok{ function\_name():} - \BuiltInTok{print}\NormalTok{(}\StringTok{"This is from a function"}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -\subsubsection{Defining a function with one -input}\label{defining-a-function-with-one-input} - -We can pass variables through to the function to be processed as -follows: - -\begin{Shaded} -\begin{Highlighting}[] - \KeywordTok{def}\NormalTok{ function(x):} - \BuiltInTok{print}\NormalTok{(x }\OperatorTok{+} \StringTok{" is best"}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -Note input variables can be of any data type (integer, float, string, -etc.). \#\#\# Returning values from a function If we want to calculate a -value and pass it back to the script for further use, we can use the -\texttt{return} keyword. Let's define a linear function that takes two -inputs, \texttt{x} and \texttt{b}, computes the corresponding \texttt{y} -value, and returns it so it can be used elsewhere in the code. - -\begin{Shaded} -\begin{Highlighting}[] - \KeywordTok{def}\NormalTok{ function(x, b):} -\NormalTok{ y }\OperatorTok{=} \DecValTok{3}\OperatorTok{*}\NormalTok{x}\OperatorTok{+}\NormalTok{b} - \ControlFlowTok{return}\NormalTok{ y} -\end{Highlighting} -\end{Shaded} - -For multiple output variables we can add \#\# Calling functions Now that -we've covered defining functions we want to call the function in order -to execute the block inside the function. To do this, we simply re-call -the function name as follows. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{function(}\DecValTok{2}\NormalTok{,}\OperatorTok{{-}}\DecValTok{1}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -Note that when running this code, nothing happens. This is because we -haven't told the computer what to do with the output. Hence, if we wish -to store the output then we need to use the assign operator \texttt{=}. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{output }\OperatorTok{=}\NormalTok{ function(}\DecValTok{2}\NormalTok{,}\OperatorTok{{-}}\DecValTok{1}\NormalTok{)} - -\BuiltInTok{print}\NormalTok{(output)} -\end{Highlighting} -\end{Shaded} - -In case you want to return multiple output variable from a single -function we will have\ldots{} - -\subsection{Summary}\label{summary} - -\begin{Shaded} -\begin{Highlighting}[] -\KeywordTok{def}\NormalTok{ function\_name(argument1, argument2, argument3):} -\NormalTok{ output1 }\OperatorTok{=}\NormalTok{ argument1 }\OperatorTok{*}\NormalTok{ argument2 }\OperatorTok{{-}}\NormalTok{ argument3} -\NormalTok{ output2 }\OperatorTok{=}\NormalTok{ argument2 }\OperatorTok{+}\NormalTok{ argument3} - \ControlFlowTok{return}\NormalTok{ output1, output2} - -\NormalTok{[solution1, solution2] }\OperatorTok{=}\NormalTok{ function\_name(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -\begin{itemize} -\tightlist -\item - \texttt{def} - defines a function. All the code that is indented - underneath is considered inside the function block. -\item - \texttt{function\_name} - this is used to call the function block. -\item - \texttt{argument1} (optional) - input variable. This is data that can - be pass to the function. It is possible to have multiple variables - separated by a comma. As well as can be omitted if the function should - just give you an output such as. -\item - \texttt{return} (optional) - if you wish to return something to your - script, the return keyword is used. The keyword can be followed by an - output variable or a constant. For multiple output variables, separate - them by a comma. -\end{itemize} diff --git a/book/module1/fundamentals_of_programming.tex b/book/module1/fundamentals_of_programming.tex deleted file mode 100644 index 6a412d1..0000000 --- a/book/module1/fundamentals_of_programming.tex +++ /dev/null @@ -1,25 +0,0 @@ -\section{Fundamentals of programming}\label{fundamentals-of-programming} - -\subsection{Orientation of common -interfaces}\label{orientation-of-common-interfaces} - -In this section we will cover the use and purpose of some common -interfaces that you'll be using in this course. - -\subsubsection{Command window, terminal, console, command -prompt.}\label{command-window-terminal-console-command-prompt.} - -This is a text based interface that allows the users to interact with -the computer. It is used to execute commands, run scripts or programs. - -\subsubsection{Text Editor / Script}\label{text-editor-script} - -Your text editor is the program used to write a script which can be -re-run every time you call it from the command window. This can be a -built-in text editor such as Spyder and MATLAB provide or an external on -such a notepad++. - -\begin{verbatim} - Globe analogy: Hardware, Kernel, shell, Application software. -- Scripting -\end{verbatim} diff --git a/book/module1/installing_anaconda.tex b/book/module1/installing_anaconda.tex deleted file mode 100644 index 0ff3d6f..0000000 --- a/book/module1/installing_anaconda.tex +++ /dev/null @@ -1,158 +0,0 @@ -\section{Installing Anaconda}\label{installing-anaconda} - -This tutorial will cover the steps on how to install Anaconda. - -\emph{Note for Advanced users: For those who wish to have a lightweight -installation, can install miniconda or miniForge, however for this -course we will show you how to use Anaconda Navigator. If you've never -used the programs before then using Anaconda is recommended.} - -\subsubsection{What is Anaconda?}\label{what-is-anaconda} - -Anaconda Distribution is a popular open-source Python distribution -specifically designed for scientific computing, data science, machine -learning, and artificial intelligence applications. It simplifies the -set up and use of Python for data science, machine learning, and -scientific computing. It comes with all the important tools you need, -like NumPy, Pandas, and JupyterLab, so you don't have to install -everything separately. The Conda package manager helps you install and -update software without worrying about breaking other programs. It also -lets you create separate environments, so different projects don't -interfere with each other. Additionally, Anaconda includes programs like -JupyterLab for interactive coding, and Spyer a MATLAB-like IDE. - -\subsection{Instructions}\label{instructions} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\item - Find the latest version of Navigator from the official Anaconda - Inc.~website: \href{https://www.anaconda.com/download}{Download - Anaconda} -\item - Press the \emph{Download Now} button. -\item - Press the \emph{Skip registration} button below the submit button, - otherwise submit your email address to subscribe to the Anaconda email - list. -\item - Under Anaconda Installers press \emph{Download} or find the - appropriate version for your operating system below. -\end{enumerate} - -Proceed to next section for your respective operating system. - -\subsubsection{Windows}\label{windows} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{4} -\tightlist -\item - Once the download is complete, double click the executable (.exe) file - to start the installer. Proceed with the installation instructions. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_01_welcome.png} -\caption{Welcome screen} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_02_terms.png} -\caption{Terms and conditions} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{5} -\tightlist -\item - Select the \emph{Just Me} recommended option. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_03_for.png} -\caption{Install for} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{6} -\tightlist -\item - You can leave the destination folder as is, just make sure you have a - minimum of \textasciitilde5 GB available storage space. Press - \emph{Next} to proceed. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_04_destination.png} -\caption{Installation destination} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{7} -\tightlist -\item - It is recommended to register Anaconda3 as the default python version - if you already have an instance of python installed. Otherwise, you - can leave the checkboxes as defaults. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_05_advanced.png} -\caption{Avanced Options} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_06_installing.png} -\caption{Installing} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_07_installing2.png} -\caption{Installing 2} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_08_installing_complete.png} -\caption{Complete} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_09_cloud.png} -\caption{Cloud} -\end{figure} - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_installer_10_finish.png} -\caption{Finish} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{8} -\tightlist -\item - You made it! Anaconda is now installed, you are ready for launch. - Assuming that you didn't add Anaconda to PATH environment variable you - will need to start navigator from the start menu. -\end{enumerate} - -\subsubsection{Mac/Linux}\label{maclinux} - -Anaconda provides installation documentation for Mac and Linux users, -please refer to the -\href{https://docs.anaconda.com/anaconda/install/}{documentation page}. diff --git a/book/module1/intro_to_anaconda.tex b/book/module1/intro_to_anaconda.tex deleted file mode 100644 index 935b3f5..0000000 --- a/book/module1/intro_to_anaconda.tex +++ /dev/null @@ -1,191 +0,0 @@ -\section{Introduction to Anaconda -Navigator}\label{introduction-to-anaconda-navigator} - -Anaconda Navigator is a program that we will be using in this course to -manage Python environments, libraries and launch programs to help us -write our python code. - -The Anaconda website nicely describes \emph{Navigator} as: - -\emph{a graphical user interface (GUI) that enables you to work with -packages and environments without needing to type conda commands in a -terminal window.Find the packages you want, install them in an -environment, run the packages, and update them -- all inside Navigator.} - -To better understand how Navigator works and interacts with the anaconda -ecosystem see the figure below. -\includegraphics{figures/AnacondaSchematic.png} As you schematic -indicated, Navigator is a tool in the Anaconda toolbox that allows the -user to select and configure python environments and libraries. Let's -see how we can do this. - -\subsection{Getting Started}\label{getting-started} - -Note to windows 10 users: Some installation instances do not allow users -to search the start menu for \emph{Navigator}, instead, you'll have to -find the program under the \emph{Anaconda (anaconda3)} folder. Expand -the folder and click on \emph{Anaconda Navigator} to launch the program. - -\begin{figure} -\centering -\includegraphics{figures/installingAnaconda_windows_launched.png} -\caption{Anaconda Navigator screen} -\end{figure} - -Once Navigator starts, under \emph{Home}, you'll see tiles of programs -that come with anaconda. The tab allows you to launch the programs we -will be using in this course. Before jumping straight into the programs -we will first need to configure our Python instance. - -The \emph{Environment} page allows us to install a variety of libraries -and configure our environments for different project, more on this in -the next section. - -\subsection{Environments}\label{environments} - -A Python environment can be thought of as a ``container'' where you can -have all the tools, libraries, and dependencies your Python project -needs without interfering with other projects. Think of it as a -dedicated toolbox for your project. - -Although the base environment comes with many libraries and programs -pre-installed, it's recommended to create a dedicated environment for -your projects. This protects the base environment from breaking due to -complex dependency conflicts. Let us go ahead and create a new -environment for us to use Spyder with. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - Click on the \emph{Environments} page located on the left hand side. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_environment_page.png} -\caption{Environment Page} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{1} -\tightlist -\item - At the bottom of the environments list, click \emph{Create}. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_create_new_environment.png} -\caption{Create new environment} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{2} -\item - Select the python checkbox. -\item - Select versions of python. At the time of making this tutorial the - latest version of Python is 3.xx.x. We will go ahead and use that one. -\item - Choose an appropriate name for your project. We will be creating an - environment for the Spyder IDE so we'll call it ``Spyder-env''. -\item - Click \emph{Create}. -\end{enumerate} - -For more information see -\href{https://docs.anaconda.com/working-with-conda/environments/}{Anaconda -Environments} and -\href{https://docs.anaconda.com/navigator/tutorials/manage-environments/}{Managing -environment}. - -\subsection{Package Management}\label{package-management} - -Now that we have a clean environment configured, let us install some -library we will be using for this class. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - Navigate to the environment page and select the environment we just - created in the previous section. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_select_package_to_manage.png} -\caption{Select environment to manage} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{1} -\tightlist -\item - Use the search bar in the top right corner to search for the following - packages: -\end{enumerate} - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Library & Usage \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -numpy & Numerical computation \\ -scipy & Scientific and techical computing \\ -pandas & Data manipulation and analysis \\ -matplotlib & Plots and visualizations \\ -sympy & Symbolic mathematics \\ -\end{longtable} - -\emph{Note: The libraries list may change throughout the development of -this course} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{2} -\tightlist -\item - Check the boxes to install the selected packages to the current - environment. -\end{enumerate} - -\subsection{Installing Applications}\label{installing-applications} - -From the \emph{Home} page you can install applications, to the current -environment we created in the Environment section above. In this section -we will install Spyder IDE, but the process is exactly the same for -other applications. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\item - Go to the \emph{Home} page. -\item - Select the desired environment. In our case, we select - \emph{Spyder-env}. -\item - From the Home page find the Spyder IDE tile. Click the \emph{Install} - button to start the download. -\end{enumerate} - -\begin{figure} -\centering -\includegraphics{figures/anaconda_homepage.png} -\caption{Anaconda Home Page} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\setcounter{enumi}{3} -\tightlist -\item - Once the download is complete, press \emph{Launch} to start the - applications. -\end{enumerate} diff --git a/book/module1/intro_to_programming.tex b/book/module1/intro_to_programming.tex deleted file mode 100644 index c73dcf4..0000000 --- a/book/module1/intro_to_programming.tex +++ /dev/null @@ -1,38 +0,0 @@ -\section{Introduction to Programming}\label{introduction-to-programming} - -\subsection{The Importance of Programming in -Engineering}\label{the-importance-of-programming-in-engineering} - -Engineering is all about solving problems, designing innovative -solutions, and making systems work efficiently. Whether you're designing -cars, airplanes, rockets, or even everyday machines, programming plays a -critical role in modern engineering. - -In mechanical engineering, programming helps us \textbf{analyze data, -model complex systems, automate repetitive tasks, and simulate -real-world physics.} For example, instead of spending hours solving -equations by hand, engineers can write a program that does it in -seconds. This saves time and therefore do more. - -With programming, mechanical engineers can: - -\begin{itemize} -\tightlist -\item - \textbf{Automate calculations:} Quickly solve equations for heat - transfer, fluid dynamics, and mechanical stresses. -\item - \textbf{Simulate systems:} Model how a bridge bends under weight or - how an engine burns fuel efficiently. -\item - \textbf{Analyze data:} Process thousands of test results to improve - designs. -\item - \textbf{Control machines:} Program robots, 3D printers, and CNC's. -\end{itemize} - -In this course, you'll see how computing and programming applies to -mechanical engineering and how they can make you a better problem -solver. By the end, you'll have the skills and understanding of how to -write programs that help you \textbf{think like an engineer in the -digital age.} diff --git a/book/module1/jupyter_lab_notebook.tex b/book/module1/jupyter_lab_notebook.tex deleted file mode 100644 index b7d9353..0000000 --- a/book/module1/jupyter_lab_notebook.tex +++ /dev/null @@ -1,146 +0,0 @@ -\subsection{Introduction}\label{introduction} - -Jupyter Notebooks are often used for data science and scientific -computing such as machine learning as the interactive design allow you -to experiment easily with your code. For our purpose, we will use -Notebooks as it's a useful tool to learn how to code as well as writing -reports. - -\emph{Note on the difference between Notebook and Lab: Jupyter Notebook -offers a simplified, lightweight notebook authoring experience, where -as, JupyterLab offers a feature-rich, tabbed multi-notebook editing -environment with additional tools like a customizable interface layout -and system console} - -\subsection{Setup and Installation}\label{setup-and-installation} - -Jupyter Notebooks can be installed either from the Anaconda Navigator -home page or directly from your Conda terminal. - -Terminal: \texttt{conda\ install\ conda-forge::jupyterlab} - -\subsection{Notebook Basics}\label{notebook-basics} - -Jupyter Notebooks are files which allows you to combine \emph{Code} and -\emph{Markdown} cells in one single document. The code cells, allow you -to interactively run python code and print and plot data in your -document. If you wish to update or change data your code you can re-run -the cell to update the output. The markdown cells allows you to write -text, titles and insert images in your documentation using the markup -language \emph{Markdown}. - -To start a new notebook select -\texttt{File\ \textgreater{}\ New\ \textgreater{}\ Notebook} or right -click the file browser and select \texttt{New\ notebook}, this will -prompt you to select a kernel (the Jupyter notebook ``engine''). For -now, just select the default Kernel 3. This will start a new fresh -kernel for us to use. Next, it's recommended to rename the file. - -Now that we have a blank notebook we can start to add cells. Add a cell -and change the type to Markdown. Add a title with the hash symbol -(\texttt{\#}). As shown below. - -\begin{Shaded} -\begin{Highlighting}[] -\FunctionTok{\# Title here} -\end{Highlighting} -\end{Shaded} - -Press \texttt{Shift\ +\ Enter} to run the cell. You just entered created -your first markdown cell. Now let's do the same but instead select code -as the cell type, we're going to add some python code to the document. - -\begin{Shaded} -\begin{Highlighting}[] -\NormalTok{x }\OperatorTok{=} \DecValTok{4} -\NormalTok{y }\OperatorTok{=} \DecValTok{3} - -\NormalTok{x}\OperatorTok{**}\DecValTok{2}\OperatorTok{+}\DecValTok{2}\OperatorTok{*}\NormalTok{y} -\end{Highlighting} -\end{Shaded} - -Again, run the cell and see what happens. You should've gotten an output -of \texttt{22}. You can now use the notebook as a calculator, but there -is so much more we can do. - -The order of running code matters. Think of the code cells as code -snippets. Every time you run a cell variable will be updated. This means -that the current state of all variables, functions, and imports depends -on the history of what cells have been executed and in what order. In -other words, if you run a later cell before running an earlier one that -defines a variable or function it needs, you will get an error. If you -change a variable in one cell and rerun it, that new value immediately -affects the results of any cells that use that variable afterward --- -but not any previously run results unless you rerun them too. Variables -and imports persist in memory between cells, but only based on the -current session state --- if you restart the kernel, you lose all -previous definitions unless you re-run the necessary cells. Therefore, -let's press the \texttt{Restart\ the\ kernel} button on the top window.3 - -Because of this, it's best practice to; Run cells in order, restart the -kernel and run all cells -(\texttt{Kernel\ -\textgreater{}\ Restart\ \&\ Run\ All}) to make sure -everything works cleanly and predictably and lastly, initialize -important variables or imports in early cells, so they are always -defined before they are needed. - -\subsection{Making your document look good with -Markdown}\label{making-your-document-look-good-with-markdown} - -Creating titles or headers is done with the hash symbol. The number of -hashes determines whether it's a sub-title \texttt{\#}, \texttt{\#\#}, -\texttt{\#\#\#} - -\subsubsection{Lists}\label{lists} - -There are two types of list in - Bullet lists: \texttt{-\ item} - -Numbered lists: \texttt{1.\ item} \#\#\# Style - Emphasis: -\emph{italic}, \textbf{bold}, \texttt{monospace} - -\subsubsection{Mathematical Equation}\label{mathematical-equation} - -Markdown supports LaTeX format equations. Inline equation is opened and -closed with a single \texttt{\$}. For a block math a double -\texttt{\$\$} is used instead of single. - -\begin{itemize} -\tightlist -\item - Inline: This equation is inline \texttt{\$E\ =\ mc\^{}2\$} in with the - markdown text. -\item - Block: Whilst this is a block: - \texttt{\$\$\textbackslash{}int\_0\^{}\textbackslash{}infty\ e\^{}\{-x\^{}2\}\ dx\ =\ \textbackslash{}frac\{\textbackslash{}sqrt\{\textbackslash{}pi\}\}\{2\}\$\$} -\end{itemize} - -\subsubsection{Links and images}\label{links-and-images} - -You can insert links to a different local file or online urls like this: -{[}Link{]}(file.md). I insert an image it's the same however start with -an exclamation mark \texttt{!} like this: !{[}Image -Caption{]}(picture.png) - -\subsection{Exporting and Sharing}\label{exporting-and-sharing} - -To export your notebook go to - -\texttt{File} \textgreater{} \texttt{Download\ As} - -You can then select these options. - -\begin{itemize} -\tightlist -\item - Notebook (\texttt{.ipynb}) -\item - HTML -\item - PDF (requires LaTeX) -\item - Markdown -\end{itemize} - -For homework assignments, download an HTML version of your document, -then from your browser, save or print as a PDF. Alternatively, you can -install the LaTeX typesetting system and export your document directly -as PDF from jupyter. diff --git a/book/module1/module1.tex b/book/module1/module1.tex deleted file mode 100644 index 27bf133..0000000 --- a/book/module1/module1.tex +++ /dev/null @@ -1,12 +0,0 @@ -\chapter{Module 1: Introductory Programming Concepts} -\input{module1/intro_to_anaconda} -\input{module1/jupyter_lab_notebook} -\input{module1/spyder_getting_started} -\input{module1/basics_of_python} -\input{module1/array} -\input{module1/control_structures} -\input{module1/functions} -\input{module1/classes_and_objects} -\input{module1/open_source_software} -\input{module1/1_excel_to_python} -\input{module1/computational_expense} diff --git a/book/module1/open_source_software.tex b/book/module1/open_source_software.tex deleted file mode 100644 index 96de292..0000000 --- a/book/module1/open_source_software.tex +++ /dev/null @@ -1,104 +0,0 @@ -\section{Open Source Software}\label{open-source-software} - -Open-source software (OSS) is a type of software that allows users to -access, modify, and distribute its source code freely. It is built on -principles of collaboration, transparency, and community-driven -development. - -You've probably heard of the saying ``Don't reinventing the wheel''. -This - -\subsubsection{Key Principles of Open Source -Software}\label{key-principles-of-open-source-software} - -\begin{itemize} -\tightlist -\item - \textbf{Free Distribution:} Anyone can download and use the software - without cost. -\item - \textbf{Access to Source Code:} Users can view and modify the code to - suit their needs. -\item - \textbf{Community Collaboration:} Developers from around the world - contribute to improvements and security fixes. -\end{itemize} - -\subsubsection{Benefits of Open Source -Software}\label{benefits-of-open-source-software} - -\begin{itemize} -\tightlist -\item - \textbf{Cost-effectiveness:} Open-source software is free to use, - making it accessible to individuals and organizations. -\item - \textbf{Transparency and Security:} Open code allows for peer review, - reducing security vulnerabilities. -\item - \textbf{Community Support:} Global developer communities provide - assistance, troubleshooting, and improvements. -\item - \textbf{Customization and Flexibility:} Users can modify software to - fit their specific requirements. -\end{itemize} - -\subsubsection{Challenges of Open Source -Software}\label{challenges-of-open-source-software} - -\begin{itemize} -\tightlist -\item - \textbf{Usability Issues:} Some open-source software may have a - steeper learning curve. -\item - \textbf{Compatibility Problems:} Integration with proprietary systems - may require additional effort. -\item - \textbf{Support and Documentation:} The quality of documentation and - support varies. -\item - \textbf{Sustainability:} Open-source projects often rely on - volunteers, which can lead to inconsistent updates. -\end{itemize} - -\subsubsection{Popular Open Source -Projects}\label{popular-open-source-projects} - -\begin{itemize} -\tightlist -\item - \textbf{Operating Systems:} Linux, Ubuntu -\item - \textbf{Web Browsers:} Mozilla Firefox -\item - \textbf{Programming Languages:} Python, JavaScript -\item - \textbf{Office Suites:} LibreOffice -\item - \textbf{Multimedia Tools:} Audacity, Blender -\item - \textbf{Software Development:} Git, GitHub, Apache -\end{itemize} - -\subsubsection{How to Contribute to Open -Source}\label{how-to-contribute-to-open-source} - -\begin{itemize} -\tightlist -\item - \textbf{Finding Projects:} Platforms like GitHub, GitLab, and - SourceForge host many open-source projects. -\item - \textbf{Understanding Licensing:} Common licenses include GPL, MIT, - and Apache. -\item - \textbf{Ways to Contribute:} Developers can contribute code, test - software, write documentation, translate, or help with design. -\item - \textbf{Best Practices for Contributions:} Using version control - (Git), writing clean code, and following community guidelines are - essential for successful collaboration. -\end{itemize} - -\subsection{Licensing}\label{licensing} diff --git a/book/module1/spyder_getting_started.tex b/book/module1/spyder_getting_started.tex deleted file mode 100644 index 3133b15..0000000 --- a/book/module1/spyder_getting_started.tex +++ /dev/null @@ -1,107 +0,0 @@ -\section{Getting started with Spyder}\label{getting-started-with-spyder} - -In this tutorial we will cover the basics of using the Spyder IDE -(Interactive Development Environment). If you've ever worked with MATLAB -before, then this will feel familiar. Spyder is a program that allows -you to write, run and de-bug code. - -\subsection{Launching Spyder}\label{launching-spyder} - -Using Anaconda we will select the environment we created earlier -\emph{spyder-dev} and then we can launch spyder from the Home page. - -\subsection{Spyder Interface}\label{spyder-interface} - -\begin{figure} -\centering -\includegraphics{figures/spyder_interface.png} -\caption{Spyder Interface} -\end{figure} - -Once you open up Spyder in it's default configuration, you'll see three -sections; the editor IPython Console, Help viewer. You can customize the -interface to suit your prefference and needs some of which include, -rearrange, undock, hide panes. Feel free to set up Spyder as you like. - -\subsubsection{Editor}\label{editor} - -This pane is used to write your scripts. The - -\begin{figure} -\centering -\includegraphics{figures/editor_key_components.png} -\caption{Editor key components} -\end{figure} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - The left sidebar shows line numbers and displays any code analysis - warnings that exist in the current file. Clicking a line number - selects the text on that line, and clicking to the right of it sets a - \href{https://docs.spyder-ide.org/5/panes/debugging.html\#debugging-breakpoints}{breakpoint}. -\item - The scrollbars allow vertical and horizontal navigation in a file. -\item - The context (right-click) menu displays actions relevant to whatever - was clicked. -\item - The options menu (``Hamburger'' icon at top right) includes useful - settings and actions relevant to the Editor. -\item - The location bar at the top of the Editor pane shows the full path of - the current file. -\item - The tab bar displays the names of all opened files. It also has a - Browse tabs button (at left) to show every open tab and switch between - them---which comes in handy if many are open. -\end{enumerate} - -\subsubsection{IPython Console}\label{ipython-console} - -This pane allows you to interactively run functions, do math -computations, assign and modify variables. - -\begin{figure} -\centering -\includegraphics{figures/spyder_ipython_console.png} -\caption{IPython Console} -\end{figure} - -\begin{itemize} -\tightlist -\item - Automatic code completion -\item - Real-time function calltips -\item - Full GUI integration with the enhanced Spyder - \href{https://docs.spyder-ide.org/5/panes/debugging.html}{Debugger}. -\item - The - \href{https://docs.spyder-ide.org/5/panes/variableexplorer.html}{Variable - Explorer}, with GUI-based editors for many built-in and third-party - Python objects. -\item - Display of Matplotlib graphics in Spyder's - \href{https://docs.spyder-ide.org/5/panes/plots.html}{Plots} pane, if - the Inline backend is selected under \texttt{Preferences} - \textgreater{} \texttt{IPython\ console} \textgreater{} - \texttt{Graphics} \textgreater{} \texttt{Graphics\ backend}, and - inline in the console if Mute inline plotting is unchecked under the - Plots pane's options menu. -\end{itemize} - -\subsubsection{Variable Explorer}\label{variable-explorer} - -This pane shows all the defined variables (objects) stored. This can be -used to identify the data type of variables, the size and inspect larger -arrays. Double clicking the value cell opens up a window which allowing -you to inspect the data in a spreadsheet like view. - -\begin{figure} -\centering -\includegraphics{figures/spyder_variable_explorer.png} -\caption{Variable Explorer} -\end{figure} diff --git a/book/module2/ai_assisted_programming.tex b/book/module2/ai_assisted_programming.tex deleted file mode 100644 index 4d6dcde..0000000 --- a/book/module2/ai_assisted_programming.tex +++ /dev/null @@ -1,79 +0,0 @@ -\section{AI Assisted Programming}\label{ai-assisted-programming} - -\subsection{What is it?}\label{what-is-it} - -Artificial Intelligence (AI) has been around for a long time. However, -not until recently did engineers make it easy and ``fun'' to work with. -By now you probably have a pretty good idea of what AI can do. However, -you may not have used an AI assistant before. As the name suggests, an -AI assistant can help you develop code, speed up your writing with code -suggestions and allows you to focus on solving the problem at hand -rather. AI is a technology that is constantly improving. As engineers we -need to \emph{understand} how we can use AI as a tool to achieve our -goals more efficiently. This section cover good practices of how we can -implement AI and lists some AI assistant tools that we can use. - -\subsection{Good vs.~Bad uses of AI}\label{good-vs.-bad-uses-of-ai} - -Don't try to get AI to do work \emph{for you} but \emph{with you}. You -need to understand what you're doing. If you don't understand what the -AI is doing, then you're not in control of the work. You're not going to -go far until something unexpected happens. - -AI is a great learning tool, research as show that students can benefit -from using AI as personal tutor -\href{https://hbsp.harvard.edu/inspiring-minds/ai-as-personal-tutor}{more}. - -\subsection{Available tools}\label{available-tools} - -Below is a comprehensive list of tools that are available at not cost to -you. - -\begin{longtable}[]{@{}ll@{}} -\toprule\noalign{} -Name & Features \\ -\midrule\noalign{} -\endhead -\bottomrule\noalign{} -\endlastfoot -GitHub Copilot & Paid, but free for students. Integrated in GitHub. \\ -ChatGPT & Free, optional paid upgrade \\ -Grok & Free, optional paid upgrade \\ -Gemini & Free, optional paid upgrade \\ -GPT4ALL & Free and Open-Source \\ -Code GPT & Free and Open-Source \\ -Cody & Free and Open-Source \\ -DataLab AI & Free \\ -Codeium & Free \\ -aiXcoder & Free \\ -\end{longtable} - -Many of the tools above come with similar, if not, the same features. -Some of the tools come as chatbots on the web and others are extensions -that can be implemented in your favorite IDE. - -\subsection{VSCode and GitHub Copilot -Integration}\label{vscode-and-github-copilot-integration} - -We will not cover how to use VSCode in this course, however it is a very -versatile IDE that comes with many other extension, for example git, -github and github copilot integration. There are also other extensions -for other IDE's however we will only cover some basic features that the -GithHub Copilot extension in VSCode can do. - -Copilot Comes with the following features: - Get code suggestions as you -type - Ask questions about the code - Inline chat to generate code. - -Fix and debug code using the chat window - Generate code documentation - -\href{https://code.visualstudio.com/}{VSCode} -\href{https://code.visualstudio.com/docs/copilot/setup-simplified}{Copilot -extension} - -\subsection{A note on intellectual -property}\label{a-note-on-intellectual-property} - -If you have a non-disclosure-agreement (NDA) with your employer, it may -not always be possible to use AI for security and integrity reasons as -you may risk exposing confidential information with third party vendors. -It is highly recommended to be able to be able to write program -independently of an AI assistant. Always think before you share data. diff --git a/book/module2/debugging_code.tex b/book/module2/debugging_code.tex deleted file mode 100644 index 0d244fb..0000000 --- a/book/module2/debugging_code.tex +++ /dev/null @@ -1,144 +0,0 @@ -\section{Debugging Code}\label{debugging-code} - -\subsection{Introduction}\label{introduction} - -Have you ever had a piece of code not work the way you expected? What -did you do? You may have, asked a friend or used an AI assistant. In -this section, the following concepts are introduced - definition of a -bug, common types of bugs and debugging techniques. - -A \emph{software bug} is an unintentional mistake or defect with a -program, this comes either from when the programmer makes a mistake in -writing the code or the code works in a way which has consequences that -were not foreseen by the programmer. Debugging is the act removing the -bugs in the software. Debugging is a normal part of programming that -even experiences developers spend a lot of time on. - -\subsection{Types of Bugs}\label{types-of-bugs} - -When writing code you are guaranteed to have bugs in your code. These -bugs can be categorized in the following three groups. - -\begin{itemize} -\tightlist -\item - \textbf{Syntax errors} - this type of error occurs when the code fails - due to missing colons, missing indentation or a typo in code - some - languages like python are case sensitive meaning that the a capital - letter are different symbols. -\item - \textbf{Runtime errors} - e.g., dividing by zero or file not found. -\item - \textbf{Logical errors} - this may be the most dangerous that we need - to be careful with because this error can occur without any error - messages but it gives you the wrong result. -\end{itemize} - -\subsection{Debugging Techniques}\label{debugging-techniques} - -\paragraph{Print Debugging}\label{print-debugging} - -Insert print statements to check values of variables throughout the -program. - -\begin{Shaded} -\begin{Highlighting}[] -\KeywordTok{def}\NormalTok{ add(x, y):} - \BuiltInTok{print}\NormalTok{(}\SpecialStringTok{f"x = }\SpecialCharTok{\{}\NormalTok{x}\SpecialCharTok{\}}\SpecialStringTok{, y = }\SpecialCharTok{\{}\NormalTok{y}\SpecialCharTok{\}}\SpecialStringTok{"}\NormalTok{)} - \ControlFlowTok{return}\NormalTok{ x }\OperatorTok{+}\NormalTok{ y} -\end{Highlighting} -\end{Shaded} - -In the example above the print statement gives us feedback on what the -code is doing. The function in this example is obviously very simple, -but when we start applying more complex equations or function then -checking to see if the input variables are correct can indicate whether -there is an issue lies within the \texttt{add()} function or if the -function is given an incorrect input. - -\paragraph{Rubber Duck Debugging}\label{rubber-duck-debugging} - -This is a technique by which you explaining your code line by line in -natural language to someone else, yourself or an inanimate object like a -rubber duck. This can help you spot your mistake in the code. - -\paragraph{Commenting Out Code}\label{commenting-out-code} - -Using comments to temporarily suppress parts of your code help you -isolate and find the bug. - -\paragraph{IDE Debugging tools}\label{ide-debugging-tools} - -Depending if you use an IDE, they often come with some sort of debugging -tools such as breakpoints, step into/over and variables explorers. - -\paragraph{AI Chat}\label{ai-chat} - -AI chat bots can help you find typo or fix logic in your code. You may -find yourself going through the steps above when using an AI assistant -to help you debug the code. However \emph{never} assume that the code AI -gives you works the way you intend it to work. - -\subsection{Interactive Debugging -Activity}\label{interactive-debugging-activity} - -In the following code snippets, debug the code and document the -following: - What the bug is - How you found it (technique used) - What -actions you took to fix the bug - -\paragraph{Code 1}\label{code-1} - -\begin{Shaded} -\begin{Highlighting}[] -\KeywordTok{def}\NormalTok{ greet(name)} - \BuiltInTok{print}\NormalTok{(}\StringTok{"Hello, "} \OperatorTok{+}\NormalTok{ Name)} -\NormalTok{greet(}\StringTok{"John"}\NormalTok{)} -\end{Highlighting} -\end{Shaded} - -\paragraph{Code 2}\label{code-2} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\NormalTok{x }\OperatorTok{=}\NormalTok{ np.linspace(}\DecValTok{0}\NormalTok{,}\DecValTok{5}\NormalTok{,}\DecValTok{100}\NormalTok{)} -\NormalTok{y }\OperatorTok{=} \DecValTok{1}\OperatorTok{/}\NormalTok{x} - -\BuiltInTok{print}\NormalTok{(}\StringTok{"Result:"}\NormalTok{, y[}\DecValTok{0}\NormalTok{])} -\end{Highlighting} -\end{Shaded} - -\paragraph{Code 3}\label{code-3} - -\begin{Shaded} -\begin{Highlighting}[] -\KeywordTok{def}\NormalTok{ f(x):} - \ControlFlowTok{return}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}} \DecValTok{4} \CommentTok{\# Root at x = ±2} - -\KeywordTok{def}\NormalTok{ bisection(a, b, tol}\OperatorTok{=}\FloatTok{1e{-}5}\NormalTok{, max\_iter}\OperatorTok{=}\DecValTok{100}\NormalTok{):} - \ControlFlowTok{if}\NormalTok{ f(a) }\OperatorTok{*}\NormalTok{ f(b) }\OperatorTok{\textgreater{}=} \DecValTok{0}\NormalTok{:} - \BuiltInTok{print}\NormalTok{(}\StringTok{"Bisection method fails. f(a) and f(b) should have opposite signs."}\NormalTok{)} - \ControlFlowTok{return} \VariableTok{None} - - \ControlFlowTok{for}\NormalTok{ i }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(max\_iter):} -\NormalTok{ c }\OperatorTok{=}\NormalTok{ (a }\OperatorTok{+}\NormalTok{ b) }\OperatorTok{/} \DecValTok{2} - \ControlFlowTok{if} \BuiltInTok{abs}\NormalTok{(f(c)) }\OperatorTok{\textless{}}\NormalTok{ tol:} - \ControlFlowTok{return}\NormalTok{ c} - \ControlFlowTok{elif}\NormalTok{ f(c) }\OperatorTok{*}\NormalTok{ f(b) }\OperatorTok{\textless{}} \DecValTok{0}\NormalTok{:} -\NormalTok{ a }\OperatorTok{=}\NormalTok{ c} - \ControlFlowTok{else}\NormalTok{:} -\NormalTok{ b }\OperatorTok{=}\NormalTok{ c} - \ControlFlowTok{return}\NormalTok{ (a }\OperatorTok{+}\NormalTok{ b) }\OperatorTok{/} \DecValTok{2} -\end{Highlighting} -\end{Shaded} - -\subsection{Reflection}\label{reflection} - -\begin{itemize} -\tightlist -\item - What was the most challenging bug you found? -\item - What debugging method did you find most useful? -\end{itemize} diff --git a/book/module2/documentation.tex b/book/module2/documentation.tex deleted file mode 100644 index ebd9d87..0000000 --- a/book/module2/documentation.tex +++ /dev/null @@ -1,64 +0,0 @@ -\section{Documentation of your code}\label{documentation-of-your-code} - -Code documentation is essential for maintaining and scaling software -projects. Whether it's an open-source project or your own private code. -It ensures that you can understand, use, troubleshoot and build upon the -code in the future. - -\subsection{Keep Detailed and Accurate -Notes}\label{keep-detailed-and-accurate-notes} - -Just as a recipe requires clear instructions, your code should be -accompanied by comprehensive notes. Document your process thoroughly to -ensure that others (and future you) can follow along without confusion. - -When documenting a project, it's essential to include detailed notes -that capture not just what the code does, but how it was developed. This -includes recording libraries used, citing any external code snippets -along with their sources, and outlining the sequence of steps taken -throughout the coding process. Such comprehensive documentation enables -others---and your future self---to understand, recreate, and maintain -the project more effectively, reducing confusion and improving long-term -usability. - -\subsection{Explain Your Decisions}\label{explain-your-decisions} - -In programming, there are often several valid approaches to solving a -problem. When documenting your code, it's important to clarify why you -chose a particular method---especially if it deviates from common -practices. Anticipating potential questions and addressing them directly -in your documentation helps others follow your reasoning and builds -trust in your solution. \includegraphics{figures/rubberDuck.png} A -useful strategy for articulating these decisions is the ``rubber duck'' -technique---explaining your code as if you're teaching it to someone -else. Whether spoken aloud or written down, this practice helps you -clarify your logic and communicate the reasoning behind your choices, -providing valuable context for future collaborators or -reviewers.\hspace{0pt} - -\subsection{Include a README}\label{include-a-readme} - -A README file serves as the introduction to your project. It should be -placed in the top-level directory and provide essential -information.\hspace{0pt} A good readme file may include: - Project title -and description - Installation instructions - Usage examples - -Contribution guidelines (if applicable) - License information (if -applicable) - -This file acts as a roadmap for anyone interacting with your project. -\hspace{0pt} - -\subsection{In-line Comments}\label{in-line-comments} - -While external documentation is vital, in-code comments provide -immediate context. Use them to explain complex logic or important -sections within your code.\hspace{0pt}Here are some guidelines to -follow: Keep comments concise and relevant. Avoid stating the obvious; -focus on the ``why'' rather than the ``what.''. - -\subsection{Maintain and Update -Documentation}\label{maintain-and-update-documentation} - -Similarly to your code, the documentation should evolve alongside your -code. Regularly review and update it to reflect changes, ensuring -accuracy and relevance.\hspace{0pt} diff --git a/book/module2/error.tex b/book/module2/error.tex deleted file mode 100644 index d515c4a..0000000 --- a/book/module2/error.tex +++ /dev/null @@ -1,97 +0,0 @@ -\section{Errors in Numerical -Computations}\label{errors-in-numerical-computations} - -In any numerical method, \textbf{error} is inevitable. Understanding -\textbf{what kinds of errors occur} and \textbf{why} is essential to -building reliable and accurate computations. - -We mainly classify errors into two major types: - Truncation Error - -Round-off Error - -\subsection{What is Error?}\label{what-is-error} - -Let's remind ourselves what error is: \[ -\text{Error} = \text{True Value} - \text{Approximate Value} -\] However, often the \textbf{true value} is unknown, so we focus on -\textbf{reducing} and \textbf{analyzing} different types of errors -instead of eliminating them completely. This can be done by using -relative error when using iterative methods and is calculated as -follows: \[ -\text{Relative Error} = \frac{\text{Best} - \text{Second to best}}{Best} -\] - -\subsection{Truncation Error}\label{truncation-error} - -Truncation error occurs \textbf{when an infinite process is approximated -by a finite process}.\\ -In simple terms, it happens \textbf{when you cut off or ``truncate'' -part of the computation}. An example of this could be using a finite -number of terms from a Taylor Series expansion to approximate a -function. - -Approximating $e^x$ by the first few terms of its Taylor series: - -$e^x \approx 1 + x +\frac{x^2}{2!} + \frac{x^3}{3!}$ - -The error comes from \textbf{neglecting} all the higher order terms -($\frac{x^4}{4!}, \frac{x^5}{5!}$), \ldots). - -Truncation error occurs when using numerical methods such as -approximating and calculating derivatives and integrals. A -representation of the truncation error is show in the figure below. -Using our numerical methods we are left if some degree of error. - -\begin{figure} -\centering -\includegraphics{figures/truncationError.png} -\caption{Representation of truncation error under a curve} -\end{figure} - -In order to reduce truncation error there are a few things we can do: - -Include more terms (higher-order methods) - Decrease step sizes (e.g., -smaller \(\Delta x\) in approximations) - Use better approximation -algorithms. - -\subsection{Round-off Error}\label{round-off-error} - -Round-off error is caused by \textbf{the limited precision} with which -computers represent numbers. Since computers cannot store an infinite -number of digits, \textbf{they round off} after a certain number of -decimal or binary places. For example, instead of representing pi with -infinite decimal places it may be rounded off to approximately 16 digits -depending on number of bits and the representation of the bits. - -In other words, round-off error happens because of how computers store -numbers. For a double-floating point, the number is stored using -64-bits. The more bits we use, the more precise of a number we can -store. However, it makes it costs us more memory making it more -computational expensive. - -While individual round-off errors may seem negligible, their effects can -\textbf{accumulate over repeated computations}, leading to significant -inaccuracies. This is particularly problematic in operations such as -\textbf{subtracting two nearly equal numbers}, where \textbf{loss of -significance} can occur, severely reducing numerical precision and -amplifying the impact of round-off error. - -\subsubsection{How to Reduce Round-off -Error:}\label{how-to-reduce-round-off-error} - -To reduce round-off error, use higher-precision data types when storing -numerical values. Additionally, code and algorithms should be structured -to \textbf{avoid subtracting nearly equal numbers}, a common source of -significant error. Finally, employing \textbf{numerically stable -algorithms} is essential for minimizing the accumulation of round-off -errors during computation. - -\subsection{Total Error}\label{total-error} - -Truncation and round-off error are inversely proportional, meaning that -if we decrease one, the other increases. If we want to minimize total -error we must find the optimal point between step size and error. - -\begin{figure} -\centering -\includegraphics{figures/totalError.png} -\caption{Total Error} -\end{figure} diff --git a/book/module2/intro_to_numerical_methods.tex b/book/module2/intro_to_numerical_methods.tex deleted file mode 100644 index 737d69d..0000000 --- a/book/module2/intro_to_numerical_methods.tex +++ /dev/null @@ -1,41 +0,0 @@ -\section{Numerical Methods}\label{numerical-methods} - -Engineering - -\subsection{What is a numerical -method?}\label{what-is-a-numerical-method} - -Numerical methods are techniques that transform mathematical problems -into forms that can be solved using arithmetic and logical operations. -Because digital computers excel at these computations, numerical methods -are often referred to as computer mathematics. - -\subsection{Numerical Differentiation}\label{numerical-differentiation} - -Forwards difference Backwards difference - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter20.00-Numerical-Differentiation.html}{Read -More} - -\subsection{Roots and Optimization}\label{roots-and-optimization} - -Incremental Search Bisection Modified Secant Newton-Raphson - -\subsection{Numerical Integration}\label{numerical-integration} - -Trapezoidal - -Simpson's Rule - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter21.00-Numerical-Integration.html}{Read -More} - -\subsection{Numerical Solutions of Ordinary Differential -Equations}\label{numerical-solutions-of-ordinary-differential-equations} - -Euler's Method - Forward - Backwards - -Runge-Kutta Method - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter22.00-ODE-Initial-Value-Problems.html}{Read -More} diff --git a/book/module2/module2.tex b/book/module2/module2.tex deleted file mode 100644 index 14f37e0..0000000 --- a/book/module2/module2.tex +++ /dev/null @@ -1,8 +0,0 @@ -\chapter{Module 2: Algorithm Development} -\input{module2/problem_solving_strategies} -\input{module2/num_methods_1} -\input{module2/error} -\input{module2/ai_assisted_programming} -\input{module2/debugging_code} -\input{module2/version_control} -\input{module2/documentation} diff --git a/book/module2/num_methods_1.tex b/book/module2/num_methods_1.tex deleted file mode 100644 index 5550d12..0000000 --- a/book/module2/num_methods_1.tex +++ /dev/null @@ -1,129 +0,0 @@ -\section{Solving non-linear -equations}\label{solving-non-linear-equations} - -\subsection{Introduction}\label{introduction} - -\subsection{Prerequisites}\label{prerequisites} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy} -\ImportTok{import}\NormalTok{ scipy} -\ImportTok{import}\NormalTok{ sympy} -\end{Highlighting} -\end{Shaded} - -\subsection{fsolve from SciPy}\label{fsolve-from-scipy} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{from}\NormalTok{ scipy.optimize }\ImportTok{import}\NormalTok{ fsolve} - -\KeywordTok{def}\NormalTok{ equations(}\BuiltInTok{vars}\NormalTok{):} -\NormalTok{ x, y }\OperatorTok{=} \BuiltInTok{vars} -\NormalTok{ eq1 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ y}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}} \DecValTok{25} -\NormalTok{ eq2 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}}\NormalTok{ y} - \ControlFlowTok{return}\NormalTok{ [eq1, eq2]} - -\NormalTok{initial\_guess }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]} -\NormalTok{solution }\OperatorTok{=}\NormalTok{ fsolve(equations, initial\_guess)} -\BuiltInTok{print}\NormalTok{(}\StringTok{"Solution:"}\NormalTok{, solution)} -\end{Highlighting} -\end{Shaded} - -\subsection{root from SciPy}\label{root-from-scipy} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{from}\NormalTok{ scipy.optimize }\ImportTok{import}\NormalTok{ root} - -\KeywordTok{def}\NormalTok{ equations(}\BuiltInTok{vars}\NormalTok{):} -\NormalTok{ x, y }\OperatorTok{=} \BuiltInTok{vars} -\NormalTok{ eq1 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ y}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}} \DecValTok{25} -\NormalTok{ eq2 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}}\NormalTok{ y} - \ControlFlowTok{return}\NormalTok{ [eq1, eq2]} - -\NormalTok{initial\_guess }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]} -\NormalTok{solution }\OperatorTok{=}\NormalTok{ root(equations, initial\_guess)} -\BuiltInTok{print}\NormalTok{(}\StringTok{"Solution:"}\NormalTok{, solution.x)} -\end{Highlighting} -\end{Shaded} - -\subsection{minimize from SciPy}\label{minimize-from-scipy} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{from}\NormalTok{ scipy.optimize }\ImportTok{import}\NormalTok{ minimize} - -\CommentTok{\# Define the equations} -\KeywordTok{def}\NormalTok{ equation1(x, y):} - \ControlFlowTok{return}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ y}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}} \DecValTok{25} - -\KeywordTok{def}\NormalTok{ equation2(x, y):} - \ControlFlowTok{return}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}}\NormalTok{ y} - -\CommentTok{\# Define the objective function for optimization} -\KeywordTok{def}\NormalTok{ objective(xy):} -\NormalTok{ x, y }\OperatorTok{=}\NormalTok{ xy} - \ControlFlowTok{return}\NormalTok{ equation1(x, y)}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ equation2(x, y)}\OperatorTok{**}\DecValTok{2} - -\CommentTok{\# Initial guess} -\NormalTok{initial\_guess }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]} - -\CommentTok{\# Perform optimization} -\NormalTok{result }\OperatorTok{=}\NormalTok{ minimize(objective, initial\_guess)} -\NormalTok{solution\_optimization }\OperatorTok{=}\NormalTok{ result.x} - -\BuiltInTok{print}\NormalTok{(}\StringTok{"Optimization Method Solution:"}\NormalTok{, solution\_optimization)} -\end{Highlighting} -\end{Shaded} - -\subsection{nsolve from SymPy}\label{nsolve-from-sympy} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{from}\NormalTok{ sympy }\ImportTok{import}\NormalTok{ symbols, Eq, nsolve} - -\CommentTok{\# Define the variables} -\NormalTok{x, y }\OperatorTok{=}\NormalTok{ symbols(}\StringTok{\textquotesingle{}x y\textquotesingle{}}\NormalTok{)} - -\CommentTok{\# Define the equations} -\NormalTok{eq1 }\OperatorTok{=}\NormalTok{ Eq(x}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ y}\OperatorTok{**}\DecValTok{2}\NormalTok{, }\DecValTok{25}\NormalTok{)} -\NormalTok{eq2 }\OperatorTok{=}\NormalTok{ Eq(x }\OperatorTok{{-}}\NormalTok{ y, }\DecValTok{0}\NormalTok{)} - -\CommentTok{\# Initial guess for the solution} -\NormalTok{initial\_guess }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]} - -\CommentTok{\# Use nsolve to find the solution} -\NormalTok{solution }\OperatorTok{=}\NormalTok{ nsolve([eq1, eq2], [x, y], initial\_guess)} -\BuiltInTok{print}\NormalTok{(}\StringTok{"Solution:"}\NormalTok{, solution)} -\end{Highlighting} -\end{Shaded} - -\subsection{newton\_method from NumPy}\label{newton_method-from-numpy} - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\KeywordTok{def}\NormalTok{ equations(}\BuiltInTok{vars}\NormalTok{):} -\NormalTok{ x, y }\OperatorTok{=} \BuiltInTok{vars} -\NormalTok{ eq1 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{+}\NormalTok{ y}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}} \DecValTok{25} -\NormalTok{ eq2 }\OperatorTok{=}\NormalTok{ x}\OperatorTok{**}\DecValTok{2} \OperatorTok{{-}}\NormalTok{ y} - \ControlFlowTok{return}\NormalTok{ np.array([eq1, eq2])} - -\KeywordTok{def}\NormalTok{ newton\_method(initial\_guess, tolerance}\OperatorTok{=}\FloatTok{1e{-}6}\NormalTok{, max\_iter}\OperatorTok{=}\DecValTok{100}\NormalTok{):} - \BuiltInTok{vars} \OperatorTok{=}\NormalTok{ np.array(initial\_guess, dtype}\OperatorTok{=}\BuiltInTok{float}\NormalTok{)} - \ControlFlowTok{for}\NormalTok{ \_ }\KeywordTok{in} \BuiltInTok{range}\NormalTok{(max\_iter):} -\NormalTok{ J }\OperatorTok{=}\NormalTok{ np.array([[}\DecValTok{2} \OperatorTok{*} \BuiltInTok{vars}\NormalTok{[}\DecValTok{0}\NormalTok{], }\DecValTok{2} \OperatorTok{*} \BuiltInTok{vars}\NormalTok{[}\DecValTok{1}\NormalTok{]], [}\DecValTok{2} \OperatorTok{*} \BuiltInTok{vars}\NormalTok{[}\DecValTok{0}\NormalTok{], }\OperatorTok{{-}}\DecValTok{1}\NormalTok{]])} -\NormalTok{ F }\OperatorTok{=}\NormalTok{ equations(}\BuiltInTok{vars}\NormalTok{)} -\NormalTok{ delta }\OperatorTok{=}\NormalTok{ np.linalg.solve(J, }\OperatorTok{{-}}\NormalTok{F)} - \BuiltInTok{vars} \OperatorTok{+=}\NormalTok{ delta} - \ControlFlowTok{if}\NormalTok{ np.linalg.norm(delta) }\OperatorTok{\textless{}}\NormalTok{ tolerance:} - \ControlFlowTok{return} \BuiltInTok{vars} - -\NormalTok{initial\_guess }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{1}\NormalTok{]} -\NormalTok{solution }\OperatorTok{=}\NormalTok{ newton\_method(initial\_guess)} -\BuiltInTok{print}\NormalTok{(}\StringTok{"Solution:"}\NormalTok{, solution)} -\end{Highlighting} -\end{Shaded} diff --git a/book/module2/problem_solving_strategies.tex b/book/module2/problem_solving_strategies.tex deleted file mode 100644 index 2f7a360..0000000 --- a/book/module2/problem_solving_strategies.tex +++ /dev/null @@ -1,122 +0,0 @@ -\section{Algorithmic thinking}\label{algorithmic-thinking} - -In engineering, solving a problem begins long before we start coding or -building models. Like any other engineering challenge, computational -problems must first be clearly framed and understood. In this section, -you will learn to \textbf{apply algorithmic thinking} to systematically -approach engineering problems, \textbf{translate real-world situations -into structured programming logic}, and \textbf{use computational tools -to implement, test, and refine solutions}. - -Before diving into code, it's crucial to define the problem carefully, -frame the problem so that logically so that a computer can understand -then execute so that - -\subsection{Define the Problem}\label{define-the-problem} - -As any other engineering problem, we need to frame it before we can -start working on it. So before jumping straight into coding or building -models, clearly define the engineering problem. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - List your givens, this includes any constants or equations. What - inputs do we know? -\item - Find: List what you're trying to solve for. What outputs do we need to - find? -\item - Establish the assumptions based on your engineering knowledge that you - deem to be appropriate to use for the problem. This determines what - mathematical models we can apply to the problem (i.e.~equations or - formulas). -\item - Solution: Show the works of the problem, this will include any code - used together with documentation or any explanations of the code. -\item - Comment: reflect and comment on your findings. -\end{enumerate} - -\subsection{Think Algorithmically}\label{think-algorithmically} - -Since we are going to use computers to compute our calculate we first -need to break the problem into logical steps that a computer can follow. -This can be done with tools such as flowchart or psuedo-code. - -\begin{itemize} -\tightlist -\item - \textbf{Define the inputs and outputs.} What variables will the - program take in, and what results will it produce? -\item - \textbf{Break the problem into sub-tasks.} Identify steps such as data - input, logic processing and output. -\item - \textbf{Outline the algorithm.} Write pseudo-code or flowcharts that - describe the computational steps. -\item - \textbf{Identify patterns or formulas.} Can loops, conditionals, or - equations be used to automate parts of the solution? -\end{itemize} - -\subsubsection{Flowchart for fixing -lamp}\label{flowchart-for-fixing-lamp} - -\begin{figure} -\centering -\includegraphics{figures/LampFlowchart.png} -\caption{Lamp Flowchart} -\end{figure} - -\subsubsection{Psuedo-Code for processing and plotting stress-strain -data:}\label{psuedo-code-for-processing-and-plotting-stress-strain-data} - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - Import force and displacement data from file. -\item - Convert data from force and displacement to stress and strain. -\item - Plot the stress-strain curve. -\item - Identify the yield point or modulus. -\end{enumerate} - -\subsection{Write \& Execute the Code}\label{write-execute-the-code} - -When writing the code it is important to ask yourself whether you're -using the right tools, libraries or method to solve the problem. -\textbf{Check for any syntax and logic errors} then debug line-by-line -using print statements or by using a debugging tool. - -\subsection{Verify and Validate}\label{verify-and-validate} - -When writing code it is crucial to test and confirm your code. It is -therefore important to ask yourself the following questions. Does the -code do what you intended it to do? And, is the mathematical model used -in the code valid for the current problem? - -\subsection{Exercise: Design a derivative finding -algorithm}\label{exercise-design-a-derivative-finding-algorithm} - -Set up the problem and write pseudo-code to calculate the gradient of an -unknown function. - -\begin{enumerate} -\def\labelenumi{\arabic{enumi}.} -\tightlist -\item - \textbf{Given:} -\item - **Find: -\item - \textbf{Assumptions:} -\item - \textbf{Solution:} -\item - \textbf{Comment:} -\end{enumerate} diff --git a/book/module2/version_control.tex b/book/module2/version_control.tex deleted file mode 100644 index 1c327c6..0000000 --- a/book/module2/version_control.tex +++ /dev/null @@ -1,163 +0,0 @@ -\section{Version Control Software}\label{version-control-software} - -\subsection{What is Version Control}\label{what-is-version-control} - -Version control is a system that tracks changes to files, enabling -developers to collaborate, manage code history, and revert to previous -versions when needed. The most used version control software (VCS) is -git. In this course git is the VCS we will be using. - -In the open-source community VCS is the - Tracks changes and history. - -Enables collaboration among developers. - Reduces errors by managing -code versions. - Supports branching and merging for parallel -development. - -In this section is divided up into two major sections. The first section -\emph{Git} will cover the basics of how to create backups of your -project. The second section will cover how to use git with GitHub to -\emph{collaborate} on projects. - -\subsection{Git}\label{git} - -Git is a version control program that tracks changes to files and -directories using snapshots. It is a distributed version control system, -meaning that each developer has a complete copy of the repository on -their local computer. Git is the most widely used version control system -and is popular among developers for its speed, flexibility, and -efficiency. - -\subsubsection{The Three States}\label{the-three-states} - -Pay attention now --- here is the main thing to remember about Git if -you want the rest of your learning process to go smoothly. Git has three -main states that your files can reside in: modified, staged, and -committed: - -\begin{itemize} -\tightlist -\item - \textbf{Modified} means that you have changed the file but have not - committed it to your database yet. -\item - \textbf{Staged} means that you have marked a modified file in its - current version to go into your next commit snapshot. -\item - \textbf{Committed} means that the data is safely stored in your local - database. -\end{itemize} - -This leads us to the three main sections of a Git project: the working -tree, the staging area, and the Git directory. - -\includegraphics{figures/git_areas.png} \#\#\# Branching In git, -branches allow for parallel workflow on a project. It give contributors -the ability to work different features at the same time. Each branch -represents an independent line of development, and once a feature or fix -is complete, it can be merged back into the main branch. Here is a -common branching structure used in many Git projects: - Main Branch - -The main branch (a.k.a. master branch) is the default branch in a Git -repository and contains the stable version of the code. - Development -Branch - is created to develop a new feature or fix a bug without -affecting the main branch. It isn't necessarily always stable, but -whenever it gets to a stable state, it can be merged into master. - -Topic Branch - A topic branch is a short-lived branch that you create -and use for a single particular feature or related work. -\includegraphics{figures/git_silo_branching.png} \#\#\# Best Practices - -Use descriptive commit messages. - Commit early and often. - Keep -commits focused on a single change. - Use feature branches for new -features or bug fixes. - Review and test changes before merging. - -Resolve conflicts promptly. - Keep the commit history clean and -organized. - -\subsubsection{Basic Commands}\label{basic-commands} - -Here is a list of some git commands to get you started. \#\#\#\# -Starting your repository - \texttt{git\ init} - Initialize a new Git -repository. - \texttt{git\ clone} - Clone an existing repository. -\#\#\#\# Committing - \texttt{git\ status} - Check the status of the -repository. - \texttt{git\ add} - Add files to the staging area. - -\texttt{git\ commit} - Commit changes to the repository. \#\#\#\# -Branching - \texttt{git\ branch} - List, create, or delete branches. - -\texttt{git\ checkout} - Switch between branches. \#\#\#\# -History/Inspection - \texttt{git\ log} - View the commit history. -\#\#\#\# Collaborative - \texttt{git\ fetch} - Fetches updates from a -remote but does not merge. - \texttt{git\ merge} - Merge changes from a -named commit to the current branch. - \texttt{git\ pull} - Fetch and -merge changes from a remote repository. - \texttt{git\ push} - Push -changes to a remote repository. - -\subsubsection{More on git}\label{more-on-git} - -Interested in learning more about git? Here's a free book that teaches -you everything about git and how to use it at a professional level. -Available as both HTML and PDF download: -\href{https://git-scm.com/book/en/v2}{Git Pro}. - -\subsection{GitHub - The collaborative -platform}\label{github---the-collaborative-platform} - -GitHub is a web-based platform that hosts Git repositories and provides -collaboration tools for developers. It allows developers to share code, -track issues, and collaborate on projects with other developers. GitHub -is widely used for open-source projects, team collaboration, and code -hosting. \#\#\# GitHub Features - Remote Repository Hosting - GitHub -allows you to host projects and code remotely on their servers. - Issues -- Issues are used to track bugs, feature - Pull Requests - Internal -request system for contributors to request code to be pulled. \#\#\# -Workflow Depending on the size of the project and whether the project is -closed- or open-source, the workflow of the project will differ. In this -section we cover some git workflow models and the model you're going to -be using for this course. - -\textbf{Centralized}: The project has only one central hub or -\emph{repository}, can accept code and everybody synchronizes their work -with it. This model is suitable for small and closed-sourced projects. -\includegraphics{figures/git_workflow_centralized.png} - -\textbf{Integration-Manager:} There are multiple public variants of the -code original code known as \emph{forks}. The integration manager can -decide what features to pull from the forks. This is the model that is -similar to the one used on GitHub -\includegraphics{figures/git_workflow_int_manager.png} - -\textbf{Dictator and Lieutenants Workflow:} This is similar to the -integration-manager model, however due to the size of the project. A -rank of integration managers is formed. one example of this is the -development of the Linux kernel. -\includegraphics{figures/git_workflow_dictator.png} - -GitHub is designed around a particular collaboration workflow, centered -on Pull Requests. This flow works whether you're collaborating with a -tightly-knit team in a single shared repository, or a -globally-distributed company or network of strangers contributing to a -project through dozens of forks. It is centered on the Topic Branches -workflow covered in Git Branching. - -Here's how it generally works: 1. Fork the project. 2. Create a topic -branch from master. 3. Make some commits to improve the project. 4. Push -this branch to your GitHub project. 5. Open a Pull Request on GitHub. 6. -Discuss, and optionally continue committing. 7. The project owner merges -or closes the Pull Request. 8. Sync the updated master back to your -fork. - -\subsubsection{Terms}\label{terms} - -\begin{itemize} -\tightlist -\item - Pull Request - A \emph{pull request} is a request to merge changes - from a feature branch into the main branch or from a forked repository - to the original or ``upstream'' repository. -\item - Merge - A \emph{merge} combines the changes from one branch into - another branch. -\item - Conflict - A \emph{conflict} occurs when Git cannot automatically - merge changes and requires manual intervention. -\end{itemize} - -\subsubsection{Code resource - Using GitHub to re-use existing -code.}\label{code-resource---using-github-to-re-use-existing-code.} - -In your engineering career, you will most likely use a computation -method that has been come up with before. In such scenarios, open-source diff --git a/book/module3/module3.tex b/book/module3/module3.tex deleted file mode 100644 index 3c59ddd..0000000 --- a/book/module3/module3.tex +++ /dev/null @@ -1,4 +0,0 @@ -\chapter{Module 3: Applications of Computational Mathematics} -\input{module3/numerical_methods} -\input{module3/supersonic} -\input{module3/system_of_equations} diff --git a/book/module3/numerical_methods.tex b/book/module3/numerical_methods.tex deleted file mode 100644 index 737d69d..0000000 --- a/book/module3/numerical_methods.tex +++ /dev/null @@ -1,41 +0,0 @@ -\section{Numerical Methods}\label{numerical-methods} - -Engineering - -\subsection{What is a numerical -method?}\label{what-is-a-numerical-method} - -Numerical methods are techniques that transform mathematical problems -into forms that can be solved using arithmetic and logical operations. -Because digital computers excel at these computations, numerical methods -are often referred to as computer mathematics. - -\subsection{Numerical Differentiation}\label{numerical-differentiation} - -Forwards difference Backwards difference - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter20.00-Numerical-Differentiation.html}{Read -More} - -\subsection{Roots and Optimization}\label{roots-and-optimization} - -Incremental Search Bisection Modified Secant Newton-Raphson - -\subsection{Numerical Integration}\label{numerical-integration} - -Trapezoidal - -Simpson's Rule - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter21.00-Numerical-Integration.html}{Read -More} - -\subsection{Numerical Solutions of Ordinary Differential -Equations}\label{numerical-solutions-of-ordinary-differential-equations} - -Euler's Method - Forward - Backwards - -Runge-Kutta Method - -\href{https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter22.00-ODE-Initial-Value-Problems.html}{Read -More} diff --git a/book/module3/supersonic.tex b/book/module3/supersonic.tex deleted file mode 100644 index d8dfc4a..0000000 --- a/book/module3/supersonic.tex +++ /dev/null @@ -1 +0,0 @@ -\section{Supersonic}\label{supersonic} diff --git a/book/module3/system_of_equations.tex b/book/module3/system_of_equations.tex deleted file mode 100644 index 89fa2ae..0000000 --- a/book/module3/system_of_equations.tex +++ /dev/null @@ -1 +0,0 @@ -\section{System of Equations}\label{system-of-equations} diff --git a/book/module4/linear_regression.tex b/book/module4/linear_regression.tex deleted file mode 100644 index 5cd81db..0000000 --- a/book/module4/linear_regression.tex +++ /dev/null @@ -1,22 +0,0 @@ -\section{Linear Regression}\label{linear-regression} - -\subsection{Statical tools}\label{statical-tools} - -Numpy comes with some useful statistical tools that we can use to -analyze our data. - -\subsubsection{Mean}\label{mean} - -The mean is the average of a set of numbers. It is calculated by summing -all the numbers and dividing by the count of numbers. - -\begin{Shaded} -\begin{Highlighting}[] -\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} - -\NormalTok{mean }\OperatorTok{=}\NormalTok{ np.mean([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\NormalTok{median }\OperatorTok{=}\NormalTok{ np.median([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\NormalTok{std }\OperatorTok{=}\NormalTok{ np.std([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\NormalTok{variance }\OperatorTok{=}\NormalTok{ np.var([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} -\end{Highlighting} -\end{Shaded} diff --git a/book/module4/module4.tex b/book/module4/module4.tex deleted file mode 100644 index 48e3475..0000000 --- a/book/module4/module4.tex +++ /dev/null @@ -1,3 +0,0 @@ -\chapter{Module 4: Data Analysis and Visualization} -\input{module4/linear_regression} -\input{module4/plotting} diff --git a/book/module4/plotting.tex b/book/module4/plotting.tex deleted file mode 100644 index f2130e4..0000000 --- a/book/module4/plotting.tex +++ /dev/null @@ -1,3 +0,0 @@ -\section{Plotting}\label{plotting} - -\subsection{matlibplot}\label{matlibplot} diff --git a/book/module5/module5.tex b/book/module5/module5.tex deleted file mode 100644 index c274e38..0000000 --- a/book/module5/module5.tex +++ /dev/null @@ -1 +0,0 @@ -\chapter{Module 5: Introduction to AI for Engineering Problems} diff --git a/book/preamble.inc b/book/preamble.inc deleted file mode 100644 index 096a0e2..0000000 --- a/book/preamble.inc +++ /dev/null @@ -1,404 +0,0 @@ -\documentclass[oneside]{scrbook} - - \usepackage[breakable]{tcolorbox} - \usepackage{parskip} % Stop auto-indenting (to mimic markdown behaviour) - \setcounter{tocdepth}{1} - - % Basic figure setup, for now with no caption control since it's done - % automatically by Pandoc (which extracts  syntax from Markdown). - \usepackage{graphicx} - % Keep aspect ratio if custom image width or height is specified - \setkeys{Gin}{keepaspectratio} - % Maintain compatibility with old templates. Remove in nbconvert 6.0 - \let\Oldincludegraphics\includegraphics - % Ensure that by default, figures have no caption (until we provide a - % proper Figure object with a Caption API and a way to capture that - % in the conversion process - todo). - \usepackage{caption} - \DeclareCaptionFormat{nocaption}{} - \captionsetup{format=nocaption,aboveskip=0pt,belowskip=0pt} - - \usepackage{float} - \floatplacement{figure}{H} % forces figures to be placed at the correct location - \usepackage{xcolor} % Allow colors to be defined - \usepackage{enumerate} % Needed for markdown enumerations to work - \usepackage{geometry} % Used to adjust the document margins - \usepackage{amsmath} % Equations - \usepackage{amssymb} % Equations - \usepackage{textcomp} % defines textquotesingle - % Hack from http://tex.stackexchange.com/a/47451/13684: - \AtBeginDocument{% - \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code - } - \usepackage{upquote} % Upright quotes for verbatim code - \usepackage{eurosym} % defines \euro - - \usepackage{iftex} - \ifPDFTeX - \usepackage[T1]{fontenc} - \IfFileExists{alphabeta.sty}{ - \usepackage{alphabeta} - }{ - \usepackage[mathletters]{ucs} - \usepackage[utf8]{inputenc} - } - \else - \usepackage{fontspec} - \usepackage{unicode-math} - \fi - - \usepackage{fancyvrb} % verbatim replacement that allows latex - \usepackage{grffile} % extends the file name processing of package graphics - % to support a larger range - \makeatletter % fix for old versions of grffile with XeLaTeX - \@ifpackagelater{grffile}{2019/11/01} - { - % Do nothing on new versions - } - { - \def\Gread@@xetex#1{% - \IfFileExists{"\Gin@base".bb}% - {\Gread@eps{\Gin@base.bb}}% - {\Gread@@xetex@aux#1}% - } - } - \makeatother - \usepackage[Export]{adjustbox} % Used to constrain images to a maximum size - \adjustboxset{max size={0.9\linewidth}{0.9\paperheight}} - - % The hyperref package gives us a pdf with properly built - % internal navigation ('pdf bookmarks' for the table of contents, - % internal cross-reference links, web links for URLs, etc.) - \usepackage{hyperref} - % The default LaTeX title has an obnoxious amount of whitespace. By default, - % titling removes some of it. It also provides customization options. - \usepackage{titling} - \usepackage{longtable} % longtable support required by pandoc >1.10 - \usepackage{booktabs} % table support for pandoc > 1.12.2 - \usepackage{array} % table support for pandoc >= 2.11.3 - \usepackage{calc} % table minipage width calculation for pandoc >= 2.11.1 - \usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) - \usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) - % normalem makes italics be italics, not underlines - \usepackage{soul} % strikethrough (\st) support for pandoc >= 3.0.0 - \usepackage{mathrsfs} - - - - % Colors for the hyperref package - \definecolor{urlcolor}{rgb}{0,.145,.698} - \definecolor{linkcolor}{rgb}{.71,0.21,0.01} - \definecolor{citecolor}{rgb}{.12,.54,.11} - - % ANSI colors - \definecolor{ansi-black}{HTML}{3E424D} - \definecolor{ansi-black-intense}{HTML}{282C36} - \definecolor{ansi-red}{HTML}{E75C58} - \definecolor{ansi-red-intense}{HTML}{B22B31} - \definecolor{ansi-green}{HTML}{00A250} - \definecolor{ansi-green-intense}{HTML}{007427} - \definecolor{ansi-yellow}{HTML}{DDB62B} - \definecolor{ansi-yellow-intense}{HTML}{B27D12} - \definecolor{ansi-blue}{HTML}{208FFB} - \definecolor{ansi-blue-intense}{HTML}{0065CA} - \definecolor{ansi-magenta}{HTML}{D160C4} - \definecolor{ansi-magenta-intense}{HTML}{A03196} - \definecolor{ansi-cyan}{HTML}{60C6C8} - \definecolor{ansi-cyan-intense}{HTML}{258F8F} - \definecolor{ansi-white}{HTML}{C5C1B4} - \definecolor{ansi-white-intense}{HTML}{A1A6B2} - \definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} - \definecolor{ansi-default-inverse-bg}{HTML}{000000} - - % common color for the border for error outputs. - \definecolor{outerrorbackground}{HTML}{FFDFDF} - - % commands and environments needed by pandoc snippets - % extracted from the output of `pandoc -s` - \providecommand{\tightlist}{% - \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} - \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} - % Add ',fontsize=\small' for more characters per line - \newenvironment{Shaded}{}{} - \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} - \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} - \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} - \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} - \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} - \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} - \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} - \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} - \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} - \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} - \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} - \newcommand{\RegionMarkerTok}[1]{{#1}} - \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} - \newcommand{\NormalTok}[1]{{#1}} - - % Additional commands for more recent versions of Pandoc - \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} - \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} - \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} - \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} - \newcommand{\ImportTok}[1]{{#1}} - \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} - \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} - \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} - \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} - \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} - \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} - \newcommand{\BuiltInTok}[1]{{#1}} - \newcommand{\ExtensionTok}[1]{{#1}} - \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} - \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} - \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} - \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} - \makeatletter - \newsavebox\pandoc@box - \newcommand*\pandocbounded[1]{% - \sbox\pandoc@box{#1}% - % scaling factors for width and height - \Gscale@div\@tempa\textheight{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% - \Gscale@div\@tempb\linewidth{\wd\pandoc@box}% - % select the smaller of both - \ifdim\@tempb\p@<\@tempa\p@ - \let\@tempa\@tempb - \fi - % scaling accordingly (\@tempa < 1) - \ifdim\@tempa\p@<\p@ - \scalebox{\@tempa}{\usebox\pandoc@box}% - % scaling not needed, use as it is - \else - \usebox{\pandoc@box}% - \fi - } - \makeatother - - % Define a nice break command that doesn't care if a line doesn't already - % exist. - \def\br{\hspace*{\fill} \\* } - % Math Jax compatibility definitions - \def\gt{>} - \def\lt{<} - \let\Oldtex\TeX - \let\Oldlatex\LaTeX - \renewcommand{\TeX}{\textrm{\Oldtex}} - \renewcommand{\LaTeX}{\textrm{\Oldlatex}} - % Document parameters - % Document title - \title{arrays} - - - - - - - -% Pygments definitions -\makeatletter -\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% - \let\PY@ul=\relax \let\PY@tc=\relax% - \let\PY@bc=\relax \let\PY@ff=\relax} -\def\PY@tok#1{\csname PY@tok@#1\endcsname} -\def\PY@toks#1+{\ifx\relax#1\empty\else% - \PY@tok{#1}\expandafter\PY@toks\fi} -\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% - \PY@it{\PY@bf{\PY@ff{#1}}}}}}} -\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} - -\@namedef{PY@tok@w}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} -\@namedef{PY@tok@c}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} -\@namedef{PY@tok@cp}{\def\PY@tc##1{\textcolor[rgb]{0.61,0.40,0.00}{##1}}} -\@namedef{PY@tok@k}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@kp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@kt}{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} -\@namedef{PY@tok@o}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@ow}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} -\@namedef{PY@tok@nb}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@nf}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} -\@namedef{PY@tok@nc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} -\@namedef{PY@tok@nn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} -\@namedef{PY@tok@ne}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.80,0.25,0.22}{##1}}} -\@namedef{PY@tok@nv}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@no}{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} -\@namedef{PY@tok@nl}{\def\PY@tc##1{\textcolor[rgb]{0.46,0.46,0.00}{##1}}} -\@namedef{PY@tok@ni}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} -\@namedef{PY@tok@na}{\def\PY@tc##1{\textcolor[rgb]{0.41,0.47,0.13}{##1}}} -\@namedef{PY@tok@nt}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@nd}{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} -\@namedef{PY@tok@s}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@sd}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@si}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} -\@namedef{PY@tok@se}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.36,0.12}{##1}}} -\@namedef{PY@tok@sr}{\def\PY@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} -\@namedef{PY@tok@ss}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@sx}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@m}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@gh}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} -\@namedef{PY@tok@gu}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} -\@namedef{PY@tok@gd}{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} -\@namedef{PY@tok@gi}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.52,0.00}{##1}}} -\@namedef{PY@tok@gr}{\def\PY@tc##1{\textcolor[rgb]{0.89,0.00,0.00}{##1}}} -\@namedef{PY@tok@ge}{\let\PY@it=\textit} -\@namedef{PY@tok@gs}{\let\PY@bf=\textbf} -\@namedef{PY@tok@gp}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} -\@namedef{PY@tok@go}{\def\PY@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} -\@namedef{PY@tok@gt}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} -\@namedef{PY@tok@err}{\def\PY@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} -\@namedef{PY@tok@kc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@kd}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@kn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@kr}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@bp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} -\@namedef{PY@tok@fm}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} -\@namedef{PY@tok@vc}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@vg}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@vi}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@vm}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} -\@namedef{PY@tok@sa}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@sb}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@sc}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@dl}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@s2}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@sh}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@s1}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} -\@namedef{PY@tok@mb}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@mf}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@mh}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@mi}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@il}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@mo}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} -\@namedef{PY@tok@ch}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} -\@namedef{PY@tok@cm}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} -\@namedef{PY@tok@cpf}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} -\@namedef{PY@tok@c1}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} -\@namedef{PY@tok@cs}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} - -\def\PYZbs{\char`\\} -\def\PYZus{\char`\_} -\def\PYZob{\char`\{} -\def\PYZcb{\char`\}} -\def\PYZca{\char`\^} -\def\PYZam{\char`\&} -\def\PYZlt{\char`\<} -\def\PYZgt{\char`\>} -\def\PYZsh{\char`\#} -\def\PYZpc{\char`\%} -\def\PYZdl{\char`\$} -\def\PYZhy{\char`\-} -\def\PYZsq{\char`\'} -\def\PYZdq{\char`\"} -\def\PYZti{\char`\~} -% for compatibility with earlier versions -\def\PYZat{@} -\def\PYZlb{[} -\def\PYZrb{]} -\makeatother - - - % For linebreaks inside Verbatim environment from package fancyvrb. - \makeatletter - \newbox\Wrappedcontinuationbox - \newbox\Wrappedvisiblespacebox - \newcommand*\Wrappedvisiblespace {\textcolor{red}{\textvisiblespace}} - \newcommand*\Wrappedcontinuationsymbol {\textcolor{red}{\llap{\tiny$\m@th\hookrightarrow$}}} - \newcommand*\Wrappedcontinuationindent {3ex } - \newcommand*\Wrappedafterbreak {\kern\Wrappedcontinuationindent\copy\Wrappedcontinuationbox} - % Take advantage of the already applied Pygments mark-up to insert - % potential linebreaks for TeX processing. - % {, <, #, %, $, ' and ": go to next line. - % _, }, ^, &, >, - and ~: stay at end of broken line. - % Use of \textquotesingle for straight quote. - \newcommand*\Wrappedbreaksatspecials {% - \def\PYGZus{\discretionary{\char`\_}{\Wrappedafterbreak}{\char`\_}}% - \def\PYGZob{\discretionary{}{\Wrappedafterbreak\char`\{}{\char`\{}}% - \def\PYGZcb{\discretionary{\char`\}}{\Wrappedafterbreak}{\char`\}}}% - \def\PYGZca{\discretionary{\char`\^}{\Wrappedafterbreak}{\char`\^}}% - \def\PYGZam{\discretionary{\char`\&}{\Wrappedafterbreak}{\char`\&}}% - \def\PYGZlt{\discretionary{}{\Wrappedafterbreak\char`\<}{\char`\<}}% - \def\PYGZgt{\discretionary{\char`\>}{\Wrappedafterbreak}{\char`\>}}% - \def\PYGZsh{\discretionary{}{\Wrappedafterbreak\char`\#}{\char`\#}}% - \def\PYGZpc{\discretionary{}{\Wrappedafterbreak\char`\%}{\char`\%}}% - \def\PYGZdl{\discretionary{}{\Wrappedafterbreak\char`\$}{\char`\$}}% - \def\PYGZhy{\discretionary{\char`\-}{\Wrappedafterbreak}{\char`\-}}% - \def\PYGZsq{\discretionary{}{\Wrappedafterbreak\textquotesingle}{\textquotesingle}}% - \def\PYGZdq{\discretionary{}{\Wrappedafterbreak\char`\"}{\char`\"}}% - \def\PYGZti{\discretionary{\char`\~}{\Wrappedafterbreak}{\char`\~}}% - } - % Some characters . , ; ? ! / are not pygmentized. - % This macro makes them "active" and they will insert potential linebreaks - \newcommand*\Wrappedbreaksatpunct {% - \lccode`\~`\.\lowercase{\def~}{\discretionary{\hbox{\char`\.}}{\Wrappedafterbreak}{\hbox{\char`\.}}}% - \lccode`\~`\,\lowercase{\def~}{\discretionary{\hbox{\char`\,}}{\Wrappedafterbreak}{\hbox{\char`\,}}}% - \lccode`\~`\;\lowercase{\def~}{\discretionary{\hbox{\char`\;}}{\Wrappedafterbreak}{\hbox{\char`\;}}}% - \lccode`\~`\:\lowercase{\def~}{\discretionary{\hbox{\char`\:}}{\Wrappedafterbreak}{\hbox{\char`\:}}}% - \lccode`\~`\?\lowercase{\def~}{\discretionary{\hbox{\char`\?}}{\Wrappedafterbreak}{\hbox{\char`\?}}}% - \lccode`\~`\!\lowercase{\def~}{\discretionary{\hbox{\char`\!}}{\Wrappedafterbreak}{\hbox{\char`\!}}}% - \lccode`\~`\/\lowercase{\def~}{\discretionary{\hbox{\char`\/}}{\Wrappedafterbreak}{\hbox{\char`\/}}}% - \catcode`\.\active - \catcode`\,\active - \catcode`\;\active - \catcode`\:\active - \catcode`\?\active - \catcode`\!\active - \catcode`\/\active - \lccode`\~`\~ - } - \makeatother - - \let\OriginalVerbatim=\Verbatim - \makeatletter - \renewcommand{\Verbatim}[1][1]{% - %\parskip\z@skip - \sbox\Wrappedcontinuationbox {\Wrappedcontinuationsymbol}% - \sbox\Wrappedvisiblespacebox {\FV@SetupFont\Wrappedvisiblespace}% - \def\FancyVerbFormatLine ##1{\hsize\linewidth - \vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@ - \doublehyphendemerits\z@\finalhyphendemerits\z@ - \strut ##1\strut}% - }% - % If the linebreak is at a space, the latter will be displayed as visible - % space at end of first line, and a continuation symbol starts next line. - % Stretch/shrink are however usually zero for typewriter font. - \def\FV@Space {% - \nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font - \discretionary{\copy\Wrappedvisiblespacebox}{\Wrappedafterbreak} - {\kern\fontdimen2\font}% - }% - - % Allow breaks at special characters using \PYG... macros. - \Wrappedbreaksatspecials - % Breaks at punctuation characters . , ; ? ! and / need catcode=\active - \OriginalVerbatim[#1,codes*=\Wrappedbreaksatpunct]% - } - \makeatother - - % Exact colors from NB - \definecolor{incolor}{HTML}{303F9F} - \definecolor{outcolor}{HTML}{D84315} - \definecolor{cellborder}{HTML}{CFCFCF} - \definecolor{cellbackground}{HTML}{F7F7F7} - - % prompt - \makeatletter - \newcommand{\boxspacing}{\kern\kvtcb@left@rule\kern\kvtcb@boxsep} - \makeatother - \newcommand{\prompt}[4]{ - {\ttfamily\llap{{\color{#2}[#3]:\hspace{3pt}#4}}\vspace{-\baselineskip}} - } - - - - % Prevent overflowing lines due to hard-to-break entities - \sloppy - % Setup hyperref package - \hypersetup{ - breaklinks=true, % so long urls are correctly broken across lines - colorlinks=true, - urlcolor=urlcolor, - linkcolor=linkcolor, - citecolor=citecolor, - } - % Slightly bigger margins than the latex defaults - - \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} |
