 bondscell_results $2ca31dab-a7fb-4003-ab1b-64d821f7ed89queued¤logsrunning¦outputbody0.2mimetext/plainrootassigneelast_run_timestampAjJspersist_js_state·has_pluto_hook_features§cell_id$2ca31dab-a7fb-4003-ab1b-64d821f7ed89depends_on_disabled_cells§runtime,published_object_keysdepends_on_skipped_cells§errored$91c7dac4-e6cb-4cb8-92a7-3a61a67da47dqueued¤logsrunning¦outputbody0.8mimetext/plainrootassigneelast_run_timestampAj^ persist_js_state·has_pluto_hook_features§cell_id$91c7dac4-e6cb-4cb8-92a7-3a61a67da47ddepends_on_disabled_cells§runtime@9published_object_keysdepends_on_skipped_cells§errored$52b3d09c-0403-4d74-a4ed-0efd296b4447queued¤logsrunning¦outputbody٠<div class="markdown"><div class="admonition question"><p class="admonition-title">Question</p><p>Is the steady state stable or unstable? Why?</p>
</div>
</div>mimetext/htmlrootassigneelast_run_timestampAjnpersist_js_state·has_pluto_hook_features§cell_id$52b3d09c-0403-4d74-a4ed-0efd296b4447depends_on_disabled_cells§runtime z1published_object_keysdepends_on_skipped_cells§errored$8de396f8-1883-45fb-af70-33eb913fb5e1queued¤logsrunning¦outputbody]<bond def="G" unique_id="nwstcjmyfdqp"><input type='range' min='1' max='20' value='1'></bond>mimetext/htmlrootassigneelast_run_timestampAjBnHpersist_js_state·has_pluto_hook_features§cell_id$8de396f8-1883-45fb-af70-33eb913fb5e1depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$d22c5b6a-66e7-49a1-8efa-47995a81df0bqueued¤logsrunning¦outputbody3mimetext/plainrootassigneelast_run_timestampAj/s.persist_js_state·has_pluto_hook_features§cell_id$d22c5b6a-66e7-49a1-8efa-47995a81df0bdepends_on_disabled_cells§runtime$ӵpublished_object_keysdepends_on_skipped_cells§errored$8022011a-7c65-479c-a879-f3d5472299f0queued¤logsrunning¦outputbody]<bond def="U" unique_id="vgwfdwhcoxor"><input type='range' min='1' max='20' value='3'></bond>mimetext/htmlrootassigneelast_run_timestampAjIpersist_js_state·has_pluto_hook_features§cell_id$8022011a-7c65-479c-a879-f3d5472299f0depends_on_disabled_cells§runtime Ppublished_object_keysdepends_on_skipped_cells§errored$01bdab11-249e-48e5-b49d-482d2bb36c0aqueued¤logsrunning¦outputbody$rhs (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAjUpersist_js_state·has_pluto_hook_features§cell_id$01bdab11-249e-48e5-b49d-482d2bb36c0adepends_on_disabled_cells§runtime 6published_object_keysdepends_on_skipped_cells§errored$4389a709-c98b-4012-9642-c8f5fc2b24f4queued¤logsrunning¦outputbody]<bond def="K" unique_id="yhilaxzcypjt"><input type='range' min='1' max='10' value='3'></bond>mimetext/htmlrootassigneelast_run_timestampAj3persist_js_state·has_pluto_hook_features§cell_id$4389a709-c98b-4012-9642-c8f5fc2b24f4depends_on_disabled_cells§runtime'ϵpublished_object_keysdepends_on_skipped_cells§errored$613b487b-e836-44fa-80eb-72c3191b4c3cqueued¤logsrunning¦outputbody<div class="markdown"><h2 id="RHS-function-\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;3&#93;&#125;&#125;">RHS function <span class="tex">$\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;3&#93;&#125;&#125;$</span></h2>
<p>Write a function <code>rhs&#40;y::Vector&#123;Number&#125;&#41;</code> that takes in the vector <span class="tex">$\boldsymbol&#123;y&#125;$</span> and returns the right-hand side of the two differential equations provided above, collected into a vector. Your function should use the values from the sliders above, i.e. <code>K</code>, <code>G</code>, <code>H</code>, <code>U</code>, and <code>T_inf</code>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAj&persist_js_state·has_pluto_hook_features§cell_id$613b487b-e836-44fa-80eb-72c3191b4c3cdepends_on_disabled_cells§runtime {published_object_keysdepends_on_skipped_cells§errored$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Numerical-stability-of-the-steady-state-\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;4&#93;&#125;&#125;">Numerical stability of the steady state <span class="tex">$\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;4&#93;&#125;&#125;$</span></h2>
<p>Now that we have determined the steady state solution, let us investigate the stability numerically. Call the <code>jacobian</code> function defined above, using either your fixed-point or Newton–Raphson solution.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129depends_on_disabled_cells§runtime "kpublished_object_keysdepends_on_skipped_cells§errored$5811cf9b-25ef-4851-9d51-8c7ec233cd03queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAj}persist_js_state·has_pluto_hook_features§cell_id$5811cf9b-25ef-4851-9d51-8c7ec233cd03depends_on_disabled_cells§runtime&published_object_keysdepends_on_skipped_cells§errored$fe4172e4-7e92-4315-8ef5-7e492741e3c6queued¤logsrunning¦outputbody0.9mimetext/plainrootassigneelast_run_timestampAjKgϰpersist_js_state·has_pluto_hook_features§cell_id$fe4172e4-7e92-4315-8ef5-7e492741e3c6depends_on_disabled_cells§runtime0published_object_keysdepends_on_skipped_cells§errored$de630fac-0faa-472e-b62a-cae1516a7812queued¤logsrunning¦outputbody0.3mimetext/plainrootassigneelast_run_timestampAjJ persist_js_state·has_pluto_hook_features§cell_id$de630fac-0faa-472e-b62a-cae1516a7812depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$0573a9fd-511d-4803-a831-f4e7774ee9d5queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Determining-the-steady-states-numerically">Determining the steady-states numerically</h2>
<p>Using the functions defined below, which correctly implement fixed-point iteration and the Newton–Raphson method, solve for <code>y_ss</code>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjUpersist_js_state·has_pluto_hook_features§cell_id$0573a9fd-511d-4803-a831-f4e7774ee9d5depends_on_disabled_cells§runtime 0ݵpublished_object_keysdepends_on_skipped_cells§errored$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42queued¤logsrunning¦outputbody0.1mimetext/plainrootassigneelast_run_timestampAjIE,persist_js_state·has_pluto_hook_features§cell_id$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42depends_on_disabled_cells§runtime%~published_object_keysdepends_on_skipped_cells§errored$5e7c0923-8c43-4488-b55f-35449c135e92queued¤logsrunning¦outputbodyR<div class="markdown"><div class="admonition info"><p class="admonition-title">Check Your Work!</p><p>If your <code>rhs</code> function is implemented properly, then using the default values provided above you should find <code>rhs&#40;&#91;0.5, 0.8&#93;&#41; &#61; &#91;-0.161873, 0.362375&#93;</code>, as checked below</p>
</div>
</div>mimetext/htmlrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$5e7c0923-8c43-4488-b55f-35449c135e92depends_on_disabled_cells§runtime :published_object_keysdepends_on_skipped_cells§errored$78196f94-7015-4b68-8cba-4d457753f192queued¤logslinemsg-It looks like there's a mistake, keep at it!
text/plaincell_id$78196f94-7015-4b68-8cba-4d457753f192kwargsidPlutoRunner_d1acb81efileP/home/runner/.julia/packages/Pluto/iHy3V/src/runner/PlutoRunner/src/io/stdout.jlgroupstdoutlevelLogLevel(-555)running¦outputbodymimetext/plainrootassigneelast_run_timestampAjuѰpersist_js_state·has_pluto_hook_features§cell_id$78196f94-7015-4b68-8cba-4d457753f192depends_on_disabled_cells§runtime ?published_object_keysdepends_on_skipped_cells§errored$3831d0b7-d8b8-4bc9-a578-8de2a3133428queued¤logsrunning¦outputbody)jacobian (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$3831d0b7-d8b8-4bc9-a578-8de2a3133428depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$2416ac47-b542-453e-8486-230deeb508e2queued¤logsrunning¦outputbody١<div class="markdown"><p>Determine the steady-state value, according to the fixed-point method, and save it in a variable titled <code>y_ss_fp</code>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjspersist_js_state·has_pluto_hook_features§cell_id$2416ac47-b542-453e-8486-230deeb508e2depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$16b2e39e-b2af-4eb4-82fe-0ac571765650queued¤logsrunning¦outputbody<div class="markdown"><h3 id="Fixed-point-iteration-\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;5&#93;&#125;&#125;">Fixed-point iteration <span class="tex">$\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;5&#93;&#125;&#125;$</span></h3>
<p>The function <code>fixed_pt&#40;f, y0&#41;</code> defined below solves for the vector <code>y</code> where <code>f&#40;y&#41; &#61; y</code>. However, we are interested in determining where <code>rhs&#40;y&#41; &#61; 0</code>. Thus, we need to define a <strong><em>new function</em></strong> that can be passed into the <code>fixed_pt</code> function. Recalling your written problem set from last week, write a function <code>fp_rhs&#40;y&#41;</code> for which <code>y &#61; fp_rhs&#40;y&#41;</code> is a solution to <code>rhs&#40;y&#41; &#61; 0</code>. There are many options to choose from, but not all of them will lead to a converged solution.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjbpersist_js_state·has_pluto_hook_features§cell_id$16b2e39e-b2af-4eb4-82fe-0ac571765650depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$ff2a0cdf-0718-4518-8e8d-4173337acd6fqueued¤logsrunning¦outputbody^<bond def="H" unique_id="cfcpdhakftsw"><input type='range' min='1' max='21' value='13'></bond>mimetext/htmlrootassigneelast_run_timestampAjJ>persist_js_state·has_pluto_hook_features§cell_id$ff2a0cdf-0718-4518-8e8d-4173337acd6fdepends_on_disabled_cells§runtime Gpublished_object_keysdepends_on_skipped_cells§errored$d22d34e2-afb8-4dff-b788-af0a73ed5a64queued¤logsrunning¦outputbody<div class="markdown"><p>We are now interested in solving for the steady-states of the highly nonlinear functions above, using numerical methods. In particular, we would like to find the vector <code>y_ss</code> such that <code>rhs&#40;y_ss&#41; &#61; 0</code>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAj{persist_js_state·has_pluto_hook_features§cell_id$d22d34e2-afb8-4dff-b788-af0a73ed5a64depends_on_disabled_cells§runtime QQpublished_object_keysdepends_on_skipped_cells§errored$82af52d8-a85b-481f-b282-3d071f84d961queued¤logsrunning¦outputbody<div class="markdown"><h3 id="Newton–Raphson-method-\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;2&#93;&#125;&#125;">Newton–Raphson method <span class="tex">$\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;2&#93;&#125;&#125;$</span></h3>
<p>Now determine the same steady-state solution using the function <code>newton_raphson</code> defined below. This function takes a function <code>f</code> and an initial guess <code>y0</code>, and solves for <code>y</code> such that <code>f&#40;y&#41; &#61; 0</code>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjҰpersist_js_state·has_pluto_hook_features§cell_id$82af52d8-a85b-481f-b282-3d071f84d961depends_on_disabled_cells§runtime 'published_object_keysdepends_on_skipped_cells§errored$d433673a-9af0-11ef-31f5-532e0f539822queued¤logsrunning¦outputbody<div class="markdown"><h1 id="Q2.-Dynamics-of-a-chemical-reactor-\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;14&#93;&#125;&#125;">Q2. Dynamics of a chemical reactor <span class="tex">$\textcolor&#123;red&#125;&#123;\texttt&#123;&#91;14&#93;&#125;&#125;$</span></h1>
<p>Here, we will continue analyzing the scenario described in the written portion of the problem set. Recall that in terms of the dimensionless concentration and temperature, we have the coupled equations</p>
<p class="tex">$$\dfrac&#123;\text&#123;d&#125; c^*&#125;&#123;\text&#123;d&#125; t^*&#125;
\, &#61; \, 1
\, - \, c^*
\, - \, \tilde&#123;K&#125; \, &#40;c^*&#41;^2 \, e^&#123;-\tilde&#123;G&#125;/T^*&#125;$$</p>
<p>and</p>
<p class="tex">$$\dfrac&#123;\text&#123;d&#125; T^*&#125;&#123;\text&#123;d&#125; t^*&#125;
\, &#61; \, 1
\, &#43; \, \tilde&#123;U&#125; \, T^*_\infty
\, - \, &#40;1 &#43; \tilde&#123;U&#125;&#41; \, T^*
\, &#43; \, \tilde&#123;K&#125; \, \tilde&#123;H&#125; \, &#40;c^*&#41;^2 \, e^&#123;-\tilde&#123;G&#125;/T^*&#125;
~.$$</p>
<p>In order to be able to solve these equations numerically, we want to express them in a form convenient to a computer. To this end, we define</p>
<p class="tex">$$y_1
\, \equiv \, c^*
\qquad
\text&#123;and&#125;
\qquad
y_2
\, \equiv \, T^*
~,$$</p>
<p>such that our collective unknowns are contained in the vector</p>
<p class="tex">$$\boldsymbol&#123;y&#125;&#40;t&#41;
\, &#61; \, \begin&#123;bmatrix&#125;
y_1 &#40;t&#41;
\\&#91;3pt&#93;
y_2 &#40;t&#41;
\end&#123;bmatrix&#125;
~.$$</p>
<p>Note that in our code, the &quot;time&quot; variable is understood to be the dimensionless time <span class="tex">$t^*$</span>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$d433673a-9af0-11ef-31f5-532e0f539822depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$fcad97ac-2227-417b-9633-205f30b115bfqueued¤logsrunning¦outputbody9<div class="markdown"><p>First, let us define the relevant constants in the problem. We will drop the &quot;<span class="tex">$\sim$</span>&quot; accent for notational simplicity. You can use the sliders to change the values of the different constants. The slider value is printed for your convenience.</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjDpersist_js_state·has_pluto_hook_features§cell_id$fcad97ac-2227-417b-9633-205f30b115bfdepends_on_disabled_cells§runtime H4published_object_keysdepends_on_skipped_cells§errored$e5893786-2a3b-4ac0-b918-d67d90d7766dqueued¤logsrunning¦outputbodyC<div class="markdown"><p>&#91;Type your answer here&#93;</p>
</div>mimetext/htmlrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$e5893786-2a3b-4ac0-b918-d67d90d7766ddepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$d254d9e6-c3cd-4ddf-94a4-50150353d4d8queued¤logsrunning¦outputbody/newton_raphson (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAjҰpersist_js_state·has_pluto_hook_features§cell_id$d254d9e6-c3cd-4ddf-94a4-50150353d4d8depends_on_disabled_cells§runtime .published_object_keysdepends_on_skipped_cells§errored$d8f55bd9-7438-4b23-a332-2b2474e15ac1queued¤logsrunning¦outputbody`<bond def="T_inf" unique_id="ijtscixcsder"><input type='range' min='1' max='5' value='2'></bond>mimetext/htmlrootassigneelast_run_timestampAjJpersist_js_state·has_pluto_hook_features§cell_id$d8f55bd9-7438-4b23-a332-2b2474e15ac1depends_on_disabled_cells§runtime =published_object_keysdepends_on_skipped_cells§errored$4f292f8e-2746-41fb-b73a-49daa8b7d3d9queued¤logsrunning¦outputbody)fixed_pt (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampAjpersist_js_state·has_pluto_hook_features§cell_id$4f292f8e-2746-41fb-b73a-49daa8b7d3d9depends_on_disabled_cells§runtime +published_object_keysdepends_on_skipped_cells§errored±cell_dependencies $2ca31dab-a7fb-4003-ab1b-64d821f7ed89precedence_heuristic	cell_id$2ca31dab-a7fb-4003-ab1b-64d821f7ed89downstream_cells_mapupstream_cells_mapH$ff2a0cdf-0718-4518-8e8d-4173337acd6f$91c7dac4-e6cb-4cb8-92a7-3a61a67da47dprecedence_heuristic	cell_id$91c7dac4-e6cb-4cb8-92a7-3a61a67da47ddownstream_cells_mapupstream_cells_maprhs$01bdab11-249e-48e5-b49d-482d2bb36c0a$52b3d09c-0403-4d74-a4ed-0efd296b4447precedence_heuristic	cell_id$52b3d09c-0403-4d74-a4ed-0efd296b4447downstream_cells_mapupstream_cells_map@md_strgetindex$8de396f8-1883-45fb-af70-33eb913fb5e1precedence_heuristic	cell_id$8de396f8-1883-45fb-af70-33eb913fb5e1downstream_cells_mapG$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$d22c5b6a-66e7-49a1-8efa-47995a81df0bprecedence_heuristic	cell_id$d22c5b6a-66e7-49a1-8efa-47995a81df0bdownstream_cells_mapupstream_cells_mapK$4389a709-c98b-4012-9642-c8f5fc2b24f4$8022011a-7c65-479c-a879-f3d5472299f0precedence_heuristic	cell_id$8022011a-7c65-479c-a879-f3d5472299f0downstream_cells_mapU$de630fac-0faa-472e-b62a-cae1516a7812upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$01bdab11-249e-48e5-b49d-482d2bb36c0aprecedence_heuristic	cell_id$01bdab11-249e-48e5-b49d-482d2bb36c0adownstream_cells_maprhs$91c7dac4-e6cb-4cb8-92a7-3a61a67da47d$78196f94-7015-4b68-8cba-4d457753f192upstream_cells_map$4389a709-c98b-4012-9642-c8f5fc2b24f4precedence_heuristic	cell_id$4389a709-c98b-4012-9642-c8f5fc2b24f4downstream_cells_mapK$d22c5b6a-66e7-49a1-8efa-47995a81df0bupstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$613b487b-e836-44fa-80eb-72c3191b4c3cprecedence_heuristic	cell_id$613b487b-e836-44fa-80eb-72c3191b4c3cdownstream_cells_mapupstream_cells_map@md_strgetindex$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129precedence_heuristic	cell_id$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129downstream_cells_mapupstream_cells_map@md_strgetindex$5811cf9b-25ef-4851-9d51-8c7ec233cd03precedence_heuristiccell_id$5811cf9b-25ef-4851-9d51-8c7ec233cd03downstream_cells_mapLinearAlgebraPlutoUIupstream_cells_map$fe4172e4-7e92-4315-8ef5-7e492741e3c6precedence_heuristic	cell_id$fe4172e4-7e92-4315-8ef5-7e492741e3c6downstream_cells_mapupstream_cells_mapT_inf$d8f55bd9-7438-4b23-a332-2b2474e15ac1$de630fac-0faa-472e-b62a-cae1516a7812precedence_heuristic	cell_id$de630fac-0faa-472e-b62a-cae1516a7812downstream_cells_mapupstream_cells_mapU$8022011a-7c65-479c-a879-f3d5472299f0$0573a9fd-511d-4803-a831-f4e7774ee9d5precedence_heuristic	cell_id$0573a9fd-511d-4803-a831-f4e7774ee9d5downstream_cells_mapupstream_cells_map@md_strgetindex$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42precedence_heuristic	cell_id$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42downstream_cells_mapupstream_cells_mapG$8de396f8-1883-45fb-af70-33eb913fb5e1$5e7c0923-8c43-4488-b55f-35449c135e92precedence_heuristic	cell_id$5e7c0923-8c43-4488-b55f-35449c135e92downstream_cells_mapupstream_cells_map@md_strgetindex$78196f94-7015-4b68-8cba-4d457753f192precedence_heuristic	cell_id$78196f94-7015-4b68-8cba-4d457753f192downstream_cells_mapupstream_cells_map<-islessrhs$01bdab11-249e-48e5-b49d-482d2bb36c0anormprintln$3831d0b7-d8b8-4bc9-a578-8de2a3133428precedence_heuristic	cell_id$3831d0b7-d8b8-4bc9-a578-8de2a3133428downstream_cells_mapjacobian$d254d9e6-c3cd-4ddf-94a4-50150353d4d8upstream_cells_maplength:-/zeros+Function$2416ac47-b542-453e-8486-230deeb508e2precedence_heuristic	cell_id$2416ac47-b542-453e-8486-230deeb508e2downstream_cells_mapupstream_cells_map@md_strgetindex$16b2e39e-b2af-4eb4-82fe-0ac571765650precedence_heuristic	cell_id$16b2e39e-b2af-4eb4-82fe-0ac571765650downstream_cells_mapupstream_cells_map@md_strgetindex$ff2a0cdf-0718-4518-8e8d-4173337acd6fprecedence_heuristic	cell_id$ff2a0cdf-0718-4518-8e8d-4173337acd6fdownstream_cells_mapH$2ca31dab-a7fb-4003-ab1b-64d821f7ed89upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$d22d34e2-afb8-4dff-b788-af0a73ed5a64precedence_heuristic	cell_id$d22d34e2-afb8-4dff-b788-af0a73ed5a64downstream_cells_mapupstream_cells_map@md_strgetindex$82af52d8-a85b-481f-b282-3d071f84d961precedence_heuristic	cell_id$82af52d8-a85b-481f-b282-3d071f84d961downstream_cells_mapupstream_cells_map@md_strgetindex$d433673a-9af0-11ef-31f5-532e0f539822precedence_heuristic	cell_id$d433673a-9af0-11ef-31f5-532e0f539822downstream_cells_mapupstream_cells_map@md_strgetindex$fcad97ac-2227-417b-9633-205f30b115bfprecedence_heuristic	cell_id$fcad97ac-2227-417b-9633-205f30b115bfdownstream_cells_mapupstream_cells_map@md_strgetindex$e5893786-2a3b-4ac0-b918-d67d90d7766dprecedence_heuristic	cell_id$e5893786-2a3b-4ac0-b918-d67d90d7766ddownstream_cells_mapupstream_cells_map@md_strgetindex$d254d9e6-c3cd-4ddf-94a4-50150353d4d8precedence_heuristic	cell_id$d254d9e6-c3cd-4ddf-94a4-50150353d4d8downstream_cells_mapnewton_raphsonupstream_cells_mapjacobian$3831d0b7-d8b8-4bc9-a578-8de2a3133428>islessnormprintlnisequalFunction<-\+*==NaN$d8f55bd9-7438-4b23-a332-2b2474e15ac1precedence_heuristic	cell_id$d8f55bd9-7438-4b23-a332-2b2474e15ac1downstream_cells_mapT_inf$fe4172e4-7e92-4315-8ef5-7e492741e3c6upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getSlider$4f292f8e-2746-41fb-b73a-49daa8b7d3d9precedence_heuristic	cell_id$4f292f8e-2746-41fb-b73a-49daa8b7d3d9downstream_cells_mapfixed_ptupstream_cells_map>islessnormprintlnisequalFunction<-+*==NaNcell_execution_order $5811cf9b-25ef-4851-9d51-8c7ec233cd03$d433673a-9af0-11ef-31f5-532e0f539822$fcad97ac-2227-417b-9633-205f30b115bf$4389a709-c98b-4012-9642-c8f5fc2b24f4$d22c5b6a-66e7-49a1-8efa-47995a81df0b$8de396f8-1883-45fb-af70-33eb913fb5e1$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42$8022011a-7c65-479c-a879-f3d5472299f0$de630fac-0faa-472e-b62a-cae1516a7812$ff2a0cdf-0718-4518-8e8d-4173337acd6f$2ca31dab-a7fb-4003-ab1b-64d821f7ed89$d8f55bd9-7438-4b23-a332-2b2474e15ac1$fe4172e4-7e92-4315-8ef5-7e492741e3c6$613b487b-e836-44fa-80eb-72c3191b4c3c$01bdab11-249e-48e5-b49d-482d2bb36c0a$91c7dac4-e6cb-4cb8-92a7-3a61a67da47d$5e7c0923-8c43-4488-b55f-35449c135e92$78196f94-7015-4b68-8cba-4d457753f192$d22d34e2-afb8-4dff-b788-af0a73ed5a64$0573a9fd-511d-4803-a831-f4e7774ee9d5$16b2e39e-b2af-4eb4-82fe-0ac571765650$4f292f8e-2746-41fb-b73a-49daa8b7d3d9$2416ac47-b542-453e-8486-230deeb508e2$82af52d8-a85b-481f-b282-3d071f84d961$3831d0b7-d8b8-4bc9-a578-8de2a3133428$d254d9e6-c3cd-4ddf-94a4-50150353d4d8$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129$52b3d09c-0403-4d74-a4ed-0efd296b4447$e5893786-2a3b-4ac0-b918-d67d90d7766dlast_hot_reload_time        shortpathps09-qs.jlprocess_statusreadypathO/home/runner/work/sahu-lab.github.io/sahu-lab.github.io/teach/che348/ps09-qs.jlpluto_versionv0.20.23last_save_timeAjcell_order $5811cf9b-25ef-4851-9d51-8c7ec233cd03$d433673a-9af0-11ef-31f5-532e0f539822$fcad97ac-2227-417b-9633-205f30b115bf$4389a709-c98b-4012-9642-c8f5fc2b24f4$d22c5b6a-66e7-49a1-8efa-47995a81df0b$8de396f8-1883-45fb-af70-33eb913fb5e1$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42$8022011a-7c65-479c-a879-f3d5472299f0$de630fac-0faa-472e-b62a-cae1516a7812$ff2a0cdf-0718-4518-8e8d-4173337acd6f$2ca31dab-a7fb-4003-ab1b-64d821f7ed89$d8f55bd9-7438-4b23-a332-2b2474e15ac1$fe4172e4-7e92-4315-8ef5-7e492741e3c6$613b487b-e836-44fa-80eb-72c3191b4c3c$01bdab11-249e-48e5-b49d-482d2bb36c0a$91c7dac4-e6cb-4cb8-92a7-3a61a67da47d$5e7c0923-8c43-4488-b55f-35449c135e92$78196f94-7015-4b68-8cba-4d457753f192$d22d34e2-afb8-4dff-b788-af0a73ed5a64$0573a9fd-511d-4803-a831-f4e7774ee9d5$16b2e39e-b2af-4eb4-82fe-0ac571765650$4f292f8e-2746-41fb-b73a-49daa8b7d3d9$2416ac47-b542-453e-8486-230deeb508e2$82af52d8-a85b-481f-b282-3d071f84d961$3831d0b7-d8b8-4bc9-a578-8de2a3133428$d254d9e6-c3cd-4ddf-94a4-50150353d4d8$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129$52b3d09c-0403-4d74-a4ed-0efd296b4447$e5893786-2a3b-4ac0-b918-d67d90d7766dpublished_objectsnbpkginstall_time_ns"instantiatedòinstalled_versionsLinearAlgebrastdlibPlutoUI0.7.60terminal_outputsnbpkg_sync
[0m[1mResolving...[22m
[90m===[39m
[33m[1m┌ [22m[39m[33m[1mWarning: [22m[39mPkg operation failed. Fixing stdlib dependencies and trying again...
[33m[1m└ [22m[39m[90m@ GracefulPkg ~/.julia/packages/GracefulPkg/GQ6My/src/apply strategies.jl:96[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Project.toml`
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Manifest.toml`

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Waiting for notebook process to start... Done. Starting precompilation...LinearAlgebra
[0m[1mResolving...[22m
[90m===[39m
[33m[1m┌ [22m[39m[33m[1mWarning: [22m[39mPkg operation failed. Fixing stdlib dependencies and trying again...
[33m[1m└ [22m[39m[90m@ GracefulPkg ~/.julia/packages/GracefulPkg/GQ6My/src/apply strategies.jl:96[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Project.toml`
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Manifest.toml`

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Waiting for notebook process to start... Done. Starting precompilation...PlutoUI
[0m[1mResolving...[22m
[90m===[39m
[33m[1m┌ [22m[39m[33m[1mWarning: [22m[39mPkg operation failed. Fixing stdlib dependencies and trying again...
[33m[1m└ [22m[39m[90m@ GracefulPkg ~/.julia/packages/GracefulPkg/GQ6My/src/apply strategies.jl:96[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Project.toml`
[32m[1m  No Changes[22m[39m to `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_nztmrnfyyy/Manifest.toml`

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Waiting for notebook process to start... Done. Starting precompilation...enabled÷restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputs $2ca31dab-a7fb-4003-ab1b-64d821f7ed89cell_id$2ca31dab-a7fb-4003-ab1b-64d821f7ed89codeHmetadatashow_logsèdisabled®skip_as_script«code_folded$91c7dac4-e6cb-4cb8-92a7-3a61a67da47dcell_id$91c7dac4-e6cb-4cb8-92a7-3a61a67da47dcoderhs([0.5, 0.8])[2]metadatashow_logsèdisabled®skip_as_script«code_folded$52b3d09c-0403-4d74-a4ed-0efd296b4447cell_id$52b3d09c-0403-4d74-a4ed-0efd296b4447codePmd"""
!!! question "Question"
	Is the steady state stable or unstable?
	Why?
"""metadatashow_logsèdisabled®skip_as_script«code_folded$8de396f8-1883-45fb-af70-33eb913fb5e1cell_id$8de396f8-1883-45fb-af70-33eb913fb5e1code(@bind G Slider(0.1:0.1:2.0, default=0.1)metadatashow_logsèdisabled®skip_as_script«code_folded$d22c5b6a-66e7-49a1-8efa-47995a81df0bcell_id$d22c5b6a-66e7-49a1-8efa-47995a81df0bcodeKmetadatashow_logsèdisabled®skip_as_script«code_folded$8022011a-7c65-479c-a879-f3d5472299f0cell_id$8022011a-7c65-479c-a879-f3d5472299f0code(@bind U Slider(0.1:0.1:2.0, default=0.3)metadatashow_logsèdisabled®skip_as_script«code_folded$01bdab11-249e-48e5-b49d-482d2bb36c0acell_id$01bdab11-249e-48e5-b49d-482d2bb36c0acodeWfunction rhs(y)
	# the following return statement is incorrect
	return [y[1], y[2]]
endmetadatashow_logsèdisabled®skip_as_script«code_folded$4389a709-c98b-4012-9642-c8f5fc2b24f4cell_id$4389a709-c98b-4012-9642-c8f5fc2b24f4code@bind K Slider(1:10, default=3)metadatashow_logsèdisabled®skip_as_script«code_folded$613b487b-e836-44fa-80eb-72c3191b4c3ccell_id$613b487b-e836-44fa-80eb-72c3191b4c3ccode_md"""

## RHS function $$\textcolor{red}{\texttt{[3]}}$$

Write a function `rhs(y::Vector{Number})` that takes in the vector $\boldsymbol{y}$ and returns the right-hand side of the two differential equations provided above, collected into a vector.
Your function should use the values from the sliders above, i.e. `K`, `G`, `H`, `U`, and `T_inf`.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129cell_id$ce22e51c-85e3-4fe3-acb4-89fa3a6ef129code$md"""
## Numerical stability of the steady state $$\textcolor{red}{\texttt{[4]}}$$

Now that we have determined the steady state solution, let us investigate the stability numerically.
Call the `jacobian` function defined above, using either your fixed-point or Newton--Raphson solution.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$5811cf9b-25ef-4851-9d51-8c7ec233cd03cell_id$5811cf9b-25ef-4851-9d51-8c7ec233cd03code-begin
	using PlutoUI
	using LinearAlgebra
endmetadatashow_logsèdisabled®skip_as_script«code_folded$fe4172e4-7e92-4315-8ef5-7e492741e3c6cell_id$fe4172e4-7e92-4315-8ef5-7e492741e3c6codeT_infmetadatashow_logsèdisabled®skip_as_script«code_folded$de630fac-0faa-472e-b62a-cae1516a7812cell_id$de630fac-0faa-472e-b62a-cae1516a7812codeUmetadatashow_logsèdisabled®skip_as_script«code_folded$0573a9fd-511d-4803-a831-f4e7774ee9d5cell_id$0573a9fd-511d-4803-a831-f4e7774ee9d5codeپmd"""
## Determining the steady-states numerically

Using the functions defined below, which correctly implement fixed-point iteration and the Newton--Raphson method, solve for `y_ss`.


"""metadatashow_logsèdisabled®skip_as_script«code_folded$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42cell_id$0a3ae873-4b8b-4255-ae8c-bd220a9a4a42codeGmetadatashow_logsèdisabled®skip_as_script«code_folded$5e7c0923-8c43-4488-b55f-35449c135e92cell_id$5e7c0923-8c43-4488-b55f-35449c135e92codemd"""
!!! info "Check Your Work!"
	If your `rhs` function is implemented properly, then using the default values provided above you should find
	`rhs([0.5, 0.8]) = [-0.161873, 0.362375]`, as checked below
"""metadatashow_logsèdisabled®skip_as_script«code_folded$78196f94-7015-4b68-8cba-4d457753f192cell_id$78196f94-7015-4b68-8cba-4d457753f192codeif norm(rhs([0.5, 0.8]) - [-0.16187267693844665, 0.3623745353876893]) < 1e-10
	println("Your function is implemented correctly!")
else
	println("It looks like there's a mistake, keep at it!")
endmetadatashow_logsèdisabled®skip_as_script«code_folded$3831d0b7-d8b8-4bc9-a578-8de2a3133428cell_id$3831d0b7-d8b8-4bc9-a578-8de2a3133428code1# this function was adapted from the coding solution to problem set 5
function jacobian(f::Function, y)
	h = 1e-7
	num_dimensions = length(y)
	J = zeros(num_dimensions, num_dimensions)
	for i = 1:num_dimensions
		dy = zeros(num_dimensions)
		dy[i] = h
		J[:,i] = (f(y + dy) - f(y)) / h
	end

	return J
endmetadatashow_logsèdisabled®skip_as_script«code_folded$2416ac47-b542-453e-8486-230deeb508e2cell_id$2416ac47-b542-453e-8486-230deeb508e2code|md"""
Determine the steady-state value, according to the fixed-point method, and save it in a variable titled `y_ss_fp`.
"""metadatashow_logsèdisabled®skip_as_script«code_folded$16b2e39e-b2af-4eb4-82fe-0ac571765650cell_id$16b2e39e-b2af-4eb4-82fe-0ac571765650code$md"""

### Fixed-point iteration $$\textcolor{red}{\texttt{[5]}}$$

The function `fixed_pt(f, y0)` defined below solves for the vector `y` where `f(y) = y`.
However, we are interested in determining where `rhs(y) = 0`.
Thus, we need to define a __*new function*__ that can be passed into the `fixed_pt` function.
Recalling your written problem set from last week, write a function `fp_rhs(y)` for which `y = fp_rhs(y)` is a solution to `rhs(y) = 0`.
There are many options to choose from, but not all of them will lead to a converged solution.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$ff2a0cdf-0718-4518-8e8d-4173337acd6fcell_id$ff2a0cdf-0718-4518-8e8d-4173337acd6fcode)@bind H Slider(-1.0:0.1:1.0, default=0.2)metadatashow_logsèdisabled®skip_as_script«code_folded$d22d34e2-afb8-4dff-b788-af0a73ed5a64cell_id$d22d34e2-afb8-4dff-b788-af0a73ed5a64codemd"""
We are now interested in solving for the steady-states of the highly nonlinear functions above, using numerical methods.
In particular, we would like to find the vector `y_ss` such that `rhs(y_ss) = 0`.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$82af52d8-a85b-481f-b282-3d071f84d961cell_id$82af52d8-a85b-481f-b282-3d071f84d961codemd"""
### Newton--Raphson method $$\textcolor{red}{\texttt{[2]}}$$

Now determine the same steady-state solution using the function `newton_raphson` defined below.
This function takes a function `f` and an initial guess `y0`, and solves for `y` such that `f(y) = 0`.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$d433673a-9af0-11ef-31f5-532e0f539822cell_id$d433673a-9af0-11ef-31f5-532e0f539822code.md"""
# Q2. Dynamics of a chemical reactor $$\textcolor{red}{\texttt{[14]}}$$

Here, we will continue analyzing the scenario described in the written portion of the problem set.
Recall that in terms of the dimensionless concentration and temperature, we have the coupled equations
```math
\dfrac{\text{d} c^*}{\text{d} t^*}
\, = \, 1
\, - \, c^*
\, - \, \tilde{K} \, (c^*)^2 \, e^{-\tilde{G}/T^*}
```
and
```math
\dfrac{\text{d} T^*}{\text{d} t^*}
\, = \, 1
\, + \, \tilde{U} \, T^*_\infty
\, - \, (1 + \tilde{U}) \, T^*
\, + \, \tilde{K} \, \tilde{H} \, (c^*)^2 \, e^{-\tilde{G}/T^*}
~.
```
In order to be able to solve these equations numerically, we want to express them in a form convenient to a computer.
To this end, we define
```math
y_1
\, \equiv \, c^*
\qquad
\text{and}
\qquad
y_2
\, \equiv \, T^*
~,
```
such that our collective unknowns are contained in the vector
```math
\boldsymbol{y}(t)
\, = \, \begin{bmatrix}
y_1 (t)
\\[3pt]
y_2 (t)
\end{bmatrix}
~.
```
Note that in our code, the "time" variable is understood to be the dimensionless time $t^*$.


"""metadatashow_logsèdisabled®skip_as_script«code_folded$fcad97ac-2227-417b-9633-205f30b115bfcell_id$fcad97ac-2227-417b-9633-205f30b115bfcodemd"""
First, let us define the relevant constants in the problem.
We will drop the "$\sim$" accent for notational simplicity.
You can use the sliders to change the values of the different constants.
The slider value is printed for your convenience.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$e5893786-2a3b-4ac0-b918-d67d90d7766dcell_id$e5893786-2a3b-4ac0-b918-d67d90d7766dcode!md"""
[Type your answer here]
"""metadatashow_logsèdisabled®skip_as_script«code_folded$d254d9e6-c3cd-4ddf-94a4-50150353d4d8cell_id$d254d9e6-c3cd-4ddf-94a4-50150353d4d8code# Use Newton--Raphson iteration to find where f(y) = 0, given an initial guess y0
function newton_raphson(f::Function, y0)
	eps_tol   = 1e-11
	max_count = 10

	y = y0
	count = 0
	error = norm(f(y))
	
	while error > eps_tol && count < max_count
		y = y - jacobian(f, y) \ f(y)
		error = norm(f(y))
		count = count + 1
		# to be used for debugging
		#println(y, "\t", error)
	end

	# if the iteration reached the maximum count, or the values approach infinity
	# (thus leading to the error being "Not a Number", or NaN, then we failed)
	if count == max_count || isequal(error, NaN)
		println("fixed point not found!")
		return 0.0 * y0;
	else
		println("converged in ", count, " iterations!")
		return y
	end
	
endmetadatashow_logsèdisabled®skip_as_script«code_folded$d8f55bd9-7438-4b23-a332-2b2474e15ac1cell_id$d8f55bd9-7438-4b23-a332-2b2474e15ac1code,@bind T_inf Slider(0.8:0.1:1.2, default=0.9)metadatashow_logsèdisabled®skip_as_script«code_folded$4f292f8e-2746-41fb-b73a-49daa8b7d3d9cell_id$4f292f8e-2746-41fb-b73a-49daa8b7d3d9code# Use fixed point iteration to find where f(y) = y, given an initial guess y0
function fixed_pt(f::Function, y0)
	eps_tol   = 1e-11
	max_count = 400

	y = y0
	count = 0
	error = norm(f(y) - y)
	while error > eps_tol && count < max_count
		y = f(y)
		error = norm(f(y) - y)
		count = count + 1
		# to be used for debugging
		#println(y, "\t", error)
	end

	# if the iteration reached the maximum count, or the values approach infinity
	# (thus leading to the error being "Not a Number", or NaN, then we failed)
	if count == max_count || isequal(error, NaN)
		println("fixed point not found!")
		return 0.0 * y0;
	else
		println("converged in ", count, " iterations!")
		return y
	end
endmetadatashow_logsèdisabled®skip_as_script«code_folded«notebook_id$7779d98c-1903-11f1-29f7-3bd04c9a512ain_temp_dir¨metadata