Odeint - Example problem using Van der Pol's Equation
MPD78
08-07-2009, 08:07 AM
Hello all,
I programmed the example problem given for the Odeint.h routine and I recieved the following output shown in graphical form. Has anyone else done this and recieved the same graph for the output? Also, I used the StepperDopr5 routine as shown in the example.
Yes, I did modify the ending point of x2 to 4 instead of 2 and I used 40 output points instead of 20. I did this for no other reason than to obtain a larger graph.
Please see attached graph.
EDIT: This graph is incorrect and can be removed.
Thanks
Matt
davekw7x
08-07-2009, 09:51 AM
...
Please see attached graph....
That may or may not be a reasonable "smoothed out" graph of values for 40 equally spaced points from zero to 4.
However...
To see the real nature of the solution I think it's more appropriate to plot all of the points that your stepper needed. In other words use
Output out(-1)
It's a stiff equation, and there are dramatic changes (peak values of y-prime on the order of plus-or-minus 1300) in the vicinity of x = 0.83, 1.67, 2.5, and 3.5
See attachment.
Regards,
Dave
MPD78
08-07-2009, 10:35 AM
Dave,
I have the same overall shape in my graphs but I am missing some of the peaks.
See attachments.
Thanks
Matt
EDIT: These graphs are incorrect and can be removed.
MPD78
08-07-2009, 10:45 AM
See attachment for numerical values.
I attached it because the spacing would not hold if I pasted the values in the body of the post.
Thanks
Matt
EDIT: Please remove the attached file it contains incorrect results.
davekw7x
08-07-2009, 01:36 PM
See attachment for numerical values.
I have attached mine (values were generated using Visual Studio Express version 8 on Windows XP). Consistent with my previous plot (that was done with all of the stepper points), edges can be seen to be on the following intervals:
[0.8, 0.9]
[1.6, 1.7]
[2.5, 2.6]
[3.3, 3.4]
Regards,
Dave
davekw7x
08-07-2009, 01:39 PM
Dave,
I have the same overall shape in my graphs but I am missing some of the peaks.
See attachments.
Thanks
Matt
Your plots are qualitatively consistent with what I would expect from this type of differential equation, but my results are quantitatively different.
Regards,
Dave
MPD78
08-07-2009, 02:23 PM
Dave,
I had two of the Dormand-Prince values incorrect. All is correct now and our outputs are the same.
As always, thanks for your help with this issue.
Matt
amirvahid
08-10-2009, 02:58 PM
Hi Dave,
It would be more instructive if you enclose your original code to this thread.
Thanks
davekw7x
08-10-2009, 04:48 PM
Hi Dave,
It would be more instructive if you enclose your original code to this thread.
Thanks
The Original Poster referred to the "example problem...for the Odeint.h routine." Code for this is in section 17.0.1 of the NR3 text. Here's how I put it together:
#include "../code/nr3.h"
#include "../code/stepper.h"
#include "../code/stepperdopr5.h"
#include "../code/odeint.h"
struct rhs_van {
//
// Code near the top of page 906
//
};
int main()
{
const Int nvar = 2;
//
// Code on page 906
//
// Inside this code define an output object:
//
// Output out(20);
// or
// Output out(-1);
// or
// whatever
//
ode.integrate();
// My stuff to generate output
cout << setw(13) << "xsave[i]"
<< setw(15) << "ysave[0][i]"
<< setw(13) << "ysave[1][i]"
<< endl << endl;
cout << fixed << setprecision(6);
for (Int i=0; i < out.count; i++) {
cout << setw(13) << out.xsave[i]
<< setw(13) << out.ysave[0][i]
<< setw(13) << out.ysave[1][i]
<< endl;
}
return 0;
}
For me (using code from the NR3 CD) It worked as expected. It worked the same with Borland and Microsoft and GNU compilers on Windows XP and with GNU compilers on Linux. Apparently the Original poster has equivalent results after correcting some errors that crept in as he was entering the code by hand.
The picture of my plots (with an Output object instantiated with the (-1) constructor parameter) is attached to my post number 2 in this thread. Those plots were created (externally) from text output of the values from the NR3 example code.
Regards,
Dave