From 4abc43cdcb7fba399d5377481dd88e54b2db8cb6 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Thu, 24 Apr 2025 15:31:56 -0600 Subject: Added tex file structure for each module --- book/module1/basics_of_python.tex | 5 - book/module1/classes_and_objects.tex | 74 ++++++++++ book/module1/computational_expense.tex | 1 + book/module1/computing_fundamentals.tex | 19 +++ book/module1/control_structures.tex | 206 +++++++++++++++++++++++++++ book/module1/functions.tex | 110 ++++++++++++++ book/module1/fundamentals_of_programming.tex | 25 ++++ book/module1/installing_anaconda.tex | 160 +++++++++++++++++++++ book/module1/intro_to_anaconda.tex | 193 +++++++++++++++++++++++++ book/module1/intro_to_programming.tex | 38 +++++ book/module1/module1.tex | 13 +- book/module1/open_source_software.tex | 104 ++++++++++++++ book/module1/spyder_getting_started.tex | 105 ++++++++++++++ 13 files changed, 1047 insertions(+), 6 deletions(-) create mode 100644 book/module1/classes_and_objects.tex create mode 100644 book/module1/computational_expense.tex create mode 100644 book/module1/computing_fundamentals.tex create mode 100644 book/module1/control_structures.tex create mode 100644 book/module1/functions.tex create mode 100644 book/module1/fundamentals_of_programming.tex create mode 100644 book/module1/installing_anaconda.tex create mode 100644 book/module1/intro_to_anaconda.tex create mode 100644 book/module1/intro_to_programming.tex create mode 100644 book/module1/open_source_software.tex create mode 100644 book/module1/spyder_getting_started.tex (limited to 'book/module1') diff --git a/book/module1/basics_of_python.tex b/book/module1/basics_of_python.tex index 64883e7..29f8cc4 100644 --- a/book/module1/basics_of_python.tex +++ b/book/module1/basics_of_python.tex @@ -1,8 +1,3 @@ - \maketitle - - - - \hypertarget{basics-of-python}{ \section{Basics of Python}\label{basics-of-python}} diff --git a/book/module1/classes_and_objects.tex b/book/module1/classes_and_objects.tex new file mode 100644 index 0000000..cb9f7ec --- /dev/null +++ b/book/module1/classes_and_objects.tex @@ -0,0 +1,74 @@ +\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} + +\begin{longtable}[]{@{} + >{\raggedleft\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.0556}}@{}} +\toprule\noalign{} +\begin{minipage}[b]{\linewidth}\raggedleft +\#\# 2. Core OOP Concepts - A. \textbf{Classes and Objects} - +Definitions - Syntax in Python - B. \textbf{Attributes and Methods} - +Instance variables - Functions inside classes - C. +\textbf{Encapsulation} - Public vs private variables - Using +\texttt{\_\_init\_\_} and \texttt{self} - D. \textbf{Inheritance} - +Parent and child classes - Reuse and extension of code - E. +\textbf{Polymorphism} \emph{(brief overview)} - Method overriding - +Flexibility in interfaces +\end{minipage} \\ +\midrule\noalign{} +\endhead +\bottomrule\noalign{} +\endlastfoot +\#\# 3. Python OOP Syntax and Examples - A. Define a simple class (e.g., +\texttt{Spring}) - B. Instantiate objects and use methods - C. Show +\texttt{\_\_init\_\_}, \texttt{\_\_str\_\_}, custom methods - D. Add a +derived class (e.g., \texttt{DampedSpring} inherits from +\texttt{Spring}) \\ +\end{longtable} + +\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} + +\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} + +\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 new file mode 100644 index 0000000..f315969 --- /dev/null +++ b/book/module1/computational_expense.tex @@ -0,0 +1 @@ +\section{Computational Expense}\label{computational-expense} diff --git a/book/module1/computing_fundamentals.tex b/book/module1/computing_fundamentals.tex new file mode 100644 index 0000000..af38b93 --- /dev/null +++ b/book/module1/computing_fundamentals.tex @@ -0,0 +1,19 @@ +\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 new file mode 100644 index 0000000..746b7a5 --- /dev/null +++ b/book/module1/control_structures.tex @@ -0,0 +1,206 @@ +\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} + +\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} + +\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} + +\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} + +\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 new file mode 100644 index 0000000..07da182 --- /dev/null +++ b/book/module1/functions.tex @@ -0,0 +1,110 @@ +\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 new file mode 100644 index 0000000..6a412d1 --- /dev/null +++ b/book/module1/fundamentals_of_programming.tex @@ -0,0 +1,25 @@ +\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 new file mode 100644 index 0000000..9b9bf1a --- /dev/null +++ b/book/module1/installing_anaconda.tex @@ -0,0 +1,160 @@ +\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. + +\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} + +\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 new file mode 100644 index 0000000..5e58908 --- /dev/null +++ b/book/module1/intro_to_anaconda.tex @@ -0,0 +1,193 @@ +\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. + +\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} + +\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{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-env-labeled.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{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-getting-started-create.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{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-pkg-list.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{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-tabs.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 new file mode 100644 index 0000000..c73dcf4 --- /dev/null +++ b/book/module1/intro_to_programming.tex @@ -0,0 +1,38 @@ +\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/module1.tex b/book/module1/module1.tex index cecf097..5f4f16b 100644 --- a/book/module1/module1.tex +++ b/book/module1/module1.tex @@ -1,3 +1,14 @@ \chapter{Module 1} -\input{module1/basics_of_python} \input{module1/arrays} +\input{module1/basics_of_python} +\input{module1/classes_and_objects} +\input{module1/computational_expense} +\input{module1/computing_fundamentals} +\input{module1/control_structures} +\input{module1/functions} +\input{module1/fundamentals_of_programming} +\input{module1/installing_anaconda} +\input{module1/intro_to_anaconda} +\input{module1/intro_to_programming} +\input{module1/open_source_software} +\input{module1/spyder_getting_started} diff --git a/book/module1/open_source_software.tex b/book/module1/open_source_software.tex new file mode 100644 index 0000000..96de292 --- /dev/null +++ b/book/module1/open_source_software.tex @@ -0,0 +1,104 @@ +\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 new file mode 100644 index 0000000..d1e20fe --- /dev/null +++ b/book/module1/spyder_getting_started.tex @@ -0,0 +1,105 @@ +\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{https://docs.spyder-ide.org/current/_images/mainwindow_default_1610.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{https://docs.spyder-ide.org/5/_images/editor-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{https://docs.spyder-ide.org/5/_images/console-standard.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 Preferences ‣ IPython console ‣ + Graphics ‣ 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{https://docs.spyder-ide.org/5/_images/variable-explorer-standard.png} +\caption{Variable Explorer} +\end{figure} -- cgit v1.2.3