<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://eclr.humanities.manchester.ac.uk/index.php?action=history&amp;feed=atom&amp;title=G_Graphing_Treat</id>
		<title>G Graphing Treat - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://eclr.humanities.manchester.ac.uk/index.php?action=history&amp;feed=atom&amp;title=G_Graphing_Treat"/>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=G_Graphing_Treat&amp;action=history"/>
		<updated>2026-04-12T23:31:46Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.1</generator>

	<entry>
		<id>http://eclr.humanities.manchester.ac.uk/index.php?title=G_Graphing_Treat&amp;diff=3925&amp;oldid=prev</id>
		<title>Rb: /* Lorenz Attractor */</title>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=G_Graphing_Treat&amp;diff=3925&amp;oldid=prev"/>
				<updated>2015-07-31T09:09:08Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Lorenz Attractor&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 style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:09, 31 July 2015&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-l7&quot; &gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Think of a little fly which moves, as they do, in a three dimensional space (think in terms of x, y and z dimensions). And let&amp;#039;s say that you are actually mind controlling this fly. As you are a mathematical fiend you write down a very specific rule how the position of that fly changes from second to second. That means you have to write down differential equations.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Think of a little fly which moves, as they do, in a three dimensional space (think in terms of x, y and z dimensions). And let&amp;#039;s say that you are actually mind controlling this fly. As you are a mathematical fiend you write down a very specific rule how the position of that fly changes from second to second. That means you have to write down differential equations.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; 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;Here is the equation for X: &amp;lt;math&amp;gt;dx = \sigma(y-x) dt&amp;lt;/math&amp;gt; Here is the equation for &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;X&lt;/del&gt;: &amp;lt;math&amp;gt;dy = (x(\rho-z)-y) dt&amp;lt;/math&amp;gt; Here is the equation for Z: &amp;lt;math&amp;gt;dz = (xy-\beta z) dt&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; 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;Here is the equation for X: &amp;lt;math&amp;gt;dx = \sigma(y-x) dt&amp;lt;/math&amp;gt; Here is the equation for &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Y&lt;/ins&gt;: &amp;lt;math&amp;gt;dy = (x(\rho-z)-y) dt&amp;lt;/math&amp;gt; Here is the equation for Z: &amp;lt;math&amp;gt;dz = (xy-\beta z) dt&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;these equations are called the [https://en.wikipedia.org/wiki/Lorenz_system Lorenz equations] and they give precise instructions how the coordinates for &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt; change in every time interval &amp;lt;math&amp;gt;dt&amp;lt;/math&amp;gt;. So let&amp;#039;s implement this in R (The code for this example comes from [http://fractalswithr.blogspot.co.uk/2007/04/lorenz-attractor.html?m=1 Atte Tenkanen]). We will essentially let the fly fly and record its position as it flies and then we will plot the flight path in a cool picture.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;these equations are called the [https://en.wikipedia.org/wiki/Lorenz_system Lorenz equations] and they give precise instructions how the coordinates for &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt; change in every time interval &amp;lt;math&amp;gt;dt&amp;lt;/math&amp;gt;. So let&amp;#039;s implement this in R (The code for this example comes from [http://fractalswithr.blogspot.co.uk/2007/04/lorenz-attractor.html?m=1 Atte Tenkanen]). We will essentially let the fly fly and record its position as it flies and then we will plot the flight path in a cool picture.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rb</name></author>	</entry>

	<entry>
		<id>http://eclr.humanities.manchester.ac.uk/index.php?title=G_Graphing_Treat&amp;diff=3924&amp;oldid=prev</id>
		<title>Rb: Created page with &quot;= Introduction and Setup =  Creating graphs can be increadibly pleasing, but often it will be very simple graphs that support the story you are telling with your data. Here I...&quot;</title>
		<link rel="alternate" type="text/html" href="http://eclr.humanities.manchester.ac.uk/index.php?title=G_Graphing_Treat&amp;diff=3924&amp;oldid=prev"/>
				<updated>2015-07-31T09:08:45Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Introduction and Setup =  Creating graphs can be increadibly pleasing, but often it will be very simple graphs that support the story you are telling with your data. Here I...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Introduction and Setup =&lt;br /&gt;
&lt;br /&gt;
Creating graphs can be increadibly pleasing, but often it will be very simple graphs that support the story you are telling with your data. Here I want to give you the opportunity to go just a little crazy and be in awe of a graph you create. Just indulge me!&lt;br /&gt;
&lt;br /&gt;
= Lorenz Attractor =&lt;br /&gt;
&lt;br /&gt;
Think of a little fly which moves, as they do, in a three dimensional space (think in terms of x, y and z dimensions). And let&amp;#039;s say that you are actually mind controlling this fly. As you are a mathematical fiend you write down a very specific rule how the position of that fly changes from second to second. That means you have to write down differential equations.&lt;br /&gt;
&lt;br /&gt;
Here is the equation for X: &amp;lt;math&amp;gt;dx = \sigma(y-x) dt&amp;lt;/math&amp;gt; Here is the equation for X: &amp;lt;math&amp;gt;dy = (x(\rho-z)-y) dt&amp;lt;/math&amp;gt; Here is the equation for Z: &amp;lt;math&amp;gt;dz = (xy-\beta z) dt&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
these equations are called the [https://en.wikipedia.org/wiki/Lorenz_system Lorenz equations] and they give precise instructions how the coordinates for &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt; change in every time interval &amp;lt;math&amp;gt;dt&amp;lt;/math&amp;gt;. So let&amp;#039;s implement this in R (The code for this example comes from [http://fractalswithr.blogspot.co.uk/2007/04/lorenz-attractor.html?m=1 Atte Tenkanen]). We will essentially let the fly fly and record its position as it flies and then we will plot the flight path in a cool picture.&lt;br /&gt;
&lt;br /&gt;
Here is the prep, as we need the &amp;#039;&amp;#039;scatterplot3d&amp;#039;&amp;#039; package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;# install.packages(&amp;amp;quot;scatterplot3d&amp;amp;quot;) # Install if needed.&lt;br /&gt;
library(scatterplot3d)&amp;lt;/pre&amp;gt;&lt;br /&gt;
First, let&amp;#039;s set some parameters and the size of the time step. Later you can change these around and see how the result changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;sigma=5; rho=28; beta=8/3; dt=0.01&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then we need the initial coordinates&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;X=0.01; Y=0.01; Z=0.01&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now let&amp;#039;s set for how many time steps &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; we want to follow our imaginary fly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;n=60000&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we define a matrix with &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; rows and 3 columns (representing &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Z&amp;lt;/code&amp;gt;), one row for each moment in time. In here we will save the positional coordinates of our fly at each of our &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; points of time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;XYZ=array(0,dim=c(n,3))&lt;br /&gt;
t=0   # set time to 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here is the core of the code. We are using a &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loop to iterate through our &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; moments in time. You should recognise the above Lorenz equations in the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;for(i in 1:n)&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
X1=X; Y1=Y; Z1=Z  # Set X1, Y1 and Z1 to the last position&lt;br /&gt;
&lt;br /&gt;
X=X1+(sigma*(Y1-X1))*dt&lt;br /&gt;
Y=Y1+(X1*(rho-Z1)-Y1)*dt&lt;br /&gt;
Z=Z1+(X1*Y1-beta*Z1)*dt&lt;br /&gt;
#t=t+dt&lt;br /&gt;
XYZ[i,]=c(X,Y,Z)  # save the current positional coordinates in the ith row&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
All the calculations are been done now. All we do now is to define three vectors &amp;lt;code&amp;gt;xpos&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ypos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;zpos&amp;lt;/code&amp;gt; with the relevant positions. We draw that info from the &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; matrix&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;xpos = XYZ[,1]&lt;br /&gt;
ypos = XYZ[,2]&lt;br /&gt;
zpos = XYZ[,3]&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can plot the positions of our fly through time. We need a three dimensional scatterplot (which is why we had to load the &amp;#039;&amp;#039;scatterplot3d&amp;#039;&amp;#039; package). I will not go through all the options that have been chosen here. You can play around with them a bit to find out what they do.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;s3d&amp;amp;lt;-scatterplot3d(xpos, ypos, zpos, highlight.3d=TRUE, xlab=&amp;amp;quot;x&amp;amp;quot;,ylab=&amp;amp;quot;y&amp;amp;quot;,zlab=&amp;amp;quot;z&amp;amp;quot;,type=&amp;amp;quot;p&amp;amp;quot;, col.axis=&amp;amp;quot;blue&amp;amp;quot;, angle=55, col.grid=&amp;amp;quot;lightblue&amp;amp;quot;, scale.y=0.7, pch=&amp;amp;quot;.&amp;amp;quot;, xlim=c(min(xpos),max(xpos)), ylim=c(min(ypos),max(ypos)), zlim=c(min(zpos),max(zpos)))&lt;br /&gt;
&lt;br /&gt;
s3d.coords &amp;amp;lt;- s3d$xyz.convert(xpos,ypos,zpos)&lt;br /&gt;
&lt;br /&gt;
title(&amp;amp;quot;Lorenz Attractor&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:figure/unnamed-chunk-8-1.png|frame|none|alt=|caption plot of chunk unnamed-chunk-8]]&lt;br /&gt;
&lt;br /&gt;
As you can see, your fly is drawing pretty angled butterfly patterns in the air. See how changes to the parameters change this pattern.&lt;br /&gt;
&lt;br /&gt;
= The Mandelbrot Set =&lt;br /&gt;
&lt;br /&gt;
This is a particular treat and you may well have seen the resulting images. Nothing short but beautiful. This code is replicated from [http://tolstoy.newcastle.edu.au/R/help/05/10/13198.html here]&lt;br /&gt;
&lt;br /&gt;
First ensure that you have installed the following two libraries (you will only have to do that once!)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;install.packages(&amp;amp;quot;caTools&amp;amp;quot;)&lt;br /&gt;
install.packages(&amp;amp;quot;fields&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here is what you need to do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;library(fields)  # for tim.colors&lt;br /&gt;
library(caTools) # for write.gif&lt;br /&gt;
m &amp;amp;lt;- 1600          # grid size&lt;br /&gt;
C &amp;amp;lt;- complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ),imag=rep(seq(-1.2,1.2, length.out=m), m ) )&lt;br /&gt;
C &amp;amp;lt;- matrix(C,m,m)&amp;lt;/pre&amp;gt;&lt;br /&gt;
You really do not have to understand any details of the mathematics that is going on here. You can find a discussion of the [https://en.wikipedia.org/wiki/Mandelbrot_set Mandelbrot Set here]. Just a little note. The initial line in which we define &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt;, assigns some complex numbers to &amp;lt;code&amp;gt;C&amp;lt;/code&amp;gt;. The line after puts these numbers onto a (m x m) grid.&lt;br /&gt;
&lt;br /&gt;
The following is just some more prep work. We define a scalar &amp;lt;code&amp;gt;Z&amp;lt;/code&amp;gt; to equal 0 and then we define an array &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;. This is a three dimensional object. Think about it as 20 slices of (m x m) matrices, with all elements filled with the value 0.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;Z &amp;amp;lt;- 0 &lt;br /&gt;
X &amp;amp;lt;- array(0, c(m,m,20)) &amp;lt;/pre&amp;gt;&lt;br /&gt;
This is now the core of the calculations. We will go through a &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loop and repeat calculations 20 times. The &amp;lt;code&amp;gt;X[,,k]&amp;lt;/code&amp;gt; line fills the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;th slice of &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; with the results of the calculations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;for (k in 1:20) { &lt;br /&gt;
  Z &amp;amp;lt;- Z^2+C &lt;br /&gt;
  X[,,k] &amp;amp;lt;- exp(-abs(Z)) &lt;br /&gt;
} &amp;lt;/pre&amp;gt;&lt;br /&gt;
The calculations are completed. Now we need an image. In this case we take the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;th slice. As we are at the end of the loop &amp;lt;code&amp;gt;k=20&amp;lt;/code&amp;gt;, so we are looking at the 20th slice. But by changing &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; to any number between 1 and 20 you can see the state of the calculations after the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;th iteration.&lt;br /&gt;
&lt;br /&gt;
Check out &amp;lt;code&amp;gt;?image&amp;lt;/code&amp;gt; to understand what image does.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;image(X[,,k], col=tim.colors(256)) # show final image in R &amp;lt;/pre&amp;gt;&lt;br /&gt;
[[File:figure/unnamed-chunk-13-1.png|frame|none|alt=|caption plot of chunk unnamed-chunk-13]]&lt;br /&gt;
&lt;br /&gt;
This following line will actually create a little animation!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r&amp;quot;&amp;gt;write.gif(X, &amp;amp;quot;Mandelbrot.gif&amp;amp;quot;, col=tim.colors(256), delay=100) # drop &amp;amp;quot;Mandelbrot.gif&amp;amp;quot; file from current directory on any web brouser to see the animation&amp;lt;/pre&amp;gt;&lt;br /&gt;
Open it in any browser and marvel!&lt;/div&gt;</summary>
		<author><name>Rb</name></author>	</entry>

	</feed>