From be1109345bf16ffebd381da675a5757e9f77fa26 Mon Sep 17 00:00:00 2001 From: Recolic Keghart <git@me.recolic.net> Date: Mon, 28 Nov 2022 21:14:39 -0800 Subject: [PATCH] add plain c --- generate-points.c | 37 +++++++++++++++++++++++++++++++++++++ generate-points.cc | 39 --------------------------------------- run.sh | 2 +- 3 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 generate-points.c delete mode 100644 generate-points.cc diff --git a/generate-points.c b/generate-points.c new file mode 100644 index 0000000..f1966de --- /dev/null +++ b/generate-points.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <assert.h> + +#define sample_per_u 10 +#define iteration_count 200 +#define sample_range_begin 1.000 +#define sample_range_end 4.000 +#define delta_u 0.001 + +void sample_after_iteration(double u, double *output_samples_arr) { + // Firstly, let's do some iterations. + double x_curr = 0.01; + for(int i = 0; i < iteration_count; ++i) { + assert(x_curr > 0 && x_curr < 1); + x_curr = u * x_curr * (1 - x_curr); + } + // And then, take some samples. + for(int i = 0; i < sample_per_u; ++i) { + output_samples_arr[i] = x_curr; + x_curr = u * x_curr * (1 - x_curr); + } +} + +void print_points() { + double samples_arr[sample_per_u]; + for(double curr_u = sample_range_begin; curr_u <= sample_range_end; curr_u += delta_u) { + sample_after_iteration(curr_u, samples_arr); + for(int i = 0; i < sample_per_u; ++i) { + printf("%f %f\n", curr_u, samples_arr[i]); + } + } +} + +int main() { + print_points(); +} + diff --git a/generate-points.cc b/generate-points.cc deleted file mode 100644 index d91b362..0000000 --- a/generate-points.cc +++ /dev/null @@ -1,39 +0,0 @@ -#include <iostream> -#include <array> -#include <cassert> - -constexpr auto sample_per_u = 10; -constexpr auto iteration_count = 200; -constexpr auto sample_range_begin = 1.000; -constexpr auto sample_range_end = 4.000; -constexpr auto delta_u = 0.001; - -auto sample_after_iteration(double u) { - // Firstly, let's do some iterations. - double x_curr = 0.01; - for(int i = 0; i < iteration_count; ++i) { - assert(x_curr > 0 && x_curr < 1); - x_curr = u * x_curr * (1 - x_curr); - } - // And then, take some samples. - std::array<double, sample_per_u> samples; - for(int i = 0; i < sample_per_u; ++i) { - samples[i] = x_curr; - x_curr = u * x_curr * (1 - x_curr); - } - return samples; -} - -void print_points() { - for(auto curr_u = sample_range_begin; curr_u <= sample_range_end; curr_u += delta_u) { - auto samples = sample_after_iteration(curr_u); - for(auto &&sample : samples) { - std::cout << curr_u << ' ' << sample << std::endl; - } - } -} - -int main() { - print_points(); -} - diff --git a/run.sh b/run.sh index 68f0e1c..04f6094 100644 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -g++ generate-points.cc -O3 -o generate-points && ./generate-points | tee points.log && python draw.py +gcc generate-points.c -O3 -o generate-points && ./generate-points | tee points.log && python draw.py -- GitLab