<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Learntofish&#039;s Blog</title>
	<atom:link href="http://learntofish.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://learntofish.wordpress.com</link>
	<description>A blog about math, physics and computer science</description>
	<lastBuildDate>Wed, 25 Jan 2012 21:47:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='learntofish.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Learntofish&#039;s Blog</title>
		<link>http://learntofish.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://learntofish.wordpress.com/osd.xml" title="Learntofish&#039;s Blog" />
	<atom:link rel='hub' href='http://learntofish.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How I learned to code</title>
		<link>http://learntofish.wordpress.com/2012/01/24/how-i-learned-to-code/</link>
		<comments>http://learntofish.wordpress.com/2012/01/24/how-i-learned-to-code/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 00:56:30 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projecteuler]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1852</guid>
		<description><![CDATA[Read this very interesting story by James Somers in which he describes how Projecteuler helped him to finally learn programming. I wrote about Projecteuler earlier here. My first program was on a Vtech laptop for kids. It had a BASIC interpreter. The code required you to specify the lines (yes, good old times) and use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1852&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Read this very interesting <a href="http://www.theatlantic.com/technology/print/2011/06/how-i-failed-failed-and-finally-succeeded-at-learning-how-to-code/239855/">story by James Somers</a> in which he describes how Projecteuler helped him to finally learn programming. I wrote about Projecteuler earlier <a href="http://learntofish.wordpress.com/2009/10/27/improve-your-programming-skills-now/">here</a>.</p>
<p>My first program was on a <a href="http://programmers.stackexchange.com/a/60295">Vtech laptop</a> for kids. It had a BASIC interpreter. The code required you to specify the lines (yes, good old times) and use the goto command to write loops. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1852/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1852/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1852/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1852&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/24/how-i-learned-to-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>The sound of hydrogen</title>
		<link>http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/</link>
		<comments>http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:50:18 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[mathematics]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[minutephysics]]></category>
		<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1841</guid>
		<description><![CDATA[Henry Reich has a series of videos on physics and mathematics each lasting for a minute on his channel minutephysics. He explains topics by using handdrawn pictures and makes them look like an animation. Here are a couple of his excellent videos (among them one that explains how to create the sound of hydrogen):<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1841&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Henry Reich has a series of videos on physics and mathematics each lasting for a minute on his channel <a href="http://www.youtube.com/user/minutephysics">minutephysics</a>. He explains topics by using handdrawn pictures and makes them look like an animation. Here are a couple of his excellent videos (among them one that explains how to create the sound of hydrogen):</p>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/"><img src="http://img.youtube.com/vi/B4UGZEjG02s/2.jpg" alt="" /></a></span>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/"><img src="http://img.youtube.com/vi/IOYyCHGWJq4/2.jpg" alt="" /></a></span>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/"><img src="http://img.youtube.com/vi/qyi5SvPlMXc/2.jpg" alt="" /></a></span>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/"><img src="http://img.youtube.com/vi/IhvW8yZdE5A/2.jpg" alt="" /></a></span>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/"><img src="http://img.youtube.com/vi/ky4RgRvVDoA/2.jpg" alt="" /></a></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1841/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1841&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/20/the-sound-of-hydrogen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>TeXworks: a user friendly LaTeX editor</title>
		<link>http://learntofish.wordpress.com/2012/01/16/texworks-a-user-friendly-latex-editor/</link>
		<comments>http://learntofish.wordpress.com/2012/01/16/texworks-a-user-friendly-latex-editor/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 18:59:39 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[texworks]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1827</guid>
		<description><![CDATA[TeXworks is a LaTeX editor developed by Jonathan Kew. Jonathan gave a talk on his editor: TeXworks for newcomers-and what&#8217;s new for old hands. He designed it with the goal to keep the interface simple, and to make it easier for beginners with getting started. You can watch the talk below (be sure to watch [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1827&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tug.org/texworks/">TeXworks</a> is a LaTeX editor developed by <a href="http://www.tug.org/interviews/kew.html">Jonathan Kew</a>. Jonathan gave a talk on his editor: <a href="http://river-valley.tv/texworks-for-newcomers-and-whats-new-for-old-hands/">TeXworks for newcomers-and what&#8217;s new for old hands</a>. He designed it with the goal to keep the interface simple, and to make it easier for beginners with getting started. You can watch the talk below (be sure to watch it in 480p):</p>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/16/texworks-a-user-friendly-latex-editor/"><img src="http://img.youtube.com/vi/9-Z43CSPgM0/2.jpg" alt="" /></a></span>
<p>&nbsp;</p>
<p><strong>Features</strong><br />
I am very impressed by the features:<br />
- Use &#8220;CTRL+MouseClick&#8221; in the .tex file to see where the corresponding output in the PDF is. Conversely, you can use &#8220;CTRL+MouseClick&#8221; on the PDF to see where this output is generated in the .tex file.<br />
- Auto completion via &#8220;TAB&#8221;. For example type &#8220;\sec&#8221; and TAB and it will complete it to &#8220;\section&#8221;<br />
- A spell checker that ignores the LaTeX code: Go to <em>Edit -&gt; Spelling -&gt; English</em><br />
- LaTeX Error Hook: If you press the green button to create your PDF but you have errors in the .tex file, the green button will turn red.<br />
Just click on the red button and a tab that only shows the errors will appear.</p>
<p><strong>Installation</strong><br />
I discovered TeXworks after installing MiKTeX on Windows. MiKTeX is the LaTeX version for Windows. To install it proceed as follows:<br />
1. Go to <a href="http://miktex.org/">http://miktex.org/</a><br />
2. On the left hand side click on &#8220;Download MiKTeX 2.9&#8243;. Choose for example &#8220;Basic MiKTeX 2.9 Installer&#8221; and start the download.<br />
3. Install MiKTeX after the download. When it asks &#8220;Download packages on the fly&#8221; choose &#8220;Yes&#8221;.<br />
4. After the installation has finished go to: <em>Start -&gt; All programs -&gt; MiKTeX 2.9 -&gt; TeXworks</em></p>
<p>If you already have MiKTeX but not TeXworks you can download TeXworks here: <a href="http://www.tug.org/texworks/">http://www.tug.org/texworks/</a></p>
<p>Before you start I recommend these settings for TeXworks:<br />
- Activate the Syntax Highlighting by clicking on: <em>Format -&gt; Syntax Coloring -&gt; LaTeX</em><br />
- Show the line numbers by clicking on: <em>Format -&gt; Line Numbers</em><br />
- <a href="http://tex.stackexchange.com/questions/21072/how-to-keep-font-preferences-in-texworks-4">Change the font size</a>: Go to <em>Edit -&gt; Preferences -&gt; Editor</em> (and set the font size e.g. to 12 pt)</p>
<p><strong>LaTeX tutorial</strong><br />
If you are completely new to LaTeX I recommend these documents with an emphasis on math symbols:<br />
<a href="http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/">Getting Started with LaTeX</a>, By David R. Wilkins<br />
<a href="http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:Basics">ArtOfProblemSolving LaTeX tutorial</a> (it includes a tutorial on TexnicCenter, another LaTeX editor, but you can ignore that part)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1827/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1827/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1827&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/16/texworks-a-user-friendly-latex-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to Markov Chains</title>
		<link>http://learntofish.wordpress.com/2012/01/15/introduction-to-markov-chains/</link>
		<comments>http://learntofish.wordpress.com/2012/01/15/introduction-to-markov-chains/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 22:34:21 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[mathematics]]></category>
		<category><![CDATA[Markov chain]]></category>
		<category><![CDATA[probability theory]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1764</guid>
		<description><![CDATA[In the following I will give an easy example on Markov Chains. I will assume that you know how to multiply two matrices. Example: Suppose today it&#8217;s Monday and you want to celebrate your birthday on Wednesday with an outdoor party. Of course, you are interested in the weather and you find this data: This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1764&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the following I will give an easy example on Markov Chains. I will assume that you know how to multiply two matrices.</p>
<p><strong>Example:</strong><br />
Suppose today it&#8217;s Monday and you want to celebrate your birthday on Wednesday with an outdoor party. Of course, you are interested in the weather and you find this data:</p>
<p><pre class="brush: plain;">
If sunny today, then tommorow:
                   80% probability for sunny
                   20% probability for rainy

If rainy today, then tomorrow:
                   60% probability for sunny
                   40% probability for rainy
</pre></p>
<p>This data could for example have been collected during summer. Note that the weather tomorrow only depends on the weather from today, so e.g. it does not matter what the weather was a week ago. So today on Monday, you go outside and see that it is a rainy day. Therefore, the probability that it will be sunny tomorrow is 60%. The problem is that your birthday is not tomorrow but in two days on Wednesday. What is the probability then?</p>
<p>A good idea is to visualize the situation as a graph: </p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/markovchain.png"><img src="http://learntofish.files.wordpress.com/2012/01/markovchain.png?w=300&#038;h=92" alt="" title="MarkovChain" width="300" height="92" class="aligncenter size-medium wp-image-1765" /></a></p>
<p>These are the ways to <span id="more-1764"></span>get from <em>rainy(Monday)</em> to <em>sunny(Wednesday)</em>:<br />
a) rainy(Monday) -&gt; sunny(Tuesday) -&gt; sunny(Wednesday)<br />
b) rainy(Monday) -&gt; rainy(Tuesday) -&gt; sunny(Wednesday)</p>
<p>Let&#8217;s calculate the probability for a):<br />
<pre class="brush: plain;">
Transition rainy(Monday) -&gt; sunny(Tueday): 0.6
Transition sunny(Tuesday) -&gt; sunny(Wednesday): 0.8
=&gt; Transition rainy(Monday) -&gt; sunny(Tuesday) -&gt; sunny(Wednesay): 0.6 * 0.8 = 0.48
</pre></p>
<p>Let&#8217;s calculate the probability for b):<br />
<pre class="brush: plain;">
Transition rainy(Monday) -&gt; rainy(Tueday): 0.4
Transition rainy(Tuesday) -&gt; sunny(Wednesday): 0.6
=&gt; Transition rainy(Monday) -&gt; rainy(Tuesday) -&gt; sunny(Wednesay): 0.4 * 0.6 = 0.24
</pre></p>
<p>The total transition probability is therefore: 0.48 + 0.24 = 0.72<br />
In a more formal notation: </p>
<p><pre class="brush: plain;">
p[rainy(Monday)-&gt;sunny(Wednesday)] 

= p[rainy(Monday)-&gt;sunny(Tuesday)-&gt;sunny(Wednesday)] + p[rainy(Monday)-&gt;rainy(Tuesday)-&gt;sunny(Wednesday)]

= p[rainy(Monday)-&gt;sunny(Tuesday)]*p[sunny(Tuesday)-&gt;sunny(Wednesday)] 
+ p[rainy(Monday)-&gt;rainy(Tuesday)]*p[rainy(Tuesday)-&gt;sunny(Wednesday)]

= 0.6*0.8 + 0.4*0.6 
= 0.48 + 0.24
= 0.72
</pre></p>
<p>We could ask other questions:<br />
- What is the probability if we start with <em>sunny(Monday)</em>?<br />
- What is the probability that it will rain on Friday?</p>
<p>It turns out that we can answer these questions easily if we introduce a<em> transition matrix P</em>:</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/transitionmatrix.png"><img src="http://learntofish.files.wordpress.com/2012/01/transitionmatrix.png?w=300&#038;h=201" alt="" title="TransitionMatrix" width="300" height="201" class="aligncenter size-medium wp-image-1793" /></a></p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/transitionmatrix2.png"><img src="http://learntofish.files.wordpress.com/2012/01/transitionmatrix2.png?w=300&#038;h=201" alt="" title="TransitionMatrix2" width="300" height="201" class="aligncenter size-medium wp-image-1796" /></a></p>
<p><img src='http://s0.wp.com/latex.php?latex=P+%3D+++%5Cbegin%7Bbmatrix%7D+++p%28ss%29+%26+p%28sr%29+%5C%5C++p%28rs%29+%26+p%28rr%29+++%5Cend%7Bbmatrix%7D++%3D+++%5Cbegin%7Bbmatrix%7D+++0.8+%26+0.2+%5C%5C++0.6+%26+0.4+++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P =   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  =   &#92;begin{bmatrix}   0.8 &amp; 0.2 &#92;&#92;  0.6 &amp; 0.4   &#92;end{bmatrix}  ' title='P =   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  =   &#92;begin{bmatrix}   0.8 &amp; 0.2 &#92;&#92;  0.6 &amp; 0.4   &#92;end{bmatrix}  ' class='latex' /></p>
<p>p(ij) is the transition probability transition from i to j, e.g. p(sr) is the transition probability from sunny to rainy.<br />
We have calculated the probability for rainy(Monday)-&gt;sunny(Wednesday) before. Let&#8217;s do this again with the transition matrix. To get the probability we just take the second power of P:</p>
<p><img src='http://s0.wp.com/latex.php?latex=P%5E2+%3D+++%5Cbegin%7Bbmatrix%7D+++p%28ss%29+%26+p%28sr%29+%5C%5C++p%28rs%29+%26+p%28rr%29+++%5Cend%7Bbmatrix%7D++%5Ccdot+++%5Cbegin%7Bbmatrix%7D+++p%28ss%29+%26+p%28sr%29+%5C%5C++p%28rs%29+%26+p%28rr%29+++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^2 =   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  &#92;cdot   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  ' title='P^2 =   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  &#92;cdot   &#92;begin{bmatrix}   p(ss) &amp; p(sr) &#92;&#92;  p(rs) &amp; p(rr)   &#92;end{bmatrix}  ' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%3D++%5Cbegin%7Bbmatrix%7D+++p%28ss%29p%28ss%29%2Bp%28sr%29p%28rs%29+%26+p%28ss%29p%28sr%29%2Bp%28sr%29p%28rr%29+%5C%5C++p%28rs%29p%28ss%29%2Bp%28rr%29p%28rs%29+%26+p%28rs%29p%28sr%29%2Bp%28rr%29p%28rr%29+++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='=  &#92;begin{bmatrix}   p(ss)p(ss)+p(sr)p(rs) &amp; p(ss)p(sr)+p(sr)p(rr) &#92;&#92;  p(rs)p(ss)+p(rr)p(rs) &amp; p(rs)p(sr)+p(rr)p(rr)   &#92;end{bmatrix}  ' title='=  &#92;begin{bmatrix}   p(ss)p(ss)+p(sr)p(rs) &amp; p(ss)p(sr)+p(sr)p(rr) &#92;&#92;  p(rs)p(ss)+p(rr)p(rs) &amp; p(rs)p(sr)+p(rr)p(rr)   &#92;end{bmatrix}  ' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%3D++%5Cbegin%7Bbmatrix%7D+++0.8+%5Ccdot+0.8+%2B+0.2+%5Ccdot+0.6+%26+0.8+%5Ccdot+0.2+%2B+0.2+%5Ccdot+0.4++%5C%5C++0.6+%5Ccdot+0.8+%2B+0.4+%5Ccdot+0.6+%26+0.6+%5Ccdot+0.2+%2B+0.4+%5Ccdot+0.4++++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='=  &#92;begin{bmatrix}   0.8 &#92;cdot 0.8 + 0.2 &#92;cdot 0.6 &amp; 0.8 &#92;cdot 0.2 + 0.2 &#92;cdot 0.4  &#92;&#92;  0.6 &#92;cdot 0.8 + 0.4 &#92;cdot 0.6 &amp; 0.6 &#92;cdot 0.2 + 0.4 &#92;cdot 0.4    &#92;end{bmatrix}  ' title='=  &#92;begin{bmatrix}   0.8 &#92;cdot 0.8 + 0.2 &#92;cdot 0.6 &amp; 0.8 &#92;cdot 0.2 + 0.2 &#92;cdot 0.4  &#92;&#92;  0.6 &#92;cdot 0.8 + 0.4 &#92;cdot 0.6 &amp; 0.6 &#92;cdot 0.2 + 0.4 &#92;cdot 0.4    &#92;end{bmatrix}  ' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%3D++%5Cbegin%7Bbmatrix%7D+++0.64%2B0.12++%26+0.16%2B0.08+%5C%5C++0.48%2B0.24++%26+0.12%2B0.16++++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='=  &#92;begin{bmatrix}   0.64+0.12  &amp; 0.16+0.08 &#92;&#92;  0.48+0.24  &amp; 0.12+0.16    &#92;end{bmatrix}  ' title='=  &#92;begin{bmatrix}   0.64+0.12  &amp; 0.16+0.08 &#92;&#92;  0.48+0.24  &amp; 0.12+0.16    &#92;end{bmatrix}  ' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%3D++%5Cbegin%7Bbmatrix%7D+++0.76++%26+0.24+%5C%5C++0.72++%26+0.28++++%5Cend%7Bbmatrix%7D++&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='=  &#92;begin{bmatrix}   0.76  &amp; 0.24 &#92;&#92;  0.72  &amp; 0.28    &#92;end{bmatrix}  ' title='=  &#92;begin{bmatrix}   0.76  &amp; 0.24 &#92;&#92;  0.72  &amp; 0.28    &#92;end{bmatrix}  ' class='latex' /></p>
<p>The probability for <em>rainy(Monday)-&gt;sunny(Wednesday)</em> is in the left bottom corner of the matrix. The value is 72% which is the same as we calculated before.<br />
(Below is a figure of the <img src='http://s0.wp.com/latex.php?latex=P%5E2&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^2' title='P^2' class='latex' /> matrix. The probability for <em>rainy(Monday)-&gt;sunny(Wednesday)</em> is the <img src='http://s0.wp.com/latex.php?latex=P%5E2%28rs%29&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^2(rs)' title='P^2(rs)' class='latex' /> entry.)</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/transitionmatrix3.png"><img src="http://learntofish.files.wordpress.com/2012/01/transitionmatrix3.png?w=300&#038;h=201" alt="" title="TransitionMatrix3" width="300" height="201" class="aligncenter size-medium wp-image-1804" /></a></p>
<p>To answer the other questions:<br />
- What is the probability if we start with <em>sunny(Monday)</em>, i.e. what is the probability for <em>sunny(Monday)-&gt;sunny(Wednesday)</em>?<br />
Answer: Have a look at the top left corner value. The probability is 76%.</p>
<p>- What is the probability that it will rain on Friday, i.e. what is the probability for <em>rainy(Monday)-&gt;sunny(Friday)</em><br />
Answer: If we start on Monday we will have to wait four more days: Tuesday, Wednesday, Thursday and Friday. This corresponds to 4 transitions:<br />
(i) Monday -&gt; Tuesday<br />
(ii) Tuesday -&gt; Wednesday<br />
(iii) Wednesday -&gt; Thursday<br />
(iv) Thursday -&gt; Friday<br />
Thus, calculate <img src='http://s0.wp.com/latex.php?latex=P%5E4&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^4' title='P^4' class='latex' /> and look for the <img src='http://s0.wp.com/latex.php?latex=P%5E4%28rs%29&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^4(rs)' title='P^4(rs)' class='latex' /> entry.</p>
<p>Finally, here is the <strong>definition</strong> of a Markov chain (quoted from reference [3]):</p>
<blockquote><p>A (finite) Markov chain is a process with a finite number of states (or outcomes, or events) in which<br />
the probability of being in a particular state at step n+1 depends only on the state occupied at<br />
step n.</p></blockquote>
<p><strong>Exercises:</strong><br />
a) What is the probability for <em>sunny(Monday)-&gt;sunny(Tuesday)</em><br />
b) What is the probability for <em>sunny(Monday)-&gt;rainy(Wednesday)</em>?<br />
c) Have a look at <img src='http://s0.wp.com/latex.php?latex=P&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P' title='P' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=P%5E2&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^2' title='P^2' class='latex' />. Where do you recognize that the sum of the probabilities equals 1.<br />
d) How do you calculate the probability for <em>rainy(Monday)-&gt;rainy(Thursday)?</em><br />
e) Can you explain why the formalism with the transition matrix works? (Hint: Look at reference [2])</p>
<p><strong>Answers:</strong><br />
a) The probability for <em>sunny(Monday)-&gt;sunny(Tuesday)</em> is P(ss) = 0.8.<br />
b) The probability for  <em>sunny(Monday)-&gt;rainy(Wednesday)</em> is <img src='http://s0.wp.com/latex.php?latex=P%5E2%28sr%29%3D0.24&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^2(sr)=0.24' title='P^2(sr)=0.24' class='latex' /><br />
c) The probabilities in a row add to 1: the final weather is either sunny or rainy.<br />
d) If it is Monday we will have to wait 3 days till Thursday: Tuesday, Wednesday and Thursday.<br />
This corresponds to 3 transitions:<br />
(i) Monday -&gt; Tuesday<br />
(ii) Tuesday -&gt; Wednesday<br />
(iii) Wednesday -&gt; Thursday<br />
Calculate <img src='http://s0.wp.com/latex.php?latex=P%5E3&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^3' title='P^3' class='latex' /> and consider the <img src='http://s0.wp.com/latex.php?latex=P%5E3%28rr%29&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='P^3(rr)' title='P^3(rr)' class='latex' /> entry.</p>
<p>e) To see why the formalism with the transition matrix works consider again our first example.<br />
We wanted to know the probability <em>p[rainy(Monday)-&gt;sunny(Wednesday)]</em> and we found out that there are two paths corresponding to two probabilities:<br />
<pre class="brush: plain;">
(i) p[rainy(Monday)-&gt;sunny(Tuesday)-&gt;sunny(Wednesday)] 
(ii) p[rainy(Monday)-&gt;rainy(Tuesday)-&gt;sunny(Wednesday)]
</pre><br />
We further found out that (i) and (ii) can be written as:<br />
<pre class="brush: plain;">
(i) p[rainy(Monday)-&gt;sunny(Tuesday)]*p[sunny(Tuesday)-&gt;sunny(Wednesday)] = p(rs)*p(ss)
(ii) p[rainy(Monday)-&gt;rainy(Tuesday)]*p[rainy(Tuesday)-&gt;sunny(Wednesday)] = p(rr)*p(rs)
</pre><br />
The sum of both is the probability we are searching for:<br />
<pre class="brush: plain;">
p[rainy(Monday)-&gt;sunny(Wednesday)] = p(rs)*p(ss) + p(rr)*p(rs)
</pre></p>
<p>Now, I will rename the weather states as 1 and 2:<br />
1 stands for sunny<br />
2 stands for rainy</p>
<p><pre class="brush: plain;">
p[2(Monday)-&gt;1(Wednesday)] = p(21)*p(11) + p(22)*p(21)
</pre></p>
<p>In general, if we have an <em>initial state i</em> and a <em>final state j</em> we can write:<br />
<pre class="brush: plain;">
p[i(Monday)-&gt;j(Wednesday)] = p(i1)*p(1j) + p(i2)*p(2j)
</pre> </p>
<p>This should remind you of a matrix multiplication:<br />
Let C = A*B where A,B and C are matrices. Then the <a href="http://en.wikipedia.org/wiki/Matrix_multiplication#Technical_details">matrix multiplication</a> is:</p>
<p><img src='http://s0.wp.com/latex.php?latex=C%28ij%29+%3D+%5Csum_%7Bk%3D1%7D%5En+A%28ik%29B%28kj%29&amp;bg=fafcff&amp;fg=2a2a2a&amp;s=0' alt='C(ij) = &#92;sum_{k=1}^n A(ik)B(kj)' title='C(ij) = &#92;sum_{k=1}^n A(ik)B(kj)' class='latex' /></p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/markovchain_renamed.png"><img src="http://learntofish.files.wordpress.com/2012/01/markovchain_renamed.png?w=300&#038;h=92" alt="" title="MarkovChain_renamed" width="300" height="92" class="aligncenter size-medium wp-image-1824" /></a></p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/transitionmatrix_renamed.png"><img src="http://learntofish.files.wordpress.com/2012/01/transitionmatrix_renamed.png?w=300&#038;h=201" alt="" title="TransitionMatrix_renamed" width="300" height="201" class="aligncenter size-medium wp-image-1825" /></a></p>
<p><strong>References:</strong><br />
<strong>[1]</strong> <a href="http://youtu.be/uvYTGEZQTEs">Introduction to Markov Chains &#8211; Part 1</a><br />
<a href="http://youtu.be/jtHBfLtMq4U">Introduction to Markov Chains, Part 2</a><br />
A youtube video by patrickJMT.</p>
<p><strong>[2]</strong> <a href="http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/book.html">Introduction to Probability (pdf)</a><br />
A book on probability theory by Charles GRINSTEAD and J. Laurie SNELL (see Chapter 11).</p>
<p><strong>[3]</strong> <a href="http://math.colgate.edu/~wweckesser/math312Spring05/handouts/MarkovChains.pdf">Markov Chains (pdf)</a><br />
<a href="http://math.colgate.edu/~wweckesser/math312Spring05/">Lecture notes</a> by Warren Weckesser, Colgate University.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1764/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1764&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/15/introduction-to-markov-chains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/markovchain.png?w=300" medium="image">
			<media:title type="html">MarkovChain</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/transitionmatrix.png?w=300" medium="image">
			<media:title type="html">TransitionMatrix</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/transitionmatrix2.png?w=300" medium="image">
			<media:title type="html">TransitionMatrix2</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/transitionmatrix3.png?w=300" medium="image">
			<media:title type="html">TransitionMatrix3</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/markovchain_renamed.png?w=300" medium="image">
			<media:title type="html">MarkovChain_renamed</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/transitionmatrix_renamed.png?w=300" medium="image">
			<media:title type="html">TransitionMatrix_renamed</media:title>
		</media:content>
	</item>
		<item>
		<title>Great lectures in honor of Feynman</title>
		<link>http://learntofish.wordpress.com/2012/01/14/great-lectures-in-honor-of-feynman/</link>
		<comments>http://learntofish.wordpress.com/2012/01/14/great-lectures-in-honor-of-feynman/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 14:54:40 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[physics]]></category>
		<category><![CDATA[Caltech]]></category>
		<category><![CDATA[Feynman]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[tedxcaltech]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1760</guid>
		<description><![CDATA[Caltech organized an event called TedxCaltech in honor of Richard Feynman. They invited speakers to talk about the person &#8216;Feynman&#8217; and his work. Among them are Leonard Susskind, Michelle Feynman, John Preskill and many more. The talks are excellent. &#160; The complete list of talks can be found here: TedxCaltech: Feynman&#8217;s Vision, the next 50 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1760&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Caltech organized an event called <a href="http://tedxcaltech.com/">TedxCaltech</a> in honor of Richard Feynman. They invited speakers to talk about the person &#8216;Feynman&#8217; and his work. Among them are Leonard Susskind, Michelle Feynman, John Preskill and many more. The talks are excellent.</p>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2012/01/14/great-lectures-in-honor-of-feynman/"><img src="http://img.youtube.com/vi/EqK02xZOXc4/2.jpg" alt="" /></a></span>
<p>&nbsp;</p>
<p>The complete list of talks can be found here: <a href="http://tedxcaltech.com/">TedxCaltech: Feynman&#8217;s Vision, the next 50 years</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1760/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1760/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1760/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1760&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/14/great-lectures-in-honor-of-feynman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>Call by Object Reference (Call by Sharing)</title>
		<link>http://learntofish.wordpress.com/2012/01/09/call-by-object-reference-call-by-sharing/</link>
		<comments>http://learntofish.wordpress.com/2012/01/09/call-by-object-reference-call-by-sharing/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 01:19:10 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[call by object reference]]></category>
		<category><![CDATA[call by sharing]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1693</guid>
		<description><![CDATA[In the following I want to talk about Call by Object Reference also known as Call by Sharing. I will use Python to illustrate the concept. 1. Strange behavior? Let&#8217;s have a look at the following Python code: Save the code in a file callBySharing.py and run it in the Python-Shell (if you use IDLE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1693&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the following I want to talk about <em>Call by Object Reference</em> also known as <em>Call by Sharing</em>. I will use Python to illustrate the concept.</p>
<p><strong>1. Strange behavior?</strong></p>
<p>Let&#8217;s have a look at the following Python code:</p>
<p><pre class="brush: python;">
def changeList1(x):
    x.append(41)

def changeList2(x):
    x = [41,42]
</pre></p>
<p>Save the code in a file <em>callBySharing.py</em> and run it in<span id="more-1693"></span> the Python-Shell (if you use IDLE press F5; if you use a terminal use <em>python -i callBySharing.py</em>). Type the following in the Python-Shell:</p>
<p><pre class="brush: plain;">
&gt;&gt;&gt; myList = [1,2,3]
&gt;&gt;&gt; changeList1(myList)
&gt;&gt;&gt; print(myList)
[1, 2, 3, 41]
</pre></p>
<p>- In line 1 we define a list.<br />
- In line 2 we passed the list to the function <em>changeList1()</em>. If you look at the definition of <em>changeList1()</em> you will recognize that it tries to append the value 41 to the list.<br />
- In line 3 we print the list and see that the value 41 indeed is appended to the list.<br />
- As the name of the function <em>changeList1()</em> suggests we have been successful in changing the list.</p>
<p>Now, continue in the Python-Shell:</p>
<p><pre class="brush: plain;">
&gt;&gt;&gt; yourList = [5,6,7]
&gt;&gt;&gt; changeList2(yourList)
&gt;&gt;&gt; print(yourList)
[5, 6, 7]
&gt;&gt;&gt;
</pre></p>
<p>- In line 1 we create a list.<br />
- In line 2 we pass the list to the function <em>changeList2()</em>. If you look at the definition of <em>changeList2()</em> <em>it seems</em> that it tries to change the list to [41,42].<br />
- In line 3 we print the list and see that it has not changed.</p>
<p><strong>2. Analyzing the functions</strong></p>
<p>So, why did <em>changeList1()</em> modify the list and <em>changeList2()</em> not? To understand this let&#8217;s write the functions in another way. We will introduce a refCopy variable that illustrates a copy procedure (which is not visible).</p>
<p><pre class="brush: python;">
def changeList1b(ref):
    refCopy = ref
    refCopy.append(41)

def changeList2b(ref):
    refCopy = ref
    refCopy = [41,42]
</pre></p>
<p>Add the code to the file <em>callBySharing.py</em> and run it again in the Python-Shell. Then type the following in the Python-Shell:</p>
<p><pre class="brush: plain;">
&gt;&gt;&gt; myList = [1,2,3]
&gt;&gt;&gt; changeList1b(myList)
&gt;&gt;&gt; print(myList)
[1, 2, 3, 41]
&gt;&gt;&gt;
&gt;&gt;&gt; yourList = [5,6,7]
&gt;&gt;&gt; changeList2b(yourList)
&gt;&gt;&gt; print(yourList)
[5, 6, 7]
&gt;&gt;&gt;
</pre></p>
<p>- In line 01-04 we used <em>changeList1b()</em> and were successful in modifying the list.<br />
- In line 06-09 we used <em>changeList2b()</em> and were not successful in modifying the list.<br />
So, we have the same behaviour as before but the new functions make it easier to see what is going on.</p>
<p>Let&#8217;s analyze the function <em>changeList1b()</em> by having a look at its definition:<br />
- In line 1 we define its name.<br />
- In line 2 we define <em>refCopy = ref</em>. Keep in mind that a reference is just something that contains a memory address of an object. For example, in the figure below the value of <em>ref</em> is the address of the object [1,2,3]. The address could be 49838280. With <em>refCopy = ref</em> we copy the address 49838280 and assign it to <em>refCopy</em>. In the figure you can see the result: we now have two references pointing to the same object, namely [1,2,3]. This is also known as <em>object sharing</em> since both references, <em>ref</em> and <em>refCopy</em>, share the same object.<br />
- In line 3 we write <em>refCopy.append(41)</em>. This just means the following: On the right hand side we have the value 41 and try to append this value to the object that <em>refCopy</em> is pointing to. We know from the figure below that <em>refCopy</em> is pointing to the list [1,2,3], therefore 41 is appended.</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/mylist.png"><img src="http://learntofish.files.wordpress.com/2012/01/mylist.png?w=300&#038;h=266" alt="" title="myList" width="300" height="266" class="aligncenter size-medium wp-image-1718" /></a></p>
<p>Now, let&#8217;s analyze the function <em>changeList2b()</em> by having a look at its definition:<br />
- In line 5 we define its name.<br />
- In line 6 we write <em>refCopy = ref</em>, i.e. we copy the value of <em>ref</em> and assign it to <em>refCopy</em>. For example, the address of <em>ref</em> is 43857600 which is then assigned to <em>refCopy</em>.<br />
- In line 7 we write <em>refCopy = [41,42]</em>. On the right hand side we create a <em>new object</em> [41,42]. With <em>refCopy = [41,42]</em> we tell <em>refCopy</em> to point to this new object, i.e. the value of <em>refCopy</em> is not 43857600 anymore (this is the crucial point!). The new value of refCopy is the address of the object [41,42] which is 43932368 (see figure below).<br />
As you can see in the figure below, the reference <em>yourList</em> still points to [5,6,7].</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/yourlist.png"><img src="http://learntofish.files.wordpress.com/2012/01/yourlist.png?w=300&#038;h=266" alt="" title="yourList" width="300" height="266" class="aligncenter size-medium wp-image-1719" /></a></p>
<p>We saw that the value of a reference (an address) is copied. This is known as <em>call by object reference</em> or <em>call by sharing</em>. </p>
<p><strong>3. An exercise</strong><br />
Let&#8217;s write a third version of the function:<br />
<pre class="brush: python;">
def changeList3(x):
    x+=[2012,2013]  # append two values to the list
</pre><br />
Here, we try to append the values 2012 and 2013 to the list. Your task:<br />
a) Pass a list to this function and find out whether the list is changed.<br />
b) Create a drawing of the references and objects that shows what happens.</p>
<p><strong>Solution:</strong><br />
a) Save the code for changeList3() in the file <em>callBySharing.py</em>. Then, type the following in the Python-Shell:<br />
<pre class="brush: plain;">
&gt;&gt;&gt; myList = [1,2,3]
&gt;&gt;&gt; changeList3(myList)
&gt;&gt;&gt; print(myList)
[1, 2, 3, 2012, 2013]
</pre><br />
Line 4 shows that the list is changed. </p>
<p>b) This is a drawing of the references and objects. The address is made up.<br />
Note: Although there is no <em>refCopy</em> in the definition of changeList3() you can imagine that the computer uses this. It&#8217;s just not visible to us.</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/mylist3.png"><img src="http://learntofish.files.wordpress.com/2012/01/mylist3.png?w=300&#038;h=244" alt="" title="myList3" width="300" height="244" class="aligncenter size-medium wp-image-1729" /></a></p>
<p><strong>4. Immutable objects &#8211; Strings and Numbers</strong><br />
Let&#8217;s try to change a string in a similar manner as <em>changeList3()</em>:<br />
<pre class="brush: python;">
def changeString(x):
    x+='World!'     # try to append 'World!' to the string
</pre><br />
Note how the code looks similar to changeList3().</p>
<p>Save this function in the file <em>callBySharing.py</em> and run it in the Python-Shell. Then type the following in the Python-Shell:</p>
<p><pre class="brush: plain;">
&gt;&gt;&gt; myString = 'Hello'
&gt;&gt;&gt; changeString(myString)
&gt;&gt;&gt; print(myString)
Hello
</pre></p>
<p>- In line 1 we created a reference <em>myString</em> to the object &#8216;Hello&#8217;.<br />
- In line 2 we pass <em>myString</em> to the function <em>changeString()</em>. From the definition of the function <em>changeString()</em> we hope that &#8216;World&#8217; is appended.<br />
- In line 3 we print myString but we see in line 4 that &#8216;World&#8217; is not appended. </p>
<p>Although we did the same thing as in changeList3() we still couldn&#8217;t change the object &#8216;Hello&#8217;. The reason is that strings are immutable objects, i.e. you can&#8217;t change the object.</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/mystring.png"><img src="http://learntofish.files.wordpress.com/2012/01/mystring.png?w=300&#038;h=266" alt="" title="myString" width="300" height="266" class="aligncenter size-medium wp-image-1731" /></a></p>
<p>&#8212;&#8212;</p>
<p>In Python everything is an object, even simple things like integers. You can confirm this by typing the following in the Python-Shell:<br />
<pre class="brush: plain;">
&gt;&gt;&gt; b = 42
&gt;&gt;&gt; print(id(b))
505498648
&gt;&gt;&gt; b = 99
&gt;&gt;&gt; print(id(b))
505499560
</pre></p>
<p>- In line 1 we have a reference b that points to the object with value 42.<br />
- In line 2 we check the address of the object that b is pointing to. It is 505498648.<br />
- In line 3 we create a new object with value 99. With b = 99 the reference points now to this new object.<br />
- In line 4 we check the address of the object b is pointing to. We see that the address is now 505499560. </p>
<p>Now, similarly to changeList3() we try to modify a number:<br />
<pre class="brush: python;">
def changeNum(x):
    x+=3       # try to increase x by 3
</pre></p>
<p>Save this function in the file <em>callBySharing.py</em> and run it in the Python-Shell. Then type the following in the Python-Shell:</p>
<p><pre class="brush: plain;">
&gt;&gt;&gt; myNumber = 77
&gt;&gt;&gt; changeNum(myNumber)
&gt;&gt;&gt; print(myNumber)
77
</pre></p>
<p>Line 4 shows that the object 77 is not changed. This is because numbers are <em>immutable</em> objects.</p>
<p><a href="http://learntofish.files.wordpress.com/2012/01/mynumber.png"><img src="http://learntofish.files.wordpress.com/2012/01/mynumber.png?w=300&#038;h=271" alt="" title="myNumber" width="300" height="271" class="aligncenter size-medium wp-image-1743" /></a></p>
<p><strong>References:</strong> (no pun intended)<br />
<strong>1.</strong> <a href="http://www.python-course.eu/passing_arguments.php">Parameter Passing</a><br />
This article is part of an online Python couse.</p>
<p><strong>2.</strong> <a href="http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference">Python: How do I pass a variable by reference?</a><br />
This is a discussion on stackoverflow.com. </p>
<p><strong>3.</strong> <a href="http://stackoverflow.com/questions/40480/is-java-pass-by-reference">Is Java pass by reference?</a><br />
This is a nice discussion on call by object reference, and although it is on Java the same applies to Python. I found two posts particularly helpful: <a href="http://stackoverflow.com/questions/40480/is-java-pass-by-reference/73021#73021">post1 </a>and <a href="http://stackoverflow.com/questions/40480/is-java-pass-by-reference/7034719#7034719">post2</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1693/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1693/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1693/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1693&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/09/call-by-object-reference-call-by-sharing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/mylist.png?w=300" medium="image">
			<media:title type="html">myList</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/yourlist.png?w=300" medium="image">
			<media:title type="html">yourList</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/mylist3.png?w=300" medium="image">
			<media:title type="html">myList3</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/mystring.png?w=300" medium="image">
			<media:title type="html">myString</media:title>
		</media:content>

		<media:content url="http://learntofish.files.wordpress.com/2012/01/mynumber.png?w=300" medium="image">
			<media:title type="html">myNumber</media:title>
		</media:content>
	</item>
		<item>
		<title>More on Bell&#8217;s Theorem</title>
		<link>http://learntofish.wordpress.com/2012/01/06/more-on-bells-theorem/</link>
		<comments>http://learntofish.wordpress.com/2012/01/06/more-on-bells-theorem/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 17:04:24 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[physics]]></category>
		<category><![CDATA[Bell's theorem]]></category>
		<category><![CDATA[EPR]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1675</guid>
		<description><![CDATA[In a previous post I shared some links with easy explanations on Bell&#8217;s theorem. Here, I want to continue although the explanations are more technical and require more knowledge: 11) Nonlocal correlations between the Canary Islands This is an excellent blogpost on the blog BackReaction. It discusses the role of nonlocality in Bell&#8217;s theorem, in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1675&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://learntofish.wordpress.com/2011/12/21/bells-theorem-easy-explained/">previous post</a> I shared some links with easy explanations on Bell&#8217;s theorem. Here, I want to continue although the explanations are more technical and require more knowledge:</p>
<p><strong>11)</strong> <a href="http://backreaction.blogspot.com/2011/06/nonlocal-correlations-between-canary.html">Nonlocal correlations between the Canary Islands</a><br />
This is an excellent blogpost on the blog <a href="http://backreaction.blogspot.com/">BackReaction</a>. It discusses the role of nonlocality in Bell&#8217;s theorem, in particular the locality loophole and the freedom-of-choice loophole.<br />
Prerequisite: Understanding of <a href="http://en.wikipedia.org/wiki/Light_cone">light cones</a>. Here are some <a href="http://www.scar.utoronto.ca/~pat/fun/RELATVTY/TUTORIAL/tutorial.html">practice questions</a> on light cones.</p>
<p><strong>12)</strong> <a href="http://www.phys.washington.edu/users/schick/325A/mermin.pdf">Is the moon there when nobody looks? Reality and the quantum theory</a><br />
This is a very intuitive article by David Mermin. He introduces machines that have 3 settings and two lamps (red and green) and shows that assigning 3 &#8220;real&#8221; properties to particles results in a contradiction. </p>
<p><strong>13)</strong> <a href="http://youtu.be/ta09WXiUqcQ">Spooky Actions At A Distance?: Oppenheimer Lecture</a><br />
A lecture by David Mermin on EPR and Bell&#8217;s theorem. Here, he uses three entangled particles (see <a href="http://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state">Greenberger–Horne–Zeilinger </a>state) instead of two. I recommend watching this lecture after you have read <strong>12)</strong>.</p>
<p><strong>14)</strong> <a href="http://cdsweb.cern.ch/record/142461">Bertlmann&#8217;s socks and the nature of reality</a><br />
by John Stewart Bell<br />
Here, John Bell derives the d&#8217;Espagnat inequality by considering socks that may or may not survive one thousand washing cycles at 45°C, 90°C and 90°C. </p>
<p>The d&#8217;Espagnat inequality is: N(A,notB)+N(B,notC)≥N(A,notC)<br />
Bell mentions that this is trivial: Each member in N(A,notC) on the right hand side either doesn&#8217;t have property B and therefore is in N(A,notB) or has property B and therefore is in N(B,notC). Thus, the left hand side cannot be less than the right hand side, in other words the left hand side is greater or equal than the right hand side.<br />
Note: When you read the document don&#8217;t wonder about the figures. They are not missing but shown in the end.<br />
By the way, Reinhold Bertlmann was a colleague of John Bell at CERN. He is a <a href="http://homepage.univie.ac.at/reinhold.bertlmann/">professor now</a> and still seems to wear <a href="http://homepage.univie.ac.at/reinhold.bertlmann/socks.html">differently coloured socks</a>.<br />
Bell&#8217;s original paper (see <a href="http://www.drchinese.com/David/EPR_Bell_Aspect.htm">DrChinese&#8217;s site</a>) becomes much more understandable with this document.</p>
<p><strong>15)</strong> <a href="http://youtu.be/yADcuGPphkY">Part 1 &#8211; From Bell&#8217;s Inequalities to Entangled Qubits: A New Quantum Age?</a><br />
This is a talk by Alain Aspect who conducted some experiments on Bell&#8217;s theorem. There are five parts.</p>
<p><strong>16)</strong> Hidden variable &#8211; Derivation of line<br />
In his talk Alain Aspect shows that one can construct a hidden variable theory that predicts a line for the expectation value. An easy to follow derivation can be found in <a href="http://books.google.pt/books?id=rMGqMyFBcL8C&amp;pg=PA148&amp;hl=de&amp;source=gbs_toc_r&amp;cad=4#v=onepage&amp;q&amp;f=false">Quantum theory: concepts and methods</a> by Asher Peres on page 161-162.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1675/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1675/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1675/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1675&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2012/01/06/more-on-bells-theorem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>Inspiring advice from Marissa Mayer</title>
		<link>http://learntofish.wordpress.com/2011/12/27/inspiring-advice-from-marissa-mayer/</link>
		<comments>http://learntofish.wordpress.com/2011/12/27/inspiring-advice-from-marissa-mayer/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 14:20:21 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[commencement]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Marissa Mayer]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1662</guid>
		<description><![CDATA[Watch the inspiring commencement given by Marissa Mayer below.  She is vice-president for search products and user experience at Google. &#160; Advice from Marissa Mayer: 1. Find something you are really passionate about. 2. &#8220;It&#8217;s not what Zoon knows but how Zoon thinks&#8221; Knowledge is not as important as the ability to view things in a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1662&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Watch the inspiring commencement given by <a href="http://en.wikipedia.org/wiki/Marissa_Mayer">Marissa Mayer</a> below.  She is vice-president for search products and user experience at Google.</p>
<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2011/12/27/inspiring-advice-from-marissa-mayer/"><img src="http://img.youtube.com/vi/jaKoMCujc2k/2.jpg" alt="" /></a></span>
<p>&nbsp;</p>
<p>Advice from Marissa Mayer:</p>
<blockquote><p>1. Find something you are really passionate about.</p>
<p>2. &#8220;It&#8217;s not what Zoon knows but how Zoon thinks&#8221;<br />
Knowledge is not as important as the ability to view things in a different way.<br />
Become a good problem solver instead of a memorizer.</p>
<p>3. Find the smartest people you can and surround yourself with them.</p>
<p>4. Find allies rather than adorers.</p>
<p>5. Find the courage to do things you are not ready to do.</p>
<p>6. Find places where you are comfortable.</p>
<p>7. Help other find things. Be an information foundtain.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1662/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1662/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1662&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2011/12/27/inspiring-advice-from-marissa-mayer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>Fear Is the Mind-Killer</title>
		<link>http://learntofish.wordpress.com/2011/12/27/fear-is-the-mind-killer/</link>
		<comments>http://learntofish.wordpress.com/2011/12/27/fear-is-the-mind-killer/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 10:33:26 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[dune]]></category>
		<category><![CDATA[Fear]]></category>
		<category><![CDATA[mind-killer]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1653</guid>
		<description><![CDATA[&#160; After having watched the video above one of the youtube commenters posted something interesting: I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1653&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<span style="text-align:center; display: block;"><a href="http://learntofish.wordpress.com/2011/12/27/fear-is-the-mind-killer/"><img src="http://img.youtube.com/vi/nKQbPYdx0fM/2.jpg" alt="" /></a></span>
<p>&nbsp;</p>
<p>After having watched the video above one of the youtube commenters posted something interesting:</p>
<blockquote><p>I must not fear.<br />
Fear is the mind-killer.<br />
Fear is the little-death that brings total obliteration.<br />
I will face my fear.<br />
I will permit it to pass over me and through me.<br />
And when it has gone past I will turn the inner eye to see its path.<br />
Where the fear has gone there will be nothing.<br />
Only I will remain.</p></blockquote>
<p>I looked it up and found out that it&#8217;s from <a href="http://en.wikiquote.org/wiki/Dune">Dune</a>, also known as <a href="http://en.wikipedia.org/wiki/Bene_Gesserit#Litany_against_fear">Litany against Fear</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1653/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1653/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1653/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1653&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2011/12/27/fear-is-the-mind-killer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
		<item>
		<title>Tutorial: Object Oriented Programming in Python – Part 10</title>
		<link>http://learntofish.wordpress.com/2011/12/26/tutorial-object-oriented-programming-in-python-part-10/</link>
		<comments>http://learntofish.wordpress.com/2011/12/26/tutorial-object-oriented-programming-in-python-part-10/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 23:01:02 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[pydev]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://learntofish.wordpress.com/?p=1614</guid>
		<description><![CDATA[This is the continuation of the Python OOP tutorial. Today I want to describe how you can use Python in Eclipse by installing PyDev. Here, I will assume you have Eclipse installed and some familiarity with it. Eclipse is a wonderful IDE known to Java users. I like it because of its auto-completion feature, e.g. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1614&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the continuation of the <a href="http://learntofish.wordpress.com/2011/12/04/tutorial-object-oriented-programming-in-python/">Python OOP tutorial</a>. Today I want to describe how you can use Python in Eclipse by installing <a href="http://pydev.org/index.html">PyDev</a>. Here, I will assume you have Eclipse installed and some familiarity with it.</p>
<p>Eclipse is a wonderful IDE known to Java users. I like it because of its auto-completion feature, e.g. if you use the dot operator on<span id="more-1614"></span> an object, Eclipse will show you the available methods. You can use Python in <a href="http://www.eclipse.org/">Eclipse</a> by installing PyDev. To install PyDev follow the instructions here: <a href="http://pydev.org/manual_101_install.html">Installing PyDev Manual</a>. Or watch this <a href="http://youtu.be/eSkNj2ACTRQ">youtube video</a>.</p>
<p>1. <a href="http://pydev.org/manual_101_project_conf.html">Create a project</a> (follow the instructions there)<br />
2. <a href="http://pydev.org/manual_101_first_module.html">Create a module</a> (follow the instructions there)<br />
3. In example.py paste the following code:<br />
<pre class="brush: python;">
class Airplane:
    __fuel = 0
    maxFuel = 24000
    
    def addFuel(self, volume):
        if(self.__fuel + volume &lt;= 24000):
            self.__fuel = self.__fuel + volume
        else:
            print(&quot;Error: You are adding too much fuel!&quot;)
            print(&quot;Fuelling not possible!&quot;)
        self.__printStatus()

    def __printStatus(self):
        print(&quot;Current fuel:&quot;, self.__fuel)
</pre><br />
That&#8217;s the code from the last tutorial (module aircraft.py). Now, we don&#8217;t want to use the Python-Shell but instead write our commands in a function <em>myProgram()</em> (see <a href="http://learntofish.wordpress.com/2011/12/10/tutorial-object-oriented-programming-in-python-part-6/">part 6</a>).</p>
<p>So, add the following to example.py (add lines 17-22):<br />
<pre class="brush: python;">
class Airplane:
    __fuel = 0
    maxFuel = 24000
    
    def addFuel(self, volume):
        if(self.__fuel + volume &lt;= 24000):
            self.__fuel = self.__fuel + volume
        else:
            print(&quot;Error: You are adding too much fuel!&quot;)
            print(&quot;Fuelling not possible!&quot;)
        self.__printStatus()

    def __printStatus(self):
        print(&quot;Current fuel:&quot;, self.__fuel)


def myProgram():
    airbus = Airplane()
    airbus.addFuel(20000)
    
if __name__ == '__main__':
    myProgram()
</pre><br />
- Notice what happens when you type &#8220;airbus.&#8221;. Eclipse recognizes that you want to use the dot operator. It will then show you the attributes and methods of the object.<br />
- Choose the <em>addFuel</em> method and press ENTER. This is called <em>auto-completion</em> which means that Eclipse completed the code for you.<br />
- Finally, <a href="http://pydev.org/manual_101_run.html">run the program</a> (follow instructions there). If you&#8217;ve done everything correctly the console output should read:<br />
<pre class="brush: plain;">
Current fuel: 20000
</pre></p>
<p><strong>Note:</strong><br />
There is also an auto-completion in IDLE. You can test it in IDLE by running the aircraft.py module from last time in the Python-Shell (use F5). Then type the following in the Python-Shell:<br />
<pre class="brush: plain;">
&gt;&gt;&gt; a = Airplane()
&gt;&gt;&gt; a.
</pre><br />
- Don&#8217;t press ENTER after the dot!<br />
- Now, press CTRL+SPACE. The options <em>addFuel</em> and <em>maxFuel</em> should appear. You can choose one of them by pressing up or down. Choose <em>addFuel</em>.<br />
- Don&#8217;t press ENTER! Instead press the bracket <strong>(</strong> key. IDLE will then auto-complete the code for you, i.e. it will paste <strong>addFuel(</strong> for you. The result should be:<br />
<pre class="brush: plain;">
&gt;&gt;&gt; a.addFuel(
</pre><br />
- Finally, type <strong>20000)</strong> and press ENTER.<br />
- So, by using CTRL+SPACE you didn&#8217;t have to type <strong>addFuel(</strong>.<br />
However, using CTRL+SPACE can crash IDLE (I encountered this in a Linux version). Just try if it works for you.<br />
- In IDLE, I couldn&#8217;t use the auto-completion outside the Python-Shell as in Eclipse. I noticed this when I wrote the myProgram() function in IDLE and no auto-complete was available for the object <em>airbus</em>. (If auto-completion for objects outside of the Python-Shell is possible please write a comment below and let me know)  </p>
<p><strong>Note2:</strong><br />
The only thing that I miss in PyDev/Eclipse is running a file (e.g. example.py or aircraft.py) in a Python-Shell. In IDLE you can simply press F5. However, in PyDev I have not yet discovered such a feature (in case I missed the feature let me know).</p>
<p><strong>References:</strong><br />
<a href="http://pydev.org/manual_101_root.html">Official PyDev Getting Started Guide</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/learntofish.wordpress.com/1614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/learntofish.wordpress.com/1614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/learntofish.wordpress.com/1614/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=learntofish.wordpress.com&amp;blog=8542538&amp;post=1614&amp;subd=learntofish&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://learntofish.wordpress.com/2011/12/26/tutorial-object-oriented-programming-in-python-part-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/27943693bb3fa766ba03db41d5fd85f9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">learntofish</media:title>
		</media:content>
	</item>
	</channel>
</rss>
