0

I want to make cobweb plot in c with gnuplot but the curve is not plotted well.

Here are the code.

#include <stdio.h>

int main(void){

int i, n=100; // Time

double r=3.80; // Initial condition of maximum rate of increase
double x[102]; // Increase rate
x[0]=0.7; // Initial condition

/*--- making data ---*/
for(i=0;i<=n;i++){
        x[i+1]=r*(1-x[i])*x[i];
        printf("%lf\t%lf\n",x[i],x[i+1]);
}

return 0;

}

plotted curve

Then, plot "chaos2.plt" with line in gnuplot.

I'd like to plot a graph from coordinates, but it is plotted like this. How do I fix the code ?

expected graph

theozh
  • 22,244
  • 5
  • 28
  • 72
CalmPenguin
  • 145
  • 7
  • Please show all the relevant code. Create smallest reproducible example. How do you execute gnuplot? – KamilCuk Oct 06 '18 at 10:17
  • @KamilCuk I did. Is there any other way to get a response? – CalmPenguin Oct 07 '18 at 06:07
  • What is the expected output? How do you want the plot to look like? gnuplot plotted it so the first column is x, the second are y values. You want `gnuplot "chaos2.plt" using 0:1 with lines, "chaos2.plt" using 0:2 with lines`? – KamilCuk Oct 07 '18 at 06:35
  • @KamilCuk The graph I added now is the expected plot. I want to graph the data like that. – CalmPenguin Oct 07 '18 at 07:15
  • But such data are not at all generated from the C program you posted. You want the first column to be X coordinate and the second to be Y you will get what you posted. That is a graph for different data. So what kind of data do you expect to get from you program? Your program outputs https://pastebin.com/mFbMdEub and you can get your graph to look like this: https://snag.gy/f8yN0Z.jpg . These are your data. – KamilCuk Oct 07 '18 at 11:05
  • @KamilCuk I want to make a plot of difference in logistic formula and cobweb plot. But it seems that my code does not accomplish my purpose... – CalmPenguin Oct 08 '18 at 05:21
  • @KamilCuk Could you tell me how to connect a previous point and a next point with a line? Just like a curve – CalmPenguin Oct 08 '18 at 12:15
  • Well, I say: 1) transpose the output of your program 2) call gnuplot . Then gnuplot will interpret the columns as unique datasets and when supplied with `with lines` will connect them with lines. – KamilCuk Oct 08 '18 at 12:53

0 Answers0