C++调用Armadillo计算库

  • 1. 下载压缩包,解压到目录,比如D:\ALGLIB\armadillo,只保留include文件夹和examples里的lib_win32文件夹即可;

    下载地址:Armadillo: C++ library for linear algebra & scientific computinghttp://arma.sourceforge.net/download.html

  •  2. 配置项目

    将blas_win32_MT.dll和lapack_win32_MT.dll文件拷贝到exe根目录 。

  • 测试代码
// ArmadilloTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
using namespace std;
using namespace arma;
int _tmain(int argc, _TCHAR* argv[])
{
 system("color 0A");
 
 mat A(4, 5, fill::randn);
 A.print("A:");
 A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr
  << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr
  << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr
  << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr
  << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr;
 A.print("A:");
 mat C = A.t();
 C.print("C:");
 mat D1 = max(A);
 D1.print("max(A):");
 mat D2 = max(A, 1);
 D2.print("max(A, 1):");
 double temp = max(max(A));
 cout << "max(max(A)):" << temp << endl;
 temp = accu(A);
 cout << "accu(A):" << temp << endl;
 mat E = eye(4, 4);
 E.print("E:");
 temp = A.max();
 cout << "A.max():" << temp << endl;
 mat F;
 F.ones(2, 5);
 F.print("F:");
 mat u;
 vec s;
 mat v;
 svd(u, s, v, A);
 u.print("u:");
 s.print("s:");
 v.print("v:");
 A = randn(2, 3);
 mat B = randn(4, 5);
 field Fi(2, 1);
 Fi(0, 0) = A;
 Fi(1, 0) = B;
 Fi.print("Fi:");
 Fi.save("mat_field.field");
 field F1;
 F1.load("mat_field.field");
 F1.print("F1:");
 system("pause");
 return 0;
}
  • 结果

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值