Plotting Logistics Equation with Mathematica

In summary: After sorting your input in DPlot (www.dplot.com), the default plot you get is shown here: If you try DPlot and have any questions please let me know at support@dplot.com.In summary, Warren was going through "The Chaos Cookbook" and found that it was too old for the programs to be in Pascal and Basic. He then wrote a C++ program to create the data points for a Martin diagram of the Logistics equation. He found something strange in Mathematica 6.0 and had to filter out the empty lists. CompuChip and Crosson suggestedgnuplot, which he tried and it worked.
  • #1
Orson1981
15
0
I'm going through "The Chaos Cookbook" right now, a fairly old book on chaos programming. A bit too old I'm afraid, all the programs are written in Pascal and Basic. I had been using Excel (well, Open Office Calc) to do the iterations and graphing, but I feel that the size of the programs are out growing the scope of Excel. I wrote a C++ program to create the data points for a Martin diagram of the Logistics equation (the data is here http://www.box.net/shared/kr2cz5es0g if you care).

My question is how can I get mathematica to turn these data points into a graph, and/or is there perhaps better software I should be using for something like this (The main advantage is I get mathematica for free from my university).

It might be worth adding I can, pretty much, change the format of the data from that file at will if someone thinks a different format would work better.

Thanks for your help!
 
Physics news on Phys.org
  • #2
You could start by something like

Code:
data = Import["data.txt", "Data"];
ListPlot[data]

and then probably do some processing (filter the data, make a fit, etc) as your data looks a bit strange.
 
  • #3
After sorting your input in DPlot (www.dplot.com), the default plot you get is shown here:

MartinPlot.gif


If you try DPlot and have any questions please let me know at support@dplot.com.

David Hyde
 
  • #4
Hmm, I found something strange in Mathematica 6.0. If there are still empty lists (corresponding to empty lines in the source file) in the data you feed to ListPlot, you get a junk image. So you have to filter those out on import. The following does work and plots all the data points (also those missing in David's post):
Code:
data = Select[Import["data.txt", "Data"], Length[#] > 1 &];
ListPlot[data]

(By the way you have 20 newlines and 845 obsolete points in your list)
 
  • #5
Here is another way to deal with the empty lists:

Code:
data = DeleteCases[Import["data.txt", "Data"], {}];
ListPlot[data]
 
  • #6
Whoops, I overlooked the blank lines, as did DPlot. You can copy/paste the individual data sets (assuming that's what they are) or send each set to DPlot programmatically, then Edit>Swap X,Y, Edit>Sort, and Edit>Swap X,Y to restore the original order. It isn't clear if this is what you're after or not, but here's the result:

MartinPlotb.gif
 
  • #7
Thanks everyone for your input,

To David: I tried DPlot over the weekend and could manage to make it give me anything, I'll re-read your second post and try again this evening. I really could use a program that can do things like this easily, so I'm hoping it works out.

To CompuChip and Crosson: I tried your suggested line of code to no effect, I checked the mathematica help file and it appears that 5.2 doesn't support the function "Data" for the import command. I tried to fiddle around with the "List" command and the "Table" command but only ended up with blank graphs.

I've changed up my program to get rid of the white spaces and got rid of the bad data. The new list can be found at the same place as the old list. http://www.box.net/shared/kr2cz5es0g

The data itself is from the logistics equation x1 = k * x * (1-x). Each set of data points is formatted as: x1 , x . Then x1 becomes the new x and the program is run again to produce a new set of points. Knowing I could get it working in excel so I threw it in and got

note: this is with many more data points than in the above text file, plus I switched the x - y-axis for cosmetic reasons.

MartinPlot1.jpg


This takes a long time to process in excel though so I'm still hoping for another option such as mathematica (which would be nice for many reasons) or DPlot.
 
  • #8
Consider gnuplot. It's stable, easy to use, and has been around forever.

- Warren
 
  • #9
There was so much scatter in your data that I thought you must have intended the blank lines to be delineators between data sets... or something.

With a text file containing comma- or tab-separated values like yours, you can just drag the file onto the DPlot window and it will interpret it correctly. Alternatively after selecting File>Open, pick file type "D Multiple columns e.g. CSV files".

When I do that with your updated file and turn symbols on, lines off, I get:

MartinPlotc.gif


Should probably take any DPlot questions off-line - I don't mind answering questions but as a newbie here I don't want to wear out my welcome, either. You can get me at support@dplot.com.
 
  • #10
Orson1981 said:
To CompuChip and Crosson: I tried your suggested line of code to no effect, I checked the mathematica help file and it appears that 5.2 doesn't support the function "Data" for the import command.
Try "CSV"

Orson1981 said:
The data itself is from the logistics equation x1 = k * x * (1-x). Each set of data points is formatted as: x1 , x . Then x1 becomes the new x and the program is run again to produce a new set of points.
You can probably easily make the list in Mathematica to begin with, using NestList and related functions.

Orson1981 said:
I switched the x - y-axis for cosmetic reasons.
To do this in Mathematica, you can just map the elements of the list to Reverse:
Code:
ListPlot[Reverse /@ data]
 

1. How can I plot the logistics equation in Mathematica?

To plot the logistics equation in Mathematica, you can use the built-in function Plot. You will need to define the equation first, using the := operator. Then, use the Plot function with the defined equation as the first argument and the desired range of values for the independent variable as the second argument. For example, Plot[x^2, {x, 0, 10}] will plot the function x^2 from 0 to 10 on the x-axis.

2. How do I change the style and appearance of the plotted curve?

You can use various options in the Plot function to change the style and appearance of the plotted curve. For example, you can use the PlotStyle option to change the color, thickness, and style of the curve. You can also use the PlotRange option to adjust the range of values shown on the axes, and the AxesLabel option to add labels for the axes.

3. Can I plot multiple curves on the same graph?

Yes, you can use the Plot function to plot multiple curves on the same graph. Simply define each equation separately and include them as a list as the first argument of the Plot function. You can also use the PlotLegends option to add labels for each curve.

4. How can I add a title and legend to the plot?

To add a title to the plot, you can use the PlotLabel option in the Plot function. This will place the title above the plot. To add a legend, you can use the PlotLegends option and specify the labels for each curve. Alternatively, you can use the Legended function to create a separate legend for the plot.

5. Can I export the plotted graph as an image or PDF?

Yes, you can use the Export function in Mathematica to save the plotted graph as an image or PDF file. You will need to specify the desired file format and the file name in the function. For example, Export["plot.pdf", plot] will save the plot as a PDF file named "plot" in the current working directory.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
16K
  • STEM Educators and Teaching
Replies
5
Views
546
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
10K
  • General Math
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top