diff --git a/src/extra/use_armadillo_ex.cpp b/src/extra/use_armadillo_ex.cpp index eaf5666..95ffe3a 100644 --- a/src/extra/use_armadillo_ex.cpp +++ b/src/extra/use_armadillo_ex.cpp @@ -29,13 +29,17 @@ // To compile the code, use: g++ use_armadillo_ex.cpp -larmadillo #define GCTL_USE_ARMADILLO +#include "gctl/core/array_algorithm.h" +#include "gctl/core/matrix_algorithm.h" #include "gctl/core/armadillo_wrapper.h" using namespace gctl; int main(int argc, char const *argv[]) { - _1d_array a(10, 1, 0.5); + /* + _1d_array a(10); + sequence(a, 1.0, 0.5); a.show(); arma::Col b; @@ -54,7 +58,7 @@ int main(int argc, char const *argv[]) a.show(); matrix m(10, 10); - m.random_float(1.0, 2.0, RdUniform); + random_float(m, 1.0, 2.0, RdUniform); m.show(); arma::Mat amat; @@ -66,5 +70,17 @@ int main(int argc, char const *argv[]) _1d_array v; armaCol2array(r, v); v.show(); + */ + + // 定义系数矩阵 A 和常数向量 b + arma::mat A = { {2.0, 1.0}, {1.0, 3.0} }; + arma::vec b = { {5.0, 6.0} }; + + // 求解线性方程组 Ax = b + arma::vec x = arma::solve(A, b, arma::solve_opts::fast); + + _1d_array c; + armaCol2array(x, c); + c.show(); return 0; } diff --git a/src/extra/use_eigen_ex.cpp b/src/extra/use_eigen_ex.cpp index 032bfd2..4546f2d 100644 --- a/src/extra/use_eigen_ex.cpp +++ b/src/extra/use_eigen_ex.cpp @@ -29,13 +29,16 @@ // To compile the code, use: g++ use_eigen_ex.cpp -I #define GCTL_USE_EIGEN3 +#include "gctl/core/array_algorithm.h" +#include "gctl/core/matrix_algorithm.h" #include "gctl/core/eigen_wrapper.h" using namespace gctl; int main(int argc, char const *argv[]) { - _1d_array a(10, 1, 0.5); + _1d_array a(10); + sequence(a, 1.0, 0.5); a.show(); Eigen::VectorXd b; @@ -50,7 +53,7 @@ int main(int argc, char const *argv[]) c.show(); _2d_matrix m(5, 6); - m.random_float(1, 2, RdUniform); + random_float(m, 1.0, 2.0, RdUniform); m.show(); Eigen::MatrixXd mat;