Part One – Euler Approximation to Solution Curves
Our goals for this section of the block are to…
We are going to explore how exact solutions to first order differential equations differ from Euler approximations.
We are also going to experiment with Euler approximations to the Lorenz equations ( which model physical or biological phenomena) for various parameter values and initial conditions. Instead of looking at one differential equation this time, we will be looking at a system of non-linear differential equations and the nature of their solution curves.There are very few known exact methods of solution for these systems of differential equations. We have to resort to numerical methods for obtaining approximations to solutions curv. We are using three linked differential equations in this first part of the second project – with three variables – they are known as the Lorenze System of non-linear equations. Edward Norton Lorenz was also known for the “butterfly effect”.
In these equations, all parameters are positive.In these equations it is common to take
.Different values of
give qualitatively different solution curves for this system of equations. For example, for
the solution is chaotic, meaning that nearby points diverge approximately exponentially rapidly (so prediction with time is difficult to impossible). The solution curves for these values form an object in 3-space that is known as the Lorentz attractor.
We created an Excel Spreadsheet that linked the three equations for us and carried out Euler’s method for us. It was time consuming to input – we kept getting errors on our output. evrytime we entered (8/3) we got the date – I tried at home on my computer and e-mailed it – then had issues trying to get it to post as a spreadsheet in wordpress. We followed the project guide and stayed with the same values that were recommended …

Excel could not plot in 3D – so we plotted x(t), y(t) and z(t) as a function of t on the same 2d graph.
This next graph is over a smaller time period than the previous – really just experimenting at this point with getting different looks.

Another try at the excel spreadsheet…this time we tried a decimal value for 8/3
9/30/08)
This is the same graph as number one – just experimenting with options in the Excel program to create “pretty” pictures
I replaced our graph with one from Edgar’s – our graph of the Excel data was not accurate ( thanks to the gremlin laptop) (or the errors of it’s user)(or both
) this seems to be a more accurate graph of the data – our numbers were a little different – but the overall general shape of the graph matches what we should have gotten.
We tried to get different views of the three systems by plotting different axis’ in 2D.
Now, the fun began … trying to use Matlab because it does have the ability to show us a 3D graph. It was not as easy as I thought it would be. I blogged many times with errors in code – trying to get graphs to post onto my page … it became a comedy of errors and I stopped fighting murphey’s law.
Whenever I did work from home – it was lost – just disappeared like socks in the dryer – forever. I learned about m-files – and the code I mostly copied from the project guide – I did not find Matlab code to be intuitive. A lot of researching, reading and asking questions.
We set up the m file euler.m
>> y_int=0.1;
>> [t,y]=euler(‘test_example’,[0.1,9.0],y_int,200);
>> y_init=[.9,1,1.1];
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,1000); This was more Matlab land adventures
We just kept trying until we got it right.
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,2500);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,3000);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,500);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,800);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,700);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,750);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,799);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,800);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,850);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,830);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,810);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,805);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,1500);
>> plot(t,y)
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,1500);
>> [t,y]=euler_system(‘lorenz_system’,[0.0,20.0],y_init,1000);
>>————————————————————————————
we created m files
g.m
function xdot = g(t,x)
xdot = zeros(3,1);
sig = 10.0;
rho = 28.0;
bet = 8.0/3.0;
xdot(1) = sig*(x(2)-x(1));
xdot(2) = rho*x(1)-x(2)-x(1)*x(3);
xdot(3) = x(1)*x(2)-bet*x(3);
created lorenze_demo.m
function lorenz_demo(time)
% Usage: lorenz_demo(time)
% time=end point of time interval
% This function integrates the lorenz attractor
% from t=0 to t=time
[t,x] = ode45(‘g’,[0 time],[1;2;3]);
disp(‘press any key to continue…’)
pause
plot3(x(:,1),x(:,2),x(:,3))
print -deps lorenz.eps
code for the lorenz attractor animated
function yprime = lorenz_system ( t, y )
function createfigure(XData1, YData1, ZData1, XData2, YData2, ZData2, XData3, YData3, ZData3)
%CREATEFIGURE(XDATA1,YDATA1,ZDATA1,XDATA2,YDATA2,ZDATA2,XDATA3,YDATA3,ZDATA3)
% XDATA1: line xdata
% YDATA1: line ydata
% ZDATA1: line zdata
% XDATA2: line xdata
% YDATA2: line ydata
% ZDATA2: line zdata
% XDATA3: line xdata
% YDATA3: line ydata
% ZDATA3: line zdata
% Auto-generated by MATLAB on 07-Oct-2008 11:39:34
% Create figure
figure1 = figure(‘NumberTitle’,'off’,'Name’,'Lorenz Attractor’,…
‘Color’,[0.35 0.35 0.35]);
% Create axes
axes1 = axes(‘Parent’,figure1,’ZTick’,zeros(1,0),’ZColor’,[1 1 1],…
‘YTick’,zeros(1,0),…
‘YColor’,[1 1 1],…
‘XTick’,zeros(1,0),…
‘XColor’,[1 1 1],…
‘Position’,[0.05 0.1 0.75 0.95],…
‘ColorOrder’,[1 1 0;1 0 1;0 1 1;1 0 0;0 1 0;0 0 1;0.75 0.75 0.75],…
‘Color’,[0 0 0]);
% Uncomment the following line to preserve the X-limits of the axes
% xlim([0 40]);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim([-35 10]);
% Uncomment the following line to preserve the Z-limits of the axes
% zlim([-10 40]);
view([-37.5 30]);
hold(‘all’);
% Create xlabel
xlabel(‘X’,'Color’,[1 1 1]);
% Create ylabel
ylabel(‘Y’,'Color’,[1 1 1]);
% Create zlabel
zlabel(‘Z’,'Color’,[1 1 1]);
% Create line
line(XData1,YData1,ZData1,’Parent’,axes1,’MarkerSize’,25,’Marker’,’.’,…
‘Color’,[1 0 0]);
% Create line
line(XData2,YData2,ZData2,’Parent’,axes1,’Color’,[1 1 0]);
% Create line
line(XData3,YData3,ZData3,’Parent’,axes1,’Color’,[0 0 1]);
% uicontrol currently does not support code generation, enter ‘doc uicontrol’ for correct input syntax
% In order to generate code for uicontrol, you may use GUIDE. Enter ‘doc guide’ for more information
% uicontrol(…); I thought I would add this small segment in for good measure of all the fun times Matlab and I shared.
Part of the story and part of the journey – hopefully by next semester I will be the Matlab queen
% uicontrol currently does not support code generation, enter ‘doc uicontrol’ for correct input syntax
% In order to generate code for uicontrol, you may use GUIDE. Enter ‘doc guide’ for more information
% uicontrol(…);
% uicontrol currently does not support code generation, enter ‘doc uicontrol’ for correct input syntax
% In order to generate code for uicontrol, you may use GUIDE. Enter ‘doc guide’ for more information
% uicontrol(…);
% uicontrol currently does not support code generation, enter ‘doc uicontrol’ for correct input syntax
% In order to generate code for uicontrol, you may use GUIDE. Enter ‘doc guide’ for more information
% uicontrol(…);
% uicontrol currently does not support code generation, enter ‘doc uicontrol’ for correct input syntax
% In order to generate code for uicontrol, you may use GUIDE. Enter ‘doc guide’ for more information
% uicontrol(…);
I enjoyed when we finally did get the 3D graph – having the ability to look at it from different viewpoints. I found it fascinating. These were my favorite views

I have been trying to import our data and our images into a post. First from a page that I have been saving and adding to this entire project – they did not insert into the post – and now they are not in the page either. So, I then tried to add the media from my media library – again just a bunch of code appeared in the post. Hopefully I can figure this out soon. Just in case it takes longer than expected to find the data – I decided to write a short summary – I know that I could probably copy and paste from Matt’s Blog – I was there in class and you answered many questions along the way – but, I really want to try to figure it out on my own first.
I learned a lot from this project. It was a lot of fun and very interesting. I got answers a long the way to my questions … and discovered new questions that I am still looking for the answers to. We started out by following the guide and the example on the class web page.
We decided to start with the Lorenz system. We followed the example that was given. We used Excel to calculate our data using Euler’s method. It was very nice to use the computer because I got to see how different values for Delta affected the graph. Even the excel graphs were noticeably different. The computer just took seconds – so, it was easy to just play with the numbers and see what happens visually very quickly in a colorful way.
We had to work through some glitches with Excel and Matlab – when we tried to enter 8/3 into the cell – it gave us the date – we ended up just using the calculator feature and using 2.66.
Matlab is getting easier for me to navigate – finally
We did have some difficulties with things like loosing the command prompt and missing quotations. But, definitely not getting stuck as much.
Once we entered the code we got some really nice pictures of our Lorenz system. Again, I was curious about the different values for Delta and experimented at changing the viewpoint of the graphs too. How the system looked depended also on your viewpoint. A powerful connection to this – I learned later. I enjoyed being able to move the axis’.
I originally thought that we were basically done with the project early – but, I read through the example one more time. And, I noticed that there was one sentence about the system changing when P=99.96 so, I realized we were not finished – we needed to gather more data. The night before I had been doing some reading and researching on-line for a research topic and stumbled upon a research project about knots – that’s when everything seemed to connect and click for me. I had read about knots before – but, had “not” connected that – our system seemed to “Knot” ! I was really confused when we got the plot of (as Matt descibed ) a weird kind of “smooshed hershey kiss” shape. I thought I remembered from the lecture the first day of the project that when you start at a point in the system and follow it through – it doesn’t intersect its previous path – so, when I saw the graph starting and ending at the same point I got confused. And then I laughed when I learned it was the definition of a Knot. When I saw a 3D image of a knot it was very interesting – but it never appeared to intersect. Ha – since it didn’t have a starting and ending point – duh – ending and starting pt. the same!. A very basic simple concept – so, it was quite funny that it seemed like a light switch moment – the 2D connected with the 3D visually for me.
As we have learned that Euler’s method is not very accurate for non-linear systems – a very small error up front can grow to a very large margin of error at the end – kind of like the shape of a cornicopia – small (margin of error) beginning or opening – large(margin of error) ending or opening. I was also able to visually get a better understanding because of this lab. The 3D picture of the Lorenz system knotted – gave a width to the line ( but since 3D – more like a tube). So, I was able to see that we might think that we are really close with the approximation – but, not close enough – not only in 2D, but also in 3D.
So, in conclusion – I got to visually see why it is difficult to get an exact answer to a non-linear equation. And, exactly what all the math is doing and applications to the math that we are learning. I can also add here – that a bunch of the missing pictures were actually in a gallery – must be a mouse error – somehow went from posting to saving – hmmmm – but, all is good – they were lost and then found!
This is the Lorenze Attractor !!!
Playing with axis’ and getting different viewpoints…
Different viewpoints of the knotted system …
These are the 3D graphs that we were able to get from Matlab -
Hmmmm … hindsite – we should have given this graph a title and legend and labeled the axis – lesson learned – my guess is each color represents a different equation within our Lorenze system. This would show how they compare and interact.
Another excell graph in 2D …
These are the rest of the pictures that dissappeared for a while. I finally figured out what may have happened …
I might not have hit the update button for the page after uploading them to the blog … or I published them as a post and I was looking in Pages. I guess I just learned to slow down and think about each step – not to rush through it so that mistakes get made – “the faster I go – the behinder I get” . Seemed like nothing was posting for awhile – you can click on my adventures of murphy’s law … each blog either got lost – mixed all together – or just was posted way too blurry to even know what it is … but, I just hung in there until things cleared up – and got back right inwhere it left off.
These pictures are just different view points of the Lorenze system — I still am just fascinated by being able to twist and turn the image – like it was in my hand and I could turn it any which way – or a piece of art that I could circle around – look lower or higher … just a really cool feature to me I guess – and the philosophy of are things really as they appear to be – or are we limited by our vantage point?
Basically the same graphs as above but, in a generalized way – by moving things around I discovered that there were less lines with these views which made it a little clearer for me to see the behavior of the system. This kind of reminds me of “Flatland” – a 3D object dropping into a 2D world which doesn’t have an up – so the 2D world can only see a sliver of the actual 3D shape – maybe that’s why I got stuck in the sand box playing with graphs :-)
PART TWO _ PREDATOR PREY
- I did some research and reading on the next two topics … but, Matt is just so much faster than I am – it’s like he’s in a sports car and I’m in my flintstone car
okay – it’s late and I’m punchy – while I was playing with the math version of barbie dolls – dressing up graphs and looking, thinking and analyzing – Matt left the sand box and graduated – he just amazes me. At this pointv – I’m realizing that I have to get these projects done – and, I remember hearing in class … just do whatever is necessary to get the job done. I have had a difficult time – looking at other classmates’ work really, prior to this week – maybe an independent spirit – or pride – or just wanting to not influence any originality on my part – whatever the reasons – I struggled with feeling like I was cheating I guess – if I wasn’t so stubborn – life might be easier
actually a couple of days ago I just went through the class list and enjoyed learning and seeing where everyone was at math wise and computer wise. It gave me the gumption to take a few minutes and personalize my blog . But it also helped me to realize – I wasn’t as far behind intellectually as I felt. So, it proved helpful – and helpful in getting things done – but still a little uncomfortable. Even though giving credit where credit is due … I never did ask – was there a way of writing to other students outside our group within the blog setup – to ask questions to other students? AHHH – maybe that’s the uncomfortableness – Adam, Jay and Edgar have no knowledge that I am using their info – I feel sneaky !!!
Matt was able to get the next two parts of this project from Adam – which he stated – I inturn give Matt the credit – I also have read through Edgar’s and Jay’s.
The Lotka-Volterra predator-prey equations are
where y is the number of predators, x is the number of prey, and
are parameters that tune the interaction of the predators and prey.
Explore solutions of the predator-prey equations for varying parameter values and initial conditions.
The Lotka-Volterra equations are a PAIR of first order, NON-LINEAR differential equations – used to describe biological systems and how different variables interact. A common example is the rabbts and the wolves.
(dy/dt) and (dx/dt) are parameters – over time
t is equal to time
are ….
prey’s growth
interaction
predator death
predator growth
Jay added a nice feature here … he added
The first thing I did was to use Euler’s method to get an approximate solution for the equations.
I started off my and
with random numbers and fixed values for sigma, rho, and beta which have been changed from the example we were given. They are shown in the following table.
My Euler’s method formula’s for variables are as follows.
I kept forgetting to ask in class about the improved Euler Method – I imagine it doesn’t matter which we used – there would still be legthly calculations and less of a margin of error in calculation – but, still large enough to not be called – great.
The predator prey model ( I will be talking about rabbits and foxes) but, this model can be used for other models – economics, medical research … (add more here) this system reminds me of the Lorenze attractor from the aspect that there are many things interacting that affect the system – in the predator prey model – ideally a stable system – where the rabbits and the wolves stay the same population wise – does not tend to be reality from the aspect of “perfect” conditions. Sickness, weather, pestilence affecting the rabbits clove, natural disasters like fire, volcanoes, etc. … can all affect the system these outside factors cannot be constant or predictable. I am still trying to grasp why a starting point in the Lorenze system would have a predictable location once we know it’s starting point – but, if another point was place delta x away from that point – it would grow further away from it’s “friend” as it traveled through the Lorenze system … both systems have patterns of behavior – but, ot definitive enough patterns – to be exact predictors of locations or populations over time.
This is the excel spreadsheet of our model … this went much faster than in project one – even though Matt doesn’t agree – he forgot about the date/decimal situation I think
Progress was made as far as neatness the numbers are in cells!!! not wandeing around freely!!!

This 2D graph plots x and y versus time – in Excel - using the data from Euler’s Method – hey Matt played dress up too – background stands out nicely Matt
(check if x-axis has values-missing) - also have to think about whether the blue line is supposed to be horizontal – time is a constant – looks like it has a slope … hmmm
Jay graphed in Excel also – but with just the predator vs. prey his looks like
The predator- prey model seems to “dance” with each other. As prey increases – so do the predators – but, at a certain point (around 160 – balances or equilibrium) if the predators keep increasing – the prey decreases – more hunters on the loose - not enough food to go around - now, the predators also decrease in numbers – but, less predators – now prey starts to increase again – the cycle continues on until an ice age or global warming … etc. As stated above – the system can be interupted by nature – or man. If mankind desides rabit meat or fur is must – or any outside force can disrupt the system.
So then I went to go use MATLAB to put up the plots and make a phase plane plot to show a direct relationship between x(t) and y(t).
I changed my variables to as follows:
I believe that this is Adam’s data …
So here’s the m file code for MATLAB:
function yp = lotka(t,y)
%LOTKA Lotka-Volterra predator-prey model.
yp = diag([1.2 - .07*y(2), -1.1 + .03*y(1)])*y;
And then the actual lines I ran in MATLAB:
>> tfinal=15;
>> y0=[20 20]‘;
>> tfinal=tfinal*(1+eps);
>> [t,y]=ode23(’lotka’,[t0 tfinal],y0);
>> subplot(1,2,1)
>> plot(t,y)
>> title(’x(t) vs. y(t)’)
>> subplot(1,2,2) Just read about the subplot feature a little while ago – subplot puts two graphs side by side to compare
>> plot(y(:,1),y(:,2))
>> title(’x(t) vs. y(t) (phase plane)’) I am going to test this code in Matlab on the infamous magic laptop … I think that Jay’s graphs were “prettier” he used slightly different
values – I will try some too.
That lead me to these charts:

Jay used slightly different values – will add my own values and charts to this …
I also liked that Jay checked his work …
Feel like this needs more slanin – will move on and come back …
Begining with Excel, I used Euler’s method using random numbers for the values of , and got some approximations using the following equations:
Is this what you wanted Matt?
If you can’t see the above equations, then it means wordpress has a problem with my perfect syntax and they need to friggin figure that out themselves. Bear with me and scroll over them lightly if you want to see them. Trust me when I say that they work, because I used them to get these in Excel:
Matt continues to teach me – don’t worry – move on – just say friggin:-) So, he’s probably sleeping right now


This is the 2D graph using Excel of the Euler’s Method values Matt used - giving the solution to our Rossler System.
This is the code of the m file in Matlab created to plot the 3D graph (useing ode45 solver)
function yprime= rossler_system(t,y)
yprime= [(-1*(y(2))-y(3)); y(1)+(0.1*y(2)); 0.2+y(3)*(y(1)-11) ];
Matlab code
>> y_init= [0.129843633;0.588914123;0.231638841];
>> [t,y]=euler_system(’rossler_system’,[0.0,300.0],y_init, 10000);


Two different view points of the Rossler System – hey Matt got back into the sand-box !!!!
some more splanin needed here about rossler system – want to discuss the three together – similarities and differences – does rossler system not also? What’s it’s behavior like?
Jay used ode23 in Matlab for the use of the Runge-Kutta integration method – he compared 0de23′s solution to ode 45′s solution – I thought this was brilliant – He compared the three methods of numerical solutions really - I need to add more about solving numerical solutions and margins of errors with the different methods – also – how each method differes from the other in how it approaches the calculations
ODE23 and ODE45 are functions for the numerical solution of ordinary differential equations. They employ variable step size Runge-Kutta integration methods. ODE23 uses a simple 2nd and 3rd order pair of formulas for medium accuracy and ODE45 uses a 4th and 5th order pair for higher accuracy.
To compare the differences between ODE23 and ODE45 I input the following code into Matlab which overlayed the 2 Time History plots on top of each other. Good job Jay!
>>[T,Y] = ode45(’lotka’,[t0 tfinal],y0);
>>subplot(1,1,1)
>>title(’Time History plot’)
>>plot(t,y,’-’,T,Y,’-’);
>>legend(’ode23prey’,’ode23predator’,’ode45prey’,’ode45predator’)
The combined plots are shown in Figure 8
Fig. 8
I next ran a combined Phase plane plot to compare the accuracy of ODE23 and ODE45 by inputting the following code.
>>[T,Y] = ode45(’lotka’,[t0 tfinal],y0);
>>subplot(1,1,1)
>>title(’Phase plane plot’)
>>plot(y(:,1),y(:,2),’-’,Y(:,1),Y(:,2),’-’);
>>legend(’ode23′,’ode45′)
This is awesome – you can visually see here that ode was more precise in it’s calculations – between the y values 100 and 150 and the x values 75 to 150 – the blue line ode 23- thanks to the legend – is not as smooth as the green line 0de45 – you can actually see some jagged edges – ode45 calculated better estimations – but, at about (168,75) you can even see a jagged turn in the green – ode45. So, the search goes on for closer to exact in estimating teqniques.
Edgar decided to try Mathematica for the Rossler Attractor graph.
Here is the code he used and the graphs that resulted.
f = {X, Y, Z} /. NDSolve[{
X'[t] \[Equal] -(Y[t] + Z[t]),
Y’[t] \[Equal] X[t] + a Y[t],
Z’[t] \[Equal] b + X[t] Z[t] – c Z[t],
X[0] \[Equal] 1, Y[0] \[Equal] 1,
Z[0] \[Equal] 1} /. {a \[Rule] .2, b \[Rule] .2, c \[Rule] 8},
{X, Y, Z}, {t, 0, 50}][[1]]
l = {X[t], Y[t], Z[t]};
Show[GraphicsArray[
Table[Plot[f[[i]][t], {t, 0, 50}, PlotRange \[Rule] All,
PlotStyle \[Rule] Red,
AxesLabel \[Rule] TraditionalForm /@ {t, l[[i]]},
DisplayFunction \[Rule] Identity], {i, 3}]
ParametricPlot3D[Evaluate[Append[#[t] & /@ f, Red]], {t, 0, 50},
BoxRatios \[Rule] {1, 1, 1}, PlotRange \[Rule] All,
PlotPoints \[Rule] 1500, AxesLabel \[Rule] TraditionalForm /@ l]
I love this 3D grah – visually pleasing to the eye and easier to visualize the 3D environment. Since I liked moving things around and seeing different views in Matlab – I wonder how Mathematica looks – the added box around the system helps define the space better (in my opinion). I will check this out later.





















