This commit is contained in:
张壹 2025-07-25 12:46:17 +08:00
parent bf14ada539
commit 4f4b39cc4b
2 changed files with 23 additions and 4 deletions

View File

@ -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<double> b;
@ -54,7 +58,7 @@ int main(int argc, char const *argv[])
a.show();
matrix<double> m(10, 10);
m.random_float(1.0, 2.0, RdUniform);
random_float(m, 1.0, 2.0, RdUniform);
m.show();
arma::Mat<double> 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;
}

View File

@ -29,13 +29,16 @@
// To compile the code, use: g++ use_eigen_ex.cpp -I<path-to-eigen3>
#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;