<?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_11</id>
	<title>Physics 212, 2019: Lecture 11 - 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_11"/>
	<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_11&amp;action=history"/>
	<updated>2026-04-26T23:47:12Z</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_11&amp;diff=3247&amp;oldid=prev</id>
		<title>Ilya: /* Your work */</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_11&amp;diff=3247&amp;oldid=prev"/>
		<updated>2019-02-17T18:36:11Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Your work&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:36, 17 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-l34&quot; &gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 34:&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;;Problem 1: Find examples (which will involve very large, very small, or relatively small numbers) the violate the distributive property of addition/multiplication.&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;;Problem 1: Find examples (which will involve very large, very small, or relatively small numbers) the violate the distributive property of addition/multiplication.&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;;Problem 2: Write a function that will compare if two floating point numbers are equal to some relative or absolute precision.&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;;Problem 2: Write a function that will compare if two floating point numbers are equal to some relative or absolute precision.&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;==Scripts used==&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;:[[media:ComputationalErrors.txt|Computational errors]] Jupyter notebook, which shows how to get the details of implementation of floating point algebra in your system, and illustrates a few common errors.&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_11&amp;diff=3246&amp;oldid=prev</id>
		<title>Ilya at 18:34, 17 February 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_11&amp;diff=3246&amp;oldid=prev"/>
		<updated>2019-02-17T18:34:34Z</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:34, 17 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-l31&quot; &gt;Line 31:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 31:&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;**Don't compare floating point numbers exactly. Compare them to a certain precision. Your work: write a function that compares if two floating point numbers are equal to a given relative precision (determined by the number with the smallest absolute value).&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;**Don't compare floating point numbers exactly. Compare them to a certain precision. Your work: write a function that compares if two floating point numbers are equal to a given relative precision (determined by the number with the smallest absolute value).&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;&amp;#160; &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;&amp;#160; &amp;#160;&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 class=&quot;diffchange diffchange-inline&quot;&gt;Please [https&lt;/del&gt;:/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;/docs&lt;/del&gt;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;google.com/forms/d/e/1FAIpQLSeNvrPddCgvMfHdlSA8uYDddBFqLK81Rrr4l7jfozud6J7iww/viewform submit your work]&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;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;==Your work==&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 class=&quot;diffchange diffchange-inline&quot;&gt;;Problem 1&lt;/ins&gt;: &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Find examples (which will involve very large, very small, or relatively small numbers) the violate the distributive property of addition&lt;/ins&gt;/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;multiplication&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 class=&quot;diffchange diffchange-inline&quot;&gt;;Problem 2: Write a function that will compare if two floating point numbers are equal to some relative or absolute precision&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_11&amp;diff=3245&amp;oldid=prev</id>
		<title>Ilya: Created page with &quot;{{PHYS212-2019}}  ==Errors in the modeling process== Errors plague modeling process. We have mentioned earlier the Mars Climate Orbiter that crashed due to an error in the uni...&quot;</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_11&amp;diff=3245&amp;oldid=prev"/>
		<updated>2019-02-17T18:31:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{PHYS212-2019}}  ==Errors in the modeling process== Errors plague modeling process. We have mentioned earlier the Mars Climate Orbiter that crashed due to an error in the uni...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{PHYS212-2019}}&lt;br /&gt;
&lt;br /&gt;
==Errors in the modeling process==&lt;br /&gt;
Errors plague modeling process. We have mentioned earlier the Mars Climate Orbiter that crashed due to an error in the unit conversion. However, such errors are maybe not the most common (and definitely avoidable). However, the computational modeling process involves also other types of errors, some of them simply unavoidable.&lt;br /&gt;
&lt;br /&gt;
===Modeling errors===&lt;br /&gt;
Incorrectly constructed model. This can include rather sophisticated errors, such as making wrong assumptions about importance of various effects. Or the errors can be trivial, like simply writing down a wrong form of a interaction law. To find these errors, one must verify the program -- line by line, but also, more crucially, using special simple cases, at least one per independent parameter.&lt;br /&gt;
&lt;br /&gt;
===Implementation (coding) errors===&lt;br /&gt;
Some of these may be notices simply -- like syntactic errors that the interpreter will pick for you. Some may be more complicated and involve incorrect logic (e.g., not initializing variables), and such mistakes are very hard to detect. As above, the only way of doing this is by verifying your program again and again with different parameter values.&lt;br /&gt;
&lt;br /&gt;
===Data errors===&lt;br /&gt;
These are often outside of your control: instruments can have errors, parameter values you read in the literature can have errors, data may be copied with errors, etc. While outside of our control, detecting such errors is also important. Check -- does the data make sense? Is it of correct sign? Of correct magnitude? Does it change in the right fashion? etc.&lt;br /&gt;
&lt;br /&gt;
===Computational errors===&lt;br /&gt;
To understand how these emerge, we need first to understand how real numbers are stored in computer memory. In Python, you can find the functions needed to check how numbers are represented in the module sys.&lt;br /&gt;
*Real number is represented by a mantissa and by exponent.  In general, '''precision''' of a floating point number is the number of significant digits in its mantissa.&lt;br /&gt;
*The little endian vs. the big endian representation of a number. See more here [https://en.wikipedia.org/wiki/Endianness]. Related, for those who haven't read it, I highly recommend [https://en.wikipedia.org/wiki/Gulliver%27s_Travels Gulliver's Travels] book. See sys.byteorder.&lt;br /&gt;
*Single precision floating point number occupies 32 bits (4 bytes), and double precision 64 bits (8 bytes).&lt;br /&gt;
*Double precision number properties can can be found in sys.foat_info (check also sys.long_info).&lt;br /&gt;
**What is the largest and the smallest number available on your computers? (be ready to submit this at the end of the class).&lt;br /&gt;
*Relative error vs absolute error.&lt;br /&gt;
*When numerical operations are done with floating point numbers, '''arithmetic''' errors generally occur. Let's consider examples:&lt;br /&gt;
**Adding two numbers with 3 digit precision. Numbers have to have the same exponents first to be added. Whatever doesn't fit into the new mantissa is '''rounded off''' or '''truncated'''. '''Epsilon''' is the smallest number you can add to 1 and still have a result different from 1. What is epsilon on your computer?&lt;br /&gt;
**Multiplying numbers with 3 digit precision. Again, rounding or truncation errors will happen. Importantly, another common error is possible: overflow or underflow (also possible for addition, but less likely). '''Overflow''' error -- the resulting number too large (in absolute value) to be represented. '''Underflow''' error -- the resulting number is too small (in absolute value) to be represented. ESA Ariane 5 rocket crushed due to an overflow error. &lt;br /&gt;
*Good practice for avoiding arithmetic errors: &lt;br /&gt;
** Don't add small numbers to large numbers. Test this by creating an array of 1e6 in length of numbers 1e-20. Replace the 1000'th entry in the array by 1. Sum the array. You will get 1.0. Now instead sort the array and sum it. What do you get? Why?&lt;br /&gt;
**How should divisions and multiplications be done? There's no one specific sequence, but there is one rule: avoid underflow or overflow. If you need to multiply and divide many numbers, make sure that your divisions and multiplications are ordered in such a way, that you don't get too large or too small numbers in the middle of the process.&lt;br /&gt;
**Don't do many additions when you can do just one multiplication. &lt;br /&gt;
**In general, don't assume that distributive or associative properties are satisfied on a computer.&lt;br /&gt;
**Don't compare floating point numbers exactly. Compare them to a certain precision. Your work: write a function that compares if two floating point numbers are equal to a given relative precision (determined by the number with the smallest absolute value).&lt;br /&gt;
 &lt;br /&gt;
Please [https://docs.google.com/forms/d/e/1FAIpQLSeNvrPddCgvMfHdlSA8uYDddBFqLK81Rrr4l7jfozud6J7iww/viewform submit your work].&lt;/div&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
</feed>