\section{Exercises}
\begin{footnotesize} 
\subsection*{Targeted exercises} 
\subsubsection*{Exercises for Section \ref{Simulating_the_kinetics_of_one_elementary_reaction_using_scipy.solve_ivp}} 
\begin{enumerate}\setcounter{enumi}{-1}
	\item  Working from the code presented in Section \ref{Simulating_the_kinetics_of_one_elementary_reaction_using_scipy.solve_ivp}, write a script that plots the maximum error in the simulation versus the relative tolerance specification within \lstinline{scipy.solve_ivp()}. You can use the \lstinline{rtol} keyword to set this. Use a range of \lstinline{rtol} values that span $10^{-1}$ to $10^{-9}$ changing by factors of 10. 

	\item   Working from the code presented in Section \ref{Simulating_the_kinetics_of_one_elementary_reaction_using_scipy.solve_ivp}, use every option for the \lstinline{method} keyword argument of \lstinline{scipy.solve_ivp()} and compare the maximum error obtained. Try making a bar chart to compare these values, using Plotly.  You can read the documentation in Chapter \ref{ch:plotly} for this, or use the \lstinline{quickBar()} function out of codechembook.

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Simulating_multi-step_reaction_mechanisms_using_scipy.solve_ivp}} 
\begin{enumerate}\setcounter{enumi}{1}
	\item  Using the code presented Section \ref{Simulating_multi-step_reaction_mechanisms_using_scipy.solve_ivp}. Adjust the reaction \textit{rates} so that:

	\begin{enumerate}
	\item $[C]$ never levels off
	\item Three of the traces appear to meet at a single point
    \end{enumerate}
    
\item  Using the code presented in Section \ref{Simulating_multi-step_reaction_mechanisms_using_scipy.solve_ivp}, adjust the initial \textit{concentrations} so that:

\begin{enumerate}
	\item There is only a single maximum for $[X]$
	\item The bound catalyst is above a concentration of 0.5M for most of the time.
    \end{enumerate}
    
\item  Change the code in Section \ref{Simulating_multi-step_reaction_mechanisms_using_scipy.solve_ivp} so that the results are plotted versus $\ln(t)$. This makes it easier to focus on the early timepoints. 


\end{enumerate}
\subsection*{Comprehensive exercises} 
\begin{enumerate}\setcounter{enumi}{4}
	\item  It is often difficult to work second order processes, like:

	\begin{align*}
    A + B \rightarrow  C
    \end{align*}
	
        Because the reaction progress depends strongly on both $[A]$ and $[B]$ (one of which may be hard to measure). Instead, you can work in excess $[A]$ or $[B]$ and make the ``pseudo-first order approximation'' to remove the explicit dependence of the differential rate law on its concentration. If, say, $A$ is in excess, then $[A]$ will not change much during the reaction, and can be approximated as a constant. Thus, we reduce:

	\begin{align*}
  \frac{d[A]}{dt} &= -k[A][B] \\
  \frac{d[B]}{dt} &= -k[A][B] \\
  \frac{d[C]}{dt} &= \phantom{-}k[A][B] \\
  \textrm{to:} \\
  \frac{d[A]}{dt} &= -\kappa[B] \\
  \frac{d[B]}{dt} &= -\kappa[B] \\
  \frac{d[C]}{dt} &= \phantom{-}\kappa[B] \\
  \text{where} \quad \kappa &= k[A]
\end{align*}

		
	It is a good idea to figure out how much excess you need for the pseudo-first order approximation to hold. While this could be done analytically, it is quick and still quite accurate to do numerically. To do this, we will run several trials with increasing excess of $A$ and track how the difference between the two solutions changes. To proceed: 
        \begin{itemize}
            \item Write scripts that model the second order and the pseudo-first order reactions.
	\item Convert these codes into functions that take as arguments the initial concentrations, rates, and reaction times and return the solution object from \lstinline{solve_ivp()}.
	\item Write another script that creates a list of initial concentrations of $A$, starting with $[A]_0 = [B]_0$ and increasing logarithmically to $[A]_0 = 100 \times [B]_0$, and then solves both reactions for the same conditions.
	\item For each condition, compute the sum of squared differences between the second order and pseudo-first order solutions for $[C](t)$. Note that because you are probably using an adaptive step size solver, the time points you get back by default will not be the same between the two reactions. Instead, you will need to use the \lstinline{tspan} keyword to specify common time points. A good idea would be to make sure you are specifying time points that are no farther apart than the smallest gap between times in any simulation.
	\item Plot the difference versus the ratio of concentrations for each time point. Identify the region of applicability for the pseudo-first order approximation.
    \end{itemize}


    
    \item  The iodine clock reaction is a classic chemistry demonstration. Look up a demonstration on YouTube if you’re not familiar. Accurately modeling it is complex, but a simplified model can be created using the Briggs-Rauscher reaction:

	\begin{align*}
  \ce{A + B ->[$k_1$] 2 B} \\
  \ce{B + C ->[$k_2$] 2 C} \\
  \ce{C ->[$k_3$] D}
    \end{align*}


	  Modify our ODE solving code to work on this system. Good starting points are initial concentrations $[A]_0 = 10$, $[B]_0 = 1$, $[C]_0 = 1$, $[D]_0 = 0$, $k_1 = 0.005$, $k_2 = 0.1$, $k_3 = 0.01$, and $t_{max} = 10000$. Change the initial concentrations and rates one at a time. Provide plots that show how all concentrations change with time, both for the full time range and one oscillation. Explain how this reaction works, particularly how it can oscillate even though all the reactions are forward only. Show the behavior at several limits in the rates and initial concentrations, particularly where the system no longer oscillates.
      
\end{enumerate}
\end{footnotesize} 
