<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nemenmanlab.org/~ilya/index.php?action=history&amp;feed=atom&amp;title=Physics_212%2C_2019%3A_Lecture_2</id>
	<title>Physics 212, 2019: Lecture 2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nemenmanlab.org/~ilya/index.php?action=history&amp;feed=atom&amp;title=Physics_212%2C_2019%3A_Lecture_2"/>
	<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;action=history"/>
	<updated>2026-04-26T23:47:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3157&amp;oldid=prev</id>
		<title>Ilya: /* How to build a computational model? */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3157&amp;oldid=prev"/>
		<updated>2019-02-03T18:40:15Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;How to build a computational model?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 18:40, 3 February 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l68&quot; &gt;Line 68:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 68:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Model building proceeds by first identifying the things we know, and the things we need to find out, and listing them clearly. This includes accounting for dimensions of the variables, and for their type: deterministic or not, continuous or not, dynamic or not. From that point, the model building proceeds hierarchically. We first define a few large scale steps that will be needed to get the solution from the known variables. Usually these include the initialization step, a few large-scale computational steps, and then the termination/results output step. Then we move to the computational steps and, for each of them, we break it up into smaller pieces. We continue to break each piece into even smaller pieces until we realize that we already have an implementation for the pieces that we just constructed. In class, we considered the &amp;quot;shut the door!&amp;quot; program as a prototype for a computational model. Opening the door had to be broken down into finding the door, navigating to it, and then shutting it. Then finding the door had to be broken down into scanning the room, comparing snapshots with various door templates, and identifying if any of the snapshots includes an open door. In its turn, comparing to the templates meant loading the set of templates, and so on. Eventually, we come down to a a set of such atomic instructions, where an atom is either understood by the computer directly, or has already been coded by someone else, and can be reused. At this point, the hierarchical construction stops, and we start moving back on the hierarchy towards larger blocks are assembling both initialization and termination steps together: what are the pieces that are needed for each level of the hierarchy to work? And what are the pieces that each level of the hierarchy will output?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Model building proceeds by first identifying the things we know, and the things we need to find out, and listing them clearly. This includes accounting for dimensions of the variables, and for their type: deterministic or not, continuous or not, dynamic or not. From that point, the model building proceeds hierarchically. We first define a few large scale steps that will be needed to get the solution from the known variables. Usually these include the initialization step, a few large-scale computational steps, and then the termination/results output step. Then we move to the computational steps and, for each of them, we break it up into smaller pieces. We continue to break each piece into even smaller pieces until we realize that we already have an implementation for the pieces that we just constructed. In class, we considered the &amp;quot;shut the door!&amp;quot; program as a prototype for a computational model. Opening the door had to be broken down into finding the door, navigating to it, and then shutting it. Then finding the door had to be broken down into scanning the room, comparing snapshots with various door templates, and identifying if any of the snapshots includes an open door. In its turn, comparing to the templates meant loading the set of templates, and so on. Eventually, we come down to a a set of such atomic instructions, where an atom is either understood by the computer directly, or has already been coded by someone else, and can be reused. At this point, the hierarchical construction stops, and we start moving back on the hierarchy towards larger blocks are assembling both initialization and termination steps together: what are the pieces that are needed for each level of the hierarchy to work? And what are the pieces that each level of the hierarchy will output?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We have spent a lot of time on this in class, and also the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;''&lt;/del&gt;Python Student's Guide&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;'' &lt;/del&gt;has some relevant discussion in the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;``&lt;/del&gt;Algorithmic Thinking&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;'' &lt;/del&gt;section, Chapter 1.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We have spent a lot of time on this in class, and also the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot;&lt;/ins&gt;Python Student's Guide&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot; &lt;/ins&gt;has some relevant discussion in the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot;&lt;/ins&gt;Algorithmic Thinking&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot; &lt;/ins&gt;section, Chapter 1.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A key concept that is illustrated by this approach to building computational models is code / model reuse. ''Do not develop models from scratch!'' Your time is valuable&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A key concept that is illustrated by this approach to building computational models is code / model reuse. ''Do not develop models from scratch!'' Your time is valuable&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;. Use the code that either you or somebody else wrote previously, even if this is not the most elegant solution, unless there's an educational value in writing the code on your own.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3156&amp;oldid=prev</id>
		<title>Ilya at 18:39, 3 February 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3156&amp;oldid=prev"/>
		<updated>2019-02-03T18:39:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 18:39, 3 February 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l64&quot; &gt;Line 64:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Which specific models to use depends on the type of problem you study, and the choice, the explanation of it, and the assumptions involved, should figure prominently in the model-building process.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Which specific models to use depends on the type of problem you study, and the choice, the explanation of it, and the assumptions involved, should figure prominently in the model-building process.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==How to build a computational model?==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Model building proceeds by first identifying the things we know, and the things we need to find out, and listing them clearly. This includes accounting for dimensions of the variables, and for their type: deterministic or not, continuous or not, dynamic or not. From that point, the model building proceeds hierarchically. We first define a few large scale steps that will be needed to get the solution from the known variables. Usually these include the initialization step, a few large-scale computational steps, and then the termination/results output step. Then we move to the computational steps and, for each of them, we break it up into smaller pieces. We continue to break each piece into even smaller pieces until we realize that we already have an implementation for the pieces that we just constructed. In class, we considered the &amp;quot;shut the door!&amp;quot; program as a prototype for a computational model. Opening the door had to be broken down into finding the door, navigating to it, and then shutting it. Then finding the door had to be broken down into scanning the room, comparing snapshots with various door templates, and identifying if any of the snapshots includes an open door. In its turn, comparing to the templates meant loading the set of templates, and so on. Eventually, we come down to a a set of such atomic instructions, where an atom is either understood by the computer directly, or has already been coded by someone else, and can be reused. At this point, the hierarchical construction stops, and we start moving back on the hierarchy towards larger blocks are assembling both initialization and termination steps together: what are the pieces that are needed for each level of the hierarchy to work? And what are the pieces that each level of the hierarchy will output?&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;We have spent a lot of time on this in class, and also the ''Python Student's Guide'' has some relevant discussion in the ``Algorithmic Thinking'' section, Chapter 1.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;A key concept that is illustrated by this approach to building computational models is code / model reuse. ''Do not develop models from scratch!'' Your time is valuable&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3155&amp;oldid=prev</id>
		<title>Ilya at 18:12, 3 February 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3155&amp;oldid=prev"/>
		<updated>2019-02-03T18:12:18Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 18:12, 3 February 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l64&quot; &gt;Line 64:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Which specific models to use depends on the type of problem you study, and the choice, the explanation of it, and the assumptions involved, should figure prominently in the model-building process.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Which specific models to use depends on the type of problem you study, and the choice, the explanation of it, and the assumptions involved, should figure prominently in the model-building process.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==An example of a model: Solving for an equilibrium position, light version==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;A charged particle free to move on a rod is put in the between two particles with an electric charge of the same sign affixed to the end of the rod. Where will the charge come to rest?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Analysis: How should we model this? is the model dynamic or static? At the first sign, this is a dynamic model, since we are talking about ''motion'' of a charge. On the other hand, we are asked only about the final equilibrium position. Then maybe this is a static model after all -- we only need to know where the charge comes to rest. The model is definitely a continuous space model -- position of the particle is a continuous variable. The model is also deterministic -- there's not a stochastic element present. To make this a static model (so that there's a final rustic point for the charge), there has to be friction, so that the particle does not keep oscillating infinitely. Nothing is mentioned about this in the problem formulation -- but it seems like this is presumed.Does it even make sense that the particle will come to a rest? Same sign particles repel. And the repulsion is stronger when they come closer. So a particle between two other fixed one will be pushed away from both ends -- it seems reasonable that it will come to a steady point at some time if friction robs it of energy.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model building: The equilibrium for the system will be &amp;lt;math&amp;gt;\sum \vec{F}=0&amp;lt;/math&amp;gt;. Since the particle is moving on a rod -- in one dimension -- this is equivalent to &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are two Coulomb forces acting on the particle from the two end charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;, and have charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;respectively. Let's suppose &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the position of the moving charge. The forces acting on the moving charge, which we call &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are then &amp;lt;math&amp;gt;\sum F= \frac{qq_1}{(x-p_1)^2}-\frac{qq_2}{(x-p_2)^2}&amp;lt;/math&amp;gt;. Thus to solve the problem, we need to solve the following equation for &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;: &amp;lt;math&amp;gt;\frac{qq_1}{(x-p_1)^2}-\frac{qq_2}{(x-p_2)^2}=0&amp;lt;/math&amp;gt;, or, cancelling &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\frac{q_1}{(x-p_1)^2}-\frac{q_2}{(x-p_2)^2}=0&amp;lt;/math&amp;gt;. Interestingly, the only variables we need for initialization are the three charge values, and the two end charge positions -- the initial position of the moving charge, and charge value itself seem to be not needed. Multiplying the equation by the two denominators (which, luckily, cannot be zero), we get: &amp;lt;math&amp;gt;{q_1}{(x-p_2)^2}-{q_2}{(x-p_1)^2}=0&amp;lt;/math&amp;gt;. Simplifying the equation, we get: &amp;lt;math&amp;gt;(q_1-q_2) x^2 +2(-q_1p_2+q_2p_1)x+(q_1p_2^2-q_2p_1^2)=0 &amp;lt;/math&amp;gt;. So it seems that solving this problem is equivalent to solving a simple quadratic equation.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model implementation: To build a model, we start with large blocks describing chunks of the solution of the problem. We progressively break them apart into smaller and smaller blocks, until we are able to write the code for each one of the blocks. At the same time, as we are implementing the blocks, we collect pieces that need to be initialized in the initialization block, and need to be reported in the termination block. Here we realize that, in the previous class hour, we wrote a simple program that solves the quadratic equation &amp;lt;math&amp;gt;ax^2+bx+c=0&amp;lt;/math&amp;gt;. Thus implementing the model is equivalent to taking the previously written solution for the quadratic. Thus the implementation will consist of just three blocks: (1) initialization, where we assign&amp;#160; &amp;lt;math&amp;gt;a=q_1-q_2&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b=2(-q_1p_2+p_2x_1)&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_1p_2^2+q2p_1^2&amp;lt;/math&amp;gt;; (2) solving the quadratic equation and getting its two solutions; and (3) termination, where, of the two solutions, we then output the one that falls between &amp;lt;math&amp;gt;p_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p_2&amp;lt;/math&amp;gt;. &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model verification: To verify that the solution is correct, we should try it in cases where the solution is easy to guess or to estimate otherwise, and compare. For example, we can try &amp;lt;math&amp;gt;q_1=q_2&amp;lt;/math&amp;gt;, where it's clear that the solution should be &amp;lt;math&amp;gt;x=(p_1+p_2)/2&amp;lt;/math&amp;gt;. We could also choose a few conditions with different &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, and we would expect that growing &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt; should push the equilibrium farther from the left end.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Discussion: Having solved the problem, we would usually discuss our findings here, and reiterate various constraints and assumptions that entered the solution. However, this problem is too simple too write much here.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Your work: Implement the code for solving this problem, using your previous solution of the quadratic equation. Think about various exceptions that can happen with the solution. '''Make sure to submit your code.'''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==An example of a model: Solving for an equilibrium position, harder version==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;A charged particle free to move on a rod is put in the between the first and the second of three immovable particles with an electric charge of the same sign affixed to the rod at various points. Where will the charge come to rest?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Analysis: The same analysis as in the simpler version applies here: it's a static, deterministic, continuous space model. We again need the friction for the solution to exist, and the moving particle with come to rest, and the solution will exist. &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;p_1&amp;lt;x_2&amp;lt;p_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-p_1)^2}-\frac{q_2}{(x-p_2)^2}-\frac{q_3}{(x-p_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-p_2)^2}(x-x_3)^2-{q_2}{(x-p_1)^2}(x-p_3)^2 -{q_2}{(x-p_2)^2}(x-p_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;p_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;''More to be added.''&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model verification:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Discussion:&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3154&amp;oldid=prev</id>
		<title>Ilya at 18:11, 3 February 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3154&amp;oldid=prev"/>
		<updated>2019-02-03T18:11:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 18:11, 3 February 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{PHYS212-2019}}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{PHYS212-2019}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In this lecture, we discuss the basics of the modeling process, focusing on simple &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;linear (exponential) bacterial growth as &lt;/del&gt;an &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;example&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In this lecture, we discuss the basics of the modeling process, focusing on &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;a &lt;/ins&gt;simple &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;static model of finding &lt;/ins&gt;an &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;equilibrium configuration of charges&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==What is a model?==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==What is a model?==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3133&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3133&amp;oldid=prev"/>
		<updated>2019-01-30T14:13:00Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 14:13, 30 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l88&quot; &gt;Line 88:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 88:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;''More to be added.''&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model verification:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model verification:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Discussion:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Discussion:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3132&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3132&amp;oldid=prev"/>
		<updated>2019-01-30T13:22:08Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:22, 30 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l85&quot; &gt;Line 85:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 85:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Analysis: The same analysis as in the simpler version applies here: it's a static, deterministic, continuous space model. We again need the friction for the solution to exist, and the moving particle with come to rest, and the solution will exist. &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Analysis: The same analysis as in the simpler version applies here: it's a static, deterministic, continuous space model. We again need the friction for the solution to exist, and the moving particle with come to rest, and the solution will exist. &amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/del&gt;&amp;lt;x_2&amp;lt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_3&lt;/del&gt;&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/del&gt;)^2}-\frac{q_2}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_2&lt;/del&gt;)^2}-\frac{q_3}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_3&lt;/del&gt;)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_2&lt;/del&gt;)^2}(x-x_3)^2-{q_2}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/del&gt;)^2}(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_3&lt;/del&gt;)^2 -{q_2}{(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_2&lt;/del&gt;)^2}(x-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/del&gt;)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/del&gt;&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_2&lt;/del&gt;&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_1&lt;/ins&gt;&amp;lt;x_2&amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_3&lt;/ins&gt;&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_1&lt;/ins&gt;)^2}-\frac{q_2}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_2&lt;/ins&gt;)^2}-\frac{q_3}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_3&lt;/ins&gt;)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_2&lt;/ins&gt;)^2}(x-x_3)^2-{q_2}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_1&lt;/ins&gt;)^2}(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_3&lt;/ins&gt;)^2 -{q_2}{(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_2&lt;/ins&gt;)^2}(x-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_1&lt;/ins&gt;)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_1&lt;/ins&gt;&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;p_2&lt;/ins&gt;&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3131&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3131&amp;oldid=prev"/>
		<updated>2019-01-30T13:19:36Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:19, 30 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l88&quot; &gt;Line 88:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 88:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? '''Don't forget to submit your code.'''&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Model verification:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;;Discussion:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3129&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3129&amp;oldid=prev"/>
		<updated>2019-01-28T22:18:56Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 22:18, 28 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot; &gt;Line 87:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 87:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2}-\frac{1}{6}&amp;lt;/math&amp;gt;. Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not? &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;'''Don't forget to submit your code.'''&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3128&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3128&amp;oldid=prev"/>
		<updated>2019-01-28T22:18:37Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 22:18, 28 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot; &gt;Line 87:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 87:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= \frac{1}{3+x^2}&amp;lt;/math&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;math&amp;gt;F(x)= {\rm atan} 3x&amp;lt;/math&amp;gt; and &lt;/ins&gt;&amp;lt;math&amp;gt;F(x)=\frac{1}{3+x^2&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;}-\frac{1}{6&lt;/ins&gt;}&amp;lt;/math&amp;gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Do you need to modify the code to deal with convergence of the iterations for some conditions? Can you understand why some of your attempts converged to a solution, and some did not?&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3127&amp;oldid=prev</id>
		<title>Ilya: /* An example of a model: Solving for an equilibrium position, harder version */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_2&amp;diff=3127&amp;oldid=prev"/>
		<updated>2019-01-28T22:12:30Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;An example of a model: Solving for an equilibrium position, harder version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 22:12, 28 January 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot; &gt;Line 87:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 87:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model building: As before, the equilibrium for the system will be given by &amp;lt;math&amp;gt;\sum {F}=0&amp;lt;/math&amp;gt;. There are now three Coulomb forces acting on the particle from the fixed charges. Let's say the charges are at positions &amp;lt;math&amp;gt;x_1&amp;lt;x_2&amp;lt;x_3&amp;lt;/math&amp;gt;, with charges &amp;lt;math&amp;gt;q_1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q_2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;q_3&amp;lt;/math&amp;gt;, respectively. Let's suppose again that the position of the movable particle is &amp;lt;math&amp;gt;x_1&amp;lt;x&amp;lt;x_2&amp;lt;/math&amp;gt;. Then the solution of the problem will be given by &amp;lt;math&amp;gt;\frac{q_1}{(x-x_1)^2}-\frac{q_2}{(x-x_2)^2}-\frac{q_3}{(x-x_3)^2}=0&amp;lt;/math&amp;gt;. We notice again that the three charges and fixed charge positions are the only things that are needed for the solution. This is equivalent to &amp;lt;math&amp;gt;{q_1}{(x-x_2)^2}(x-x_3)^2-{q_2}{(x-x_1)^2}(x-x_3)^2 -{q_2}{(x-x_2)^2}(x-x_1)^2=0&amp;lt;/math&amp;gt;. This is not a quartic equation in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, and solving this problem would be equivalent to finding the root of this quartic equation between &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_2&amp;lt;/math&amp;gt;. This is going to be more interesting!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&amp;lt;/math&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;Model implementation: We need to find roots of a fourth order polynomial. How do we do this? For this we will introduce the Newton-Raphson method for finding a root of an equation &amp;lt;math&amp;gt;F(x)=0&amp;lt;/math&amp;gt;. Let's suppose that we have a guess &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; for a root. We evaluate the function, &amp;lt;math&amp;gt;F_0=F(x_0)&amp;lt;/math&amp;gt;, and it turns out that the guess is not quite right, &amp;lt;math&amp;gt;F_0\neq 0&amp;lt;/math&amp;gt;. We can then write the Taylor expansion for the function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; for the values of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; around &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. Namely, &amp;lt;math&amp;gt;F(x)\approx F_0 + G_0(x-x_0)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;G_0&amp;lt;/math&amp;gt; is the value of the derivative of &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;G_0=\left(dF/dx\right)_{x_0}&amp;lt;/math&amp;gt;. But then we can get a better estimate of where the root is by solving the equation &amp;lt;math&amp;gt; F_0+G_0(x-x_0)=0&amp;lt;/math&amp;gt;. This would give &amp;lt;math&amp;gt;x_1=x_0-F_0/G_0&amp;lt;/math&amp;gt; for the next estimate. Iterating this, one will get &amp;lt;math&amp;gt;x_{i+1}=x_i -F_i/G_i&amp;lt;/math&amp;gt;. This way we will approach the solution progressively better and better, as we iterate more. At some point we will need to stop the iteration. Usually, this is yet another parameter that one adds to the initialization in the experiment: the tolerance &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for finding the solution. That is, one interrupts the recursion when &amp;lt;math&amp;gt;\left|x_{i+1}-x_i\right|&amp;lt;\epsilon&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/math&amp;gt;. Note that the algorithm will only find a root if it is initialized with the initial guess in its vicinity. So if one wants to find a root, one needs to have good guesses. And to find all roots, one needs to have initial guesses near all of the roots. Even then the solution may not exist -- there is no guarantee that the the iterations converge; they can enter cycles or diverge instead. '''Your work:''' with the provided code implementing the Newton-Raphson method, try to find '''all''' roots of the following functions &amp;lt;math&amp;gt;F(x)= \frac{1}{3+x^2}&lt;/ins&gt;&amp;lt;/math&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
</feed>