1#include <matplot/matplot.h>
3#include "boost/multi_array.hpp"
4#include "boost/array.hpp"
5#include "CustomLibraries/np.hpp"
6#include "CustomLibraries/np_to_matplot.hpp"
8using namespace matplot;
11 std::vector<double> x =
linspace(-2 * pi, 2 * pi);
12 std::vector<double> y =
linspace(0, 4 * pi);
15 transform(X, Y, [](
double x,
double y)
16 {
return sin(x) + cos(y); });
17 contourf(X, Y, Z, 10);
24 boost::multi_array<double, 1> x =
np::linspace(0, 1, 100);
25 boost::multi_array<double, 1> y =
np::linspace(0, 1, 100);
29 const boost::multi_array<double, 1> axis[2] = {x, y};
30 std::vector<boost::multi_array<double, 2>> XcY =
np::meshgrid(axis,
false, np::xy);
36 boost::multi_array<double, 2> f =
np::pow(XcY[0], 2.0) + XcY[0] *
np::pow(XcY[1], 1.0);
40 std::vector<boost::multi_array<double, 2>> gradf =
np::gradient(f, {dx, dy});
43 matplot::vector_2d X = matplot::meshgrid(
linspace(0, 1, 100),
linspace(0, 1, 100)).first;
44 matplot::vector_2d Y = matplot::meshgrid(
linspace(0, 1, 100),
linspace(0, 1, 100)).second;
47 std::cout <<
"X.size() = " << X.size() << std::endl;
48 std::cout <<
"Y.size() = " << Y.size() << std::endl;
49 std::cout <<
"Z.size() = " << Z.size() << std::endl;
50 for (
size_t i = 0; i < X.size(); i++)
52 for (
size_t j = 0; j < X[i].size(); j++)
54 std::cout <<
"X[" << i <<
"][" << j <<
"] = " << X[i][j] <<
" | XP[" << i <<
"][" << j <<
"] = " << Xp[i][j] <<
" | YP[" << i <<
"][" << j <<
"] = " << Yp[i][j] << std::endl;
57 contourf(Xp, Yp, Z, 10);
matplot::vector_2d convert_to_matplot(const boost::multi_array< double, 2 > &arr)
Convert a 2D boost::multi_array to a matplot::vector_2d.
::value constexpr boost::multi_array< T, ND > pow(const boost::multi_array< T, ND > &input_array, const T exponent)
Implements the numpy pow function on multi arrays.
::value constexpr std::vector< boost::multi_array< T, ND > > gradient(boost::multi_array< T, ND > inArray, std::initializer_list< T > args)
::value constexpr std::vector< boost::multi_array< T, ND > > meshgrid(const boost::multi_array< T, 1 >(&cinput)[ND], bool sparsing=false, indexing indexing_type=xy)
boost::multi_array< double, 1 > linspace(double start, double stop, long unsigned int num)
Implements the numpy linspace function.