diff --git a/experiment/newton/newton.c b/experiment/newton/newton.c index b766ffe59ff6417154c4a878da06bd32e8d11a07..d51093b9b4bdd6e2d3d0c843cc4d77702fb0902a 100644 --- a/experiment/newton/newton.c +++ b/experiment/newton/newton.c @@ -56,7 +56,11 @@ int main(int argc, char **argv) { struct timespec time = {0, dt * 1e9}; int num = sqrt(width / 1000.0 / 0.5 / (force / MASS)) / dt; - printf("%d\n", num); + if (debug) { + printf("time position velocity acceleration\n"); + } else { + printf("time position\n"); + } gfx_clear(ctxt, COLOR_BLACK); @@ -69,7 +73,7 @@ int main(int argc, char **argv) { if (debug) { printf("t = %f, pos = %f, vel = %f, acc = %f\n", i * dt, p, vel, acc); } else { - printf("t = %f, pos = %f\n", i * dt, p); + printf("%f, %f\n", i * dt, p); } avg_acc += acc; } diff --git a/experiment/newton/newton.py b/experiment/newton/newton.py new file mode 100644 index 0000000000000000000000000000000000000000..79538f884bb531d18b615702ba1fec96158c5330 --- /dev/null +++ b/experiment/newton/newton.py @@ -0,0 +1,18 @@ +import numpy as np + +time_pos = np.genfromtxt("input.txt", delimiter=",") + +time = time_pos[:,0] +time_p1 = np.roll(time, -1) + +pos = time_pos[:,1] +pos_p1 = np.roll(pos, -1) +# print(pos) + +vel = (pos_p1 - pos) / (time_p1 - time) +vel_p1 = np.roll(vel, -1) +# print(vel) + +acc = (vel_p1 - vel) / (time_p1 - time) +# print(np.mean(acc[0:len(acc)-2])) +