From 397ba81d210dad7331626e4bbaccfca3b745576c Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 5 Nov 2025 10:13:24 -0700 Subject: Removed book/ from tracking --- book/module2/ai_assisted_programming.tex | 79 -------------- book/module2/debugging_code.tex | 144 ------------------------ book/module2/documentation.tex | 64 ----------- book/module2/error.tex | 97 ----------------- book/module2/intro_to_numerical_methods.tex | 41 ------- book/module2/module2.tex | 8 -- book/module2/num_methods_1.tex | 129 ---------------------- book/module2/problem_solving_strategies.tex | 122 --------------------- book/module2/version_control.tex | 163 ---------------------------- 9 files changed, 847 deletions(-) delete mode 100644 book/module2/ai_assisted_programming.tex delete mode 100644 book/module2/debugging_code.tex delete mode 100644 book/module2/documentation.tex delete mode 100644 book/module2/error.tex delete mode 100644 book/module2/intro_to_numerical_methods.tex delete mode 100644 book/module2/module2.tex delete mode 100644 book/module2/num_methods_1.tex delete mode 100644 book/module2/problem_solving_strategies.tex delete mode 100644 book/module2/version_control.tex (limited to 'book/module2') 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 -- cgit v1.2.3