From 461851105aa82f395e709d32316b8c389c0d2333 Mon Sep 17 00:00:00 2001 From: Orestis <orestis.malaspinas@pm.me> Date: Mon, 3 Oct 2022 10:03:41 +0200 Subject: [PATCH] added analysis --- experiment/newton/newton.c | 8 ++++++-- experiment/newton/newton.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 experiment/newton/newton.py diff --git a/experiment/newton/newton.c b/experiment/newton/newton.c index b766ffe..d51093b 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 0000000..79538f8 --- /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])) + -- GitLab