blob: 1d2a686f61a5f1d3896b82e1d0a9351d06be9766 [file] [log] [blame]
Austin Schuhad596222018-01-31 23:34:03 -08001#include <chrono>
2#include <cmath>
3#include <thread>
4
Austin Schuh87dc7bb2018-10-29 21:53:23 -07005#include "gflags/gflags.h"
Austin Schuhad596222018-01-31 23:34:03 -08006#include "third_party/matplotlib-cpp/matplotlibcpp.h"
7
8DEFINE_double(yrange, 1.0, "+- y max");
9
10double fx(double x, double yrange) {
Philipp Schrader790cb542023-07-05 21:06:52 -070011 return 2.0 * ((1.0 / (1.0 + ::std::exp(-x * 2.0 / yrange)) - 0.5)) * yrange;
Austin Schuhad596222018-01-31 23:34:03 -080012}
13
14int main(int argc, char **argv) {
15 gflags::ParseCommandLineFlags(&argc, &argv, false);
16
17 matplotlibcpp::figure();
18 ::std::vector<double> x;
19 ::std::vector<double> y;
20 ::std::vector<double> slope_y;
21
22 for (double i = -5.0; i < 5.0; i += 0.01) {
23 x.push_back(i);
24 y.push_back(fx(i, FLAGS_yrange));
25 slope_y.push_back(
26 (fx(i + 0.0001, FLAGS_yrange) - fx(i - 0.0001, FLAGS_yrange)) /
27 (2.0 * 0.0001));
28 }
29
30 matplotlibcpp::plot(x, y, {{"label", "saturated x"}});
31 matplotlibcpp::plot(x, slope_y, {{"label", "slope"}});
32 matplotlibcpp::legend();
33 matplotlibcpp::show();
Austin Schuhad596222018-01-31 23:34:03 -080034}