Original Post
hi, i'm writing some simple programs to test different inegration methods, i've only done euler, with this code: integration.h euler.h euler.cpp main.cpp the problem is that the time always shows up as 0, is this becuase it run to fast for the timer to pick up a change in time? also when the dt is shortened the output change to 0, but when the timer step is increased the answer increases, what is causing this? is it my implementation or is it standard behaviour? ps should this be here or in maths? **EDIT** when using dt as 0.3 i get 519, not a bad estimate, but when using 0.29 just 1/100th of a second shorter i get 348, quite a large jump an i thought a smaller dt would make the results closer to the real value ( 500 ), is this normal behaviour?
#include <iostream>
class State
{
public:
State() : x(0), v(0) {};
State( int _x, int _v ) : x(_x), v(_v) {};
int x;
int v;
};
#include "integration.h"
void Euler(float tend, float dt, float a, State &result);
#include "integration.h"
void Euler(float tend, float dt, float a, State &result)
{
State s;
s.x = 0;
s.v = 0;
float tstart = 0;
while( tstart <= tend )
{
s.v = s.v + a*dt;
s.x = s.x + s.v*dt;
tstart = tstart + dt;
}
result = s;
}
#include "Euler.h"
#include <ctime>
int main()
{
State st;
time_t start, end;
double time;
std::time(&start);
Euler( 10, 0.1, 10, st );
std::time(&end);
time = difftime( end, start );
std::cout << st.x << "\n";
std::cout << time << "\n";
return 0;
}